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

This commit is contained in:
Kirill Primak 2024-08-09 15:27:17 +03:00 committed by Alexander Orzechowski
parent 08495d2596
commit 310a5eb61c

View File

@ -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) {
struct wlr_keyboard *keyboard = data;
int64_t time_msec = get_current_time_msec();
uint32_t *keycode_ptr;
wl_array_for_each(keycode_ptr, keys) {
struct wlr_keyboard_key_event event = {
.keycode = *keycode_ptr,
.state = WL_KEYBOARD_KEY_STATE_PRESSED,
.time_msec = get_current_time_msec(),
.time_msec = time_msec,
.update_state = false,
};
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) {
struct wlr_keyboard *keyboard = data;
size_t num_keycodes = keyboard->num_keycodes;
uint32_t pressed[num_keycodes + 1];
memcpy(pressed, keyboard->keycodes,
num_keycodes * sizeof(uint32_t));
for (size_t i = 0; i < num_keycodes; ++i) {
uint32_t keycode = pressed[i];
int64_t time_msec = get_current_time_msec();
while (keyboard->num_keycodes > 0) {
struct wlr_keyboard_key_event event = {
.keycode = keycode,
.keycode = keyboard->keycodes[keyboard->num_keycodes - 1],
.state = WL_KEYBOARD_KEY_STATE_RELEASED,
.time_msec = get_current_time_msec(),
.time_msec = time_msec,
.update_state = false,
};
wlr_keyboard_notify_key(keyboard, &event);