keyboard: simplify releasing keys on finish

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

View File

@ -153,12 +153,11 @@ static void keyboard_unset_keymap(struct wlr_keyboard *kb) {
void wlr_keyboard_finish(struct wlr_keyboard *kb) { void wlr_keyboard_finish(struct wlr_keyboard *kb) {
/* Release pressed keys */ /* Release pressed keys */
size_t orig_num_keycodes = kb->num_keycodes; int64_t time_msec = get_current_time_msec();
for (size_t i = 0; i < orig_num_keycodes; ++i) { while (kb->num_keycodes > 0) {
assert(kb->num_keycodes == orig_num_keycodes - i);
struct wlr_keyboard_key_event event = { struct wlr_keyboard_key_event event = {
.time_msec = get_current_time_msec(), .time_msec = time_msec,
.keycode = kb->keycodes[orig_num_keycodes - i - 1], .keycode = kb->keycodes[kb->num_keycodes - 1],
.update_state = false, .update_state = false,
.state = WL_KEYBOARD_KEY_STATE_RELEASED, .state = WL_KEYBOARD_KEY_STATE_RELEASED,
}; };