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.
This commit is contained in:
Campbell Barton 2022-06-23 15:38:43 +10:00
parent e4f51b3a6e
commit d20bad914e

@ -47,6 +47,8 @@
static GHOST_WindowWayland *window_from_surface(struct wl_surface *surface); 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. * 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. * 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->wl_keyboard) {
if (input->key_repeat.timer) { if (input->key_repeat.timer) {
delete static_cast<key_repeat_payload_t *>(input->key_repeat.timer->getUserData()); keyboard_handle_key_repeat_cancel(input);
input->system->removeTimer(input->key_repeat.timer);
input->key_repeat.timer = nullptr;
} }
wl_keyboard_destroy(input->wl_keyboard); wl_keyboard_destroy(input->wl_keyboard);
} }
@ -1699,9 +1699,8 @@ static void keyboard_handle_enter(void *data,
struct wl_surface *surface, struct wl_surface *surface,
struct wl_array * /*keys*/) struct wl_array * /*keys*/)
{ {
if (surface != nullptr) { input_t *input = static_cast<input_t *>(data);
static_cast<input_t *>(data)->focus_keyboard = surface; input->focus_keyboard = surface;
}
} }
/** /**
@ -1713,10 +1712,14 @@ static void keyboard_handle_enter(void *data,
static void keyboard_handle_leave(void *data, static void keyboard_handle_leave(void *data,
struct wl_keyboard * /*wl_keyboard*/, struct wl_keyboard * /*wl_keyboard*/,
uint32_t /*serial*/, uint32_t /*serial*/,
struct wl_surface *surface) struct wl_surface * /*surface*/)
{ {
if (surface != nullptr) { input_t *input = static_cast<input_t *>(data);
static_cast<input_t *>(data)->focus_keyboard = nullptr; 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; 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<key_repeat_payload_t *>(input->key_repeat.timer->getUserData());
input->system->removeTimer(input->key_repeat.timer);
input->key_repeat.timer = nullptr;
}
/** /**
* Restart the key-repeat timer. * Restart the key-repeat timer.
* \param use_delay: When false, use the interval * \param use_delay: When false, use the interval