From e88988e364103ac0acd0da2e7642d5bf7fefd83e Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Fri, 9 Aug 2024 15:27:51 +0300 Subject: [PATCH] keyboard: simplify releasing keys on finish --- types/wlr_keyboard.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 98978ee1d..366f4218a 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -153,12 +153,11 @@ static void keyboard_unset_keymap(struct wlr_keyboard *kb) { void wlr_keyboard_finish(struct wlr_keyboard *kb) { /* Release pressed keys */ - size_t orig_num_keycodes = kb->num_keycodes; - for (size_t i = 0; i < orig_num_keycodes; ++i) { - assert(kb->num_keycodes == orig_num_keycodes - i); + int64_t time_msec = get_current_time_msec(); + while (kb->num_keycodes > 0) { struct wlr_keyboard_key_event event = { - .time_msec = get_current_time_msec(), - .keycode = kb->keycodes[orig_num_keycodes - i - 1], + .time_msec = time_msec, + .keycode = kb->keycodes[kb->num_keycodes - 1], .update_state = false, .state = WL_KEYBOARD_KEY_STATE_RELEASED, };