Correctly read wl_array with keystate on keyboard focus gain
This commit is contained in:
parent
c98b67fcd3
commit
b2fe2b09ef
2 changed files with 17 additions and 4 deletions
18
wayland.c
18
wayland.c
|
|
@ -197,16 +197,28 @@ void keymap_callback(void *data, struct wl_keyboard *kb, uint format, int fd, ui
|
|||
fprintf(stderr, "Could not initialize XKB state machine\n");
|
||||
}
|
||||
|
||||
void enter_callback(void *data, struct wl_keyboard* kb, uint serial, struct wl_surface* surface, struct wl_array *keys)
|
||||
void enter_callback(void *data, struct wl_keyboard* kb, uint serial, struct wl_surface* surface, struct wl_array *arr)
|
||||
{
|
||||
fprintf(stdout, "KBMAP with serial %d entered surface\n", serial);
|
||||
user_input.keyboard_state = KEYBOARD_STATE_UNFOCUSED;
|
||||
user_input.keyboard_state = KEYBOARD_STATE_FOCUSED;
|
||||
|
||||
// NOTE: wl_array is a dynamic array as specified in wayland-util.h
|
||||
int32_t *pos = arr->data;
|
||||
// wl_keyboard is giving us all the currenly pressed keys anyways
|
||||
for (int i = 0; i < KEYBOARD_KEY_TOTAL)
|
||||
user_input.keys[i] = KEY_STATE_UNPRESSED;
|
||||
|
||||
wl_array_for_each(pos, arr) {
|
||||
xkb_keysym_t sym = xkb_state_key_get_one_sym(xkb_state, (*pos) + 8);
|
||||
// TODO: Decide if we should also set KEY_STATE_HELD
|
||||
user_input.keys[sym] = KEY_STATE_PRESSED;
|
||||
}
|
||||
}
|
||||
|
||||
void leave_callback(void *data, struct wl_keyboard* kb, uint serial, struct wl_surface* surface)
|
||||
{
|
||||
fprintf(stdout, "KBMAP with serial %d left surface\n", serial);
|
||||
user_input.keyboard_state = KEYBOARD_STATE_FOCUSED;
|
||||
user_input.keyboard_state = KEYBOARD_STATE_UNFOCUSED;
|
||||
}
|
||||
|
||||
void key_callback(void *data, struct wl_keyboard *kb, uint serial, uint time, uint key, uint state)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue