SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
input_wayland.c File Reference
#include "linux_internal.h"
#include <string.h>
Include dependency graph for input_wayland.c:

Go to the source code of this file.

Functions

static SBGL_Scancode wayland_key_to_scancode (uint32_t key)
 
static void pointer_enter (void *data, struct wl_pointer *p, uint32_t s, struct wl_surface *surf, wl_fixed_t sx, wl_fixed_t sy)
 
static void pointer_leave (void *data, struct wl_pointer *p, uint32_t s, struct wl_surface *surf)
 
static void pointer_motion (void *data, struct wl_pointer *p, uint32_t t, wl_fixed_t sx, wl_fixed_t sy)
 
static void pointer_button (void *data, struct wl_pointer *p, uint32_t s, uint32_t t, uint32_t button, uint32_t state)
 
static void pointer_axis (void *data, struct wl_pointer *p, uint32_t t, uint32_t axis, wl_fixed_t value)
 
static void pointer_frame (void *data, struct wl_pointer *p)
 
static void pointer_axis_source (void *data, struct wl_pointer *p, uint32_t src)
 
static void pointer_axis_stop (void *data, struct wl_pointer *p, uint32_t t, uint32_t axis)
 
static void pointer_axis_discrete (void *data, struct wl_pointer *p, uint32_t axis, int32_t discrete)
 
static void keyboard_keymap (void *data, struct wl_keyboard *k, uint32_t format, int32_t fd, uint32_t size)
 
static void keyboard_enter (void *data, struct wl_keyboard *k, uint32_t s, struct wl_surface *surf, struct wl_array *keys)
 
static void keyboard_leave (void *data, struct wl_keyboard *k, uint32_t s, struct wl_surface *surf)
 
static void keyboard_key (void *data, struct wl_keyboard *k, uint32_t s, uint32_t t, uint32_t key, uint32_t state)
 
static void keyboard_modifiers (void *data, struct wl_keyboard *k, uint32_t s, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group)
 
static void keyboard_repeat_info (void *data, struct wl_keyboard *k, int32_t rate, int32_t delay)
 
static void relative_motion (void *data, struct zwp_relative_pointer_v1 *p, uint32_t hi, uint32_t lo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel)
 
void linux_init_input (struct wl_registry *registry, uint32_t name, uint32_t version, sbgl_Window *window)
 
void linux_internal_update_input_states (sbgl_Window *window)
 

Variables

const struct wl_pointer_listener pointer_listener
 
const struct wl_keyboard_listener keyboard_listener
 
const struct zwp_relative_pointer_v1_listener relative_pointer_listener
 

Function Documentation

◆ keyboard_enter()

static void keyboard_enter ( void * data,
struct wl_keyboard * k,
uint32_t s,
struct wl_surface * surf,
struct wl_array * keys )
static

Definition at line 82 of file input_wayland.c.

82 {
83 (void)k; (void)s; (void)surf; (void)keys;
84 ((sbgl_Window*)data)->focused = true;
85}
Native X11 window state.

◆ keyboard_key()

static void keyboard_key ( void * data,
struct wl_keyboard * k,
uint32_t s,
uint32_t t,
uint32_t key,
uint32_t state )
static

Definition at line 90 of file input_wayland.c.

90 {
91 (void)k; (void)s; (void)t;
92 sbgl_InputState* input = ((struct sbgl_Window*)data)->input;
94 if (code < SBGL_SCANCODE_MAX) {
95 bool down = (state == WL_KEYBOARD_KEY_STATE_PRESSED);
96 if (down && !input->keysDown[code]) {
97 input->keysPressed[code] = true;
98 }
99 input->keysDown[code] = down;
100 }
101}
SBGL_Scancode
OS-independent physical scancodes.
Definition sbgl_input.h:21
@ SBGL_SCANCODE_MAX
Definition sbgl_input.h:137
static SBGL_Scancode wayland_key_to_scancode(uint32_t key)
Represents the real-time state of physical inputs.
Definition sbgl_input.h:165
bool keysPressed[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:167
bool keysDown[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:166
sbgl_InputState * input

◆ keyboard_keymap()

static void keyboard_keymap ( void * data,
struct wl_keyboard * k,
uint32_t format,
int32_t fd,
uint32_t size )
static

Definition at line 81 of file input_wayland.c.

81{ (void)data; (void)k; (void)format; (void)fd; (void)size; }

◆ keyboard_leave()

static void keyboard_leave ( void * data,
struct wl_keyboard * k,
uint32_t s,
struct wl_surface * surf )
static

Definition at line 86 of file input_wayland.c.

86 {
87 (void)k; (void)s; (void)surf;
88 ((sbgl_Window*)data)->focused = false;
89}

◆ keyboard_modifiers()

static void keyboard_modifiers ( void * data,
struct wl_keyboard * k,
uint32_t s,
uint32_t depressed,
uint32_t latched,
uint32_t locked,
uint32_t group )
static

Definition at line 102 of file input_wayland.c.

102{ (void)data; (void)k; (void)s; (void)depressed; (void)latched; (void)locked; (void)group; }

◆ keyboard_repeat_info()

static void keyboard_repeat_info ( void * data,
struct wl_keyboard * k,
int32_t rate,
int32_t delay )
static

Definition at line 103 of file input_wayland.c.

103{ (void)data; (void)k; (void)rate; (void)delay; }

◆ linux_init_input()

void linux_init_input ( struct wl_registry * registry,
uint32_t name,
uint32_t version,
sbgl_Window * window )

Definition at line 122 of file input_wayland.c.

122 {
123 window->seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
124}

◆ linux_internal_update_input_states()

void linux_internal_update_input_states ( sbgl_Window * window)

Definition at line 127 of file input_wayland.c.

127 {
128 sbgl_InputState* input = window->input;
129 if (!input) return;
130
131 if (!window->relative_pointer) {
132 input->mouseDeltaX = input->mouseX - input->_internalMouseX;
133 input->mouseDeltaY = input->mouseY - input->_internalMouseY;
134 }
135 // Note: If relative_pointer is active, mouseDeltaX/Y were accumulated in relative_motion.
136 // We do NOT reset them here, as they should be reset at the start of PollEvents
137 // or we should handle the accumulation window carefully.
138 // For now, assume PollEvents or the next frame will clear them if needed,
139 // but actually sbgl_InputState usually expects deltas to be "since last frame".
140
141 input->_internalMouseX = input->mouseX;
142 input->_internalMouseY = input->mouseY;
143}

◆ pointer_axis()

static void pointer_axis ( void * data,
struct wl_pointer * p,
uint32_t t,
uint32_t axis,
wl_fixed_t value )
static

Definition at line 68 of file input_wayland.c.

68{ (void)data; (void)p; (void)t; (void)axis; (void)value; }

◆ pointer_axis_discrete()

static void pointer_axis_discrete ( void * data,
struct wl_pointer * p,
uint32_t axis,
int32_t discrete )
static

Definition at line 72 of file input_wayland.c.

72{ (void)data; (void)p; (void)axis; (void)discrete; }

◆ pointer_axis_source()

static void pointer_axis_source ( void * data,
struct wl_pointer * p,
uint32_t src )
static

Definition at line 70 of file input_wayland.c.

70{ (void)data; (void)p; (void)src; }

◆ pointer_axis_stop()

static void pointer_axis_stop ( void * data,
struct wl_pointer * p,
uint32_t t,
uint32_t axis )
static

Definition at line 71 of file input_wayland.c.

71{ (void)data; (void)p; (void)t; (void)axis; }

◆ pointer_button()

static void pointer_button ( void * data,
struct wl_pointer * p,
uint32_t s,
uint32_t t,
uint32_t button,
uint32_t state )
static

Definition at line 57 of file input_wayland.c.

57 {
58 (void)p; (void)s; (void)t;
59 sbgl_InputState* input = ((struct sbgl_Window*)data)->input;
60 int btn = -1;
61 if (button == 0x110) btn = SBGL_MOUSE_BUTTON_LEFT;
62 else if (button == 0x111) btn = SBGL_MOUSE_BUTTON_RIGHT;
63 else if (button == 0x112) btn = SBGL_MOUSE_BUTTON_MIDDLE;
64 if (btn != -1 && btn < SBGL_MOUSE_BUTTON_MAX) {
65 input->mouseDown[btn] = (state == WL_POINTER_BUTTON_STATE_PRESSED);
66 }
67}
@ SBGL_MOUSE_BUTTON_MIDDLE
Definition sbgl_input.h:146
@ SBGL_MOUSE_BUTTON_MAX
Definition sbgl_input.h:147
@ SBGL_MOUSE_BUTTON_LEFT
Definition sbgl_input.h:144
@ SBGL_MOUSE_BUTTON_RIGHT
Definition sbgl_input.h:145
bool mouseDown[SBGL_MOUSE_BUTTON_MAX]
Definition sbgl_input.h:168

◆ pointer_enter()

static void pointer_enter ( void * data,
struct wl_pointer * p,
uint32_t s,
struct wl_surface * surf,
wl_fixed_t sx,
wl_fixed_t sy )
static

Definition at line 44 of file input_wayland.c.

44 {
45 (void)p; (void)s; (void)surf;
46 sbgl_InputState* input = ((struct sbgl_Window*)data)->input;
47 input->mouseX = wl_fixed_to_int(sx);
48 input->mouseY = wl_fixed_to_int(sy);
49}

◆ pointer_frame()

static void pointer_frame ( void * data,
struct wl_pointer * p )
static

Definition at line 69 of file input_wayland.c.

69{ (void)data; (void)p; }

◆ pointer_leave()

static void pointer_leave ( void * data,
struct wl_pointer * p,
uint32_t s,
struct wl_surface * surf )
static

Definition at line 50 of file input_wayland.c.

50{ (void)data; (void)p; (void)s; (void)surf; }

◆ pointer_motion()

static void pointer_motion ( void * data,
struct wl_pointer * p,
uint32_t t,
wl_fixed_t sx,
wl_fixed_t sy )
static

Definition at line 51 of file input_wayland.c.

51 {
52 (void)p; (void)t;
53 sbgl_InputState* input = ((struct sbgl_Window*)data)->input;
54 input->mouseX = wl_fixed_to_int(sx);
55 input->mouseY = wl_fixed_to_int(sy);
56}

◆ relative_motion()

static void relative_motion ( void * data,
struct zwp_relative_pointer_v1 * p,
uint32_t hi,
uint32_t lo,
wl_fixed_t dx,
wl_fixed_t dy,
wl_fixed_t dx_unaccel,
wl_fixed_t dy_unaccel )
static

Definition at line 111 of file input_wayland.c.

111 {
112 (void)p; (void)hi; (void)lo; (void)dx_unaccel; (void)dy_unaccel;
113 sbgl_Window* window = (sbgl_Window*)data;
114 window->input->mouseDeltaX += wl_fixed_to_int(dx);
115 window->input->mouseDeltaY += wl_fixed_to_int(dy);
116}

◆ wayland_key_to_scancode()

static SBGL_Scancode wayland_key_to_scancode ( uint32_t key)
static

Definition at line 4 of file input_wayland.c.

4 {
5 switch (key) {
6 case 1: return SBGL_SCANCODE_ESCAPE;
7 case 28: return SBGL_SCANCODE_RETURN;
8 case 57: return SBGL_SCANCODE_SPACE;
9 case 15: return SBGL_SCANCODE_TAB;
10 case 14: return SBGL_SCANCODE_BACKSPACE;
11 case 103: return SBGL_SCANCODE_UP;
12 case 108: return SBGL_SCANCODE_DOWN;
13 case 105: return SBGL_SCANCODE_LEFT;
14 case 106: return SBGL_SCANCODE_RIGHT;
15 case 42: return SBGL_SCANCODE_LSHIFT;
16 case 29: return SBGL_SCANCODE_LCTRL;
17 case 56: return SBGL_SCANCODE_LALT;
18 case 2: return SBGL_SCANCODE_1;
19 case 3: return SBGL_SCANCODE_2;
20 case 4: return SBGL_SCANCODE_3;
21 case 5: return SBGL_SCANCODE_4;
22 case 6: return SBGL_SCANCODE_5;
23 case 7: return SBGL_SCANCODE_6;
24 case 8: return SBGL_SCANCODE_7;
25 case 9: return SBGL_SCANCODE_8;
26 case 10: return SBGL_SCANCODE_9;
27 case 11: return SBGL_SCANCODE_0;
28 case 12: return SBGL_SCANCODE_MINUS;
29 case 13: return SBGL_SCANCODE_EQUAL;
30 case 30: return SBGL_SCANCODE_A; case 48: return SBGL_SCANCODE_B; case 46: return SBGL_SCANCODE_C;
31 case 32: return SBGL_SCANCODE_D; case 18: return SBGL_SCANCODE_E; case 33: return SBGL_SCANCODE_F;
32 case 34: return SBGL_SCANCODE_G; case 35: return SBGL_SCANCODE_H; case 23: return SBGL_SCANCODE_I;
33 case 36: return SBGL_SCANCODE_J; case 37: return SBGL_SCANCODE_K; case 38: return SBGL_SCANCODE_L;
34 case 50: return SBGL_SCANCODE_M; case 49: return SBGL_SCANCODE_N; case 24: return SBGL_SCANCODE_O;
35 case 25: return SBGL_SCANCODE_P; case 16: return SBGL_SCANCODE_Q; case 19: return SBGL_SCANCODE_R;
36 case 31: return SBGL_SCANCODE_S; case 20: return SBGL_SCANCODE_T; case 22: return SBGL_SCANCODE_U;
37 case 47: return SBGL_SCANCODE_V; case 17: return SBGL_SCANCODE_W; case 45: return SBGL_SCANCODE_X;
38 case 21: return SBGL_SCANCODE_Y; case 44: return SBGL_SCANCODE_Z;
39 default: return SBGL_SCANCODE_UNKNOWN;
40 }
41}
@ SBGL_SCANCODE_V
Definition sbgl_input.h:44
@ SBGL_SCANCODE_M
Definition sbgl_input.h:35
@ SBGL_SCANCODE_UNKNOWN
Definition sbgl_input.h:22
@ SBGL_SCANCODE_0
Definition sbgl_input.h:59
@ SBGL_SCANCODE_K
Definition sbgl_input.h:33
@ SBGL_SCANCODE_SPACE
Definition sbgl_input.h:65
@ SBGL_SCANCODE_RIGHT
Definition sbgl_input.h:70
@ SBGL_SCANCODE_9
Definition sbgl_input.h:58
@ SBGL_SCANCODE_C
Definition sbgl_input.h:25
@ SBGL_SCANCODE_2
Definition sbgl_input.h:51
@ SBGL_SCANCODE_8
Definition sbgl_input.h:57
@ SBGL_SCANCODE_A
Definition sbgl_input.h:23
@ SBGL_SCANCODE_Y
Definition sbgl_input.h:47
@ SBGL_SCANCODE_LALT
Definition sbgl_input.h:77
@ SBGL_SCANCODE_LEFT
Definition sbgl_input.h:71
@ SBGL_SCANCODE_O
Definition sbgl_input.h:37
@ SBGL_SCANCODE_R
Definition sbgl_input.h:40
@ SBGL_SCANCODE_4
Definition sbgl_input.h:53
@ SBGL_SCANCODE_Z
Definition sbgl_input.h:48
@ SBGL_SCANCODE_H
Definition sbgl_input.h:30
@ SBGL_SCANCODE_5
Definition sbgl_input.h:54
@ SBGL_SCANCODE_J
Definition sbgl_input.h:32
@ SBGL_SCANCODE_LSHIFT
Definition sbgl_input.h:75
@ SBGL_SCANCODE_ESCAPE
Definition sbgl_input.h:62
@ SBGL_SCANCODE_X
Definition sbgl_input.h:46
@ SBGL_SCANCODE_LCTRL
Definition sbgl_input.h:76
@ SBGL_SCANCODE_UP
Definition sbgl_input.h:73
@ SBGL_SCANCODE_B
Definition sbgl_input.h:24
@ SBGL_SCANCODE_DOWN
Definition sbgl_input.h:72
@ SBGL_SCANCODE_G
Definition sbgl_input.h:29
@ SBGL_SCANCODE_TAB
Definition sbgl_input.h:64
@ SBGL_SCANCODE_7
Definition sbgl_input.h:56
@ SBGL_SCANCODE_F
Definition sbgl_input.h:28
@ SBGL_SCANCODE_MINUS
Definition sbgl_input.h:67
@ SBGL_SCANCODE_RETURN
Definition sbgl_input.h:61
@ SBGL_SCANCODE_E
Definition sbgl_input.h:27
@ SBGL_SCANCODE_T
Definition sbgl_input.h:42
@ SBGL_SCANCODE_3
Definition sbgl_input.h:52
@ SBGL_SCANCODE_D
Definition sbgl_input.h:26
@ SBGL_SCANCODE_1
Definition sbgl_input.h:50
@ SBGL_SCANCODE_P
Definition sbgl_input.h:38
@ SBGL_SCANCODE_Q
Definition sbgl_input.h:39
@ SBGL_SCANCODE_BACKSPACE
Definition sbgl_input.h:63
@ SBGL_SCANCODE_L
Definition sbgl_input.h:34
@ SBGL_SCANCODE_6
Definition sbgl_input.h:55
@ SBGL_SCANCODE_S
Definition sbgl_input.h:41
@ SBGL_SCANCODE_U
Definition sbgl_input.h:43
@ SBGL_SCANCODE_N
Definition sbgl_input.h:36
@ SBGL_SCANCODE_EQUAL
Definition sbgl_input.h:68
@ SBGL_SCANCODE_I
Definition sbgl_input.h:31
@ SBGL_SCANCODE_W
Definition sbgl_input.h:45

Variable Documentation

◆ keyboard_listener

const struct wl_keyboard_listener keyboard_listener
Initial value:
= {
.keymap = keyboard_keymap, .enter = keyboard_enter, .leave = keyboard_leave,
.key = keyboard_key, .modifiers = keyboard_modifiers, .repeat_info = keyboard_repeat_info
}
static void keyboard_repeat_info(void *data, struct wl_keyboard *k, int32_t rate, int32_t delay)
static void keyboard_leave(void *data, struct wl_keyboard *k, uint32_t s, struct wl_surface *surf)
static void keyboard_keymap(void *data, struct wl_keyboard *k, uint32_t format, int32_t fd, uint32_t size)
static void keyboard_key(void *data, struct wl_keyboard *k, uint32_t s, uint32_t t, uint32_t key, uint32_t state)
static void keyboard_modifiers(void *data, struct wl_keyboard *k, uint32_t s, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group)
static void keyboard_enter(void *data, struct wl_keyboard *k, uint32_t s, struct wl_surface *surf, struct wl_array *keys)

Definition at line 105 of file input_wayland.c.

105 {
106 .keymap = keyboard_keymap, .enter = keyboard_enter, .leave = keyboard_leave,
107 .key = keyboard_key, .modifiers = keyboard_modifiers, .repeat_info = keyboard_repeat_info
108};

◆ pointer_listener

const struct wl_pointer_listener pointer_listener
Initial value:
= {
.enter = pointer_enter, .leave = pointer_leave, .motion = pointer_motion, .button = pointer_button,
.axis = pointer_axis, .frame = pointer_frame, .axis_source = pointer_axis_source,
.axis_stop = pointer_axis_stop, .axis_discrete = pointer_axis_discrete
}
static void pointer_motion(void *data, struct wl_pointer *p, uint32_t t, wl_fixed_t sx, wl_fixed_t sy)
static void pointer_button(void *data, struct wl_pointer *p, uint32_t s, uint32_t t, uint32_t button, uint32_t state)
static void pointer_axis_stop(void *data, struct wl_pointer *p, uint32_t t, uint32_t axis)
static void pointer_leave(void *data, struct wl_pointer *p, uint32_t s, struct wl_surface *surf)
static void pointer_enter(void *data, struct wl_pointer *p, uint32_t s, struct wl_surface *surf, wl_fixed_t sx, wl_fixed_t sy)
static void pointer_axis_source(void *data, struct wl_pointer *p, uint32_t src)
static void pointer_frame(void *data, struct wl_pointer *p)
static void pointer_axis_discrete(void *data, struct wl_pointer *p, uint32_t axis, int32_t discrete)
static void pointer_axis(void *data, struct wl_pointer *p, uint32_t t, uint32_t axis, wl_fixed_t value)

Definition at line 74 of file input_wayland.c.

74 {
75 .enter = pointer_enter, .leave = pointer_leave, .motion = pointer_motion, .button = pointer_button,
76 .axis = pointer_axis, .frame = pointer_frame, .axis_source = pointer_axis_source,
77 .axis_stop = pointer_axis_stop, .axis_discrete = pointer_axis_discrete
78};

◆ relative_pointer_listener

const struct zwp_relative_pointer_v1_listener relative_pointer_listener
Initial value:
= {
.relative_motion = relative_motion
}
static void relative_motion(void *data, struct zwp_relative_pointer_v1 *p, uint32_t hi, uint32_t lo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel)

Definition at line 118 of file input_wayland.c.

118 {
119 .relative_motion = relative_motion
120};