backend/wayland: simplify wl_keyboard.{enter,leave} processing

master
Kirill Primak 3 months ago committed by Alexander Orzechowski
parent 08495d2596
commit 310a5eb61c

@ -27,12 +27,14 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
struct wlr_keyboard *keyboard = data; struct wlr_keyboard *keyboard = data;
int64_t time_msec = get_current_time_msec();
uint32_t *keycode_ptr; uint32_t *keycode_ptr;
wl_array_for_each(keycode_ptr, keys) { wl_array_for_each(keycode_ptr, keys) {
struct wlr_keyboard_key_event event = { struct wlr_keyboard_key_event event = {
.keycode = *keycode_ptr, .keycode = *keycode_ptr,
.state = WL_KEYBOARD_KEY_STATE_PRESSED, .state = WL_KEYBOARD_KEY_STATE_PRESSED,
.time_msec = get_current_time_msec(), .time_msec = time_msec,
.update_state = false, .update_state = false,
}; };
wlr_keyboard_notify_key(keyboard, &event); wlr_keyboard_notify_key(keyboard, &event);
@ -43,18 +45,12 @@ static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface) { uint32_t serial, struct wl_surface *surface) {
struct wlr_keyboard *keyboard = data; struct wlr_keyboard *keyboard = data;
size_t num_keycodes = keyboard->num_keycodes; int64_t time_msec = get_current_time_msec();
uint32_t pressed[num_keycodes + 1]; while (keyboard->num_keycodes > 0) {
memcpy(pressed, keyboard->keycodes,
num_keycodes * sizeof(uint32_t));
for (size_t i = 0; i < num_keycodes; ++i) {
uint32_t keycode = pressed[i];
struct wlr_keyboard_key_event event = { struct wlr_keyboard_key_event event = {
.keycode = keycode, .keycode = keyboard->keycodes[keyboard->num_keycodes - 1],
.state = WL_KEYBOARD_KEY_STATE_RELEASED, .state = WL_KEYBOARD_KEY_STATE_RELEASED,
.time_msec = get_current_time_msec(), .time_msec = time_msec,
.update_state = false, .update_state = false,
}; };
wlr_keyboard_notify_key(keyboard, &event); wlr_keyboard_notify_key(keyboard, &event);

Loading…
Cancel
Save