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
3
input.h
3
input.h
|
|
@ -45,10 +45,11 @@ typedef enum {
|
|||
} mouse_keysym_t;
|
||||
|
||||
#define IME_STR_MAX 200 // TODO: check if this limit is sensible
|
||||
#define KEYBOARD_KEY_TOTAL
|
||||
|
||||
typedef struct {
|
||||
uint8_t keyboard_state; // mostly used to check if we are using the IME
|
||||
uint8_t keys[256]; // the state of the full keyboard
|
||||
uint8_t keys[KEYBOARD_KEY_TOTAL]; // the state of the full keyboard
|
||||
uint8_t mouse_state;
|
||||
int32_t mouse_x;
|
||||
int32_t mouse_y;
|
||||
|
|
|
|||
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