Commit d133a5f6f7c1ae4a2c89eb767c29d19723252358

Cameron Gutman 2021-01-24T17:19:48

wayland: cancel key repeat when keyboard focus is lost SDL_SetKeyboardFocus(NULL) will lift any keys still pressed when keyboard focus leaves the window, but then key repeat comes behind our backs and presses the key down again. This results in an infinite stream of SDL_KEYDOWN events when focus leaves the window with a key down (particularly noticeable with Alt+Tab).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index d485de1..0cb1f67 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -731,6 +731,12 @@ static void
 keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
                       uint32_t serial, struct wl_surface *surface)
 {
+    struct SDL_WaylandInput *input = data;
+
+    /* Stop key repeat before clearing keyboard focus */
+    keyboard_repeat_clear(&input->keyboard_repeat);
+
+    /* This will release any keys still pressed */ 
     SDL_SetKeyboardFocus(NULL);
 }