From d20bad914e310f93f53dba4decf6e1e534a08345 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 23 Jun 2022 15:38:43 +1000 Subject: [PATCH] Fix key repeat continuing after a window loses focus for GHOST/Wayland Also remove NULL checks in keyboard enter/leave handlers, as they didn't serve any purpose. --- intern/ghost/intern/GHOST_SystemWayland.cpp | 29 ++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index a5359b8dd28..2adbca7ee40 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -47,6 +47,8 @@ static GHOST_WindowWayland *window_from_surface(struct wl_surface *surface); +static void keyboard_handle_key_repeat_cancel(struct input_t *input); + /** * GNOME (mutter 42.2 had a bug with confine not respecting scale - Hi-DPI), See: T98793. * Even though this has been fixed, at time of writing it's not yet in a release. @@ -365,9 +367,7 @@ static void display_destroy(display_t *d) } if (input->wl_keyboard) { if (input->key_repeat.timer) { - delete static_cast(input->key_repeat.timer->getUserData()); - input->system->removeTimer(input->key_repeat.timer); - input->key_repeat.timer = nullptr; + keyboard_handle_key_repeat_cancel(input); } wl_keyboard_destroy(input->wl_keyboard); } @@ -1699,9 +1699,8 @@ static void keyboard_handle_enter(void *data, struct wl_surface *surface, struct wl_array * /*keys*/) { - if (surface != nullptr) { - static_cast(data)->focus_keyboard = surface; - } + input_t *input = static_cast(data); + input->focus_keyboard = surface; } /** @@ -1713,10 +1712,14 @@ static void keyboard_handle_enter(void *data, static void keyboard_handle_leave(void *data, struct wl_keyboard * /*wl_keyboard*/, uint32_t /*serial*/, - struct wl_surface *surface) + struct wl_surface * /*surface*/) { - if (surface != nullptr) { - static_cast(data)->focus_keyboard = nullptr; + input_t *input = static_cast(data); + input->focus_keyboard = nullptr; + + /* Losing focus must stop repeating text. */ + if (input->key_repeat.timer) { + keyboard_handle_key_repeat_cancel(input); } } @@ -1746,6 +1749,14 @@ static xkb_keysym_t xkb_state_key_get_one_sym_without_modifiers(struct xkb_state return sym; } +static void keyboard_handle_key_repeat_cancel(input_t *input) +{ + GHOST_ASSERT(input->key_repeat.timer != nullptr, "Caller much check for timer"); + delete static_cast(input->key_repeat.timer->getUserData()); + input->system->removeTimer(input->key_repeat.timer); + input->key_repeat.timer = nullptr; +} + /** * Restart the key-repeat timer. * \param use_delay: When false, use the interval