[Commits] SDL: x11: Don't send duplicate events when reconciling the keybo...

libsdl.org revision control commits-owner at libsdl.org
Mon May 29 15:31:52 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/1f2cb42aa5d3
changeset: 11055:1f2cb42aa5d3
user:      Bastien Bouclet <bastien.bouclet at gmail.com>
date:      Sat Apr 22 19:53:52 2017 +0200
description:
x11: Don't send duplicate events when reconciling the keyboard state

Failing to check if a key was known to be pressed by SDL was causing
SDL_SendKeyboardKey to send duplicate key pressed events with the repeat
property set to true.

Fixes Bugzilla #3637.

diffstat:

 src/video/x11/SDL_x11events.c |  14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r 0092cb66f341 -r 1f2cb42aa5d3 src/video/x11/SDL_x11events.c
--- a/src/video/x11/SDL_x11events.c	Mon May 29 18:24:06 2017 -0400
+++ b/src/video/x11/SDL_x11events.c	Sat Apr 22 19:53:52 2017 +0200
@@ -348,6 +348,7 @@
     Window junk_window;
     int x, y;
     unsigned int mask;
+    const Uint8 *keyboardState;
 
     X11_XQueryKeymap(display, keys);
 
@@ -357,11 +358,16 @@
         SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0);
     }
 
+    keyboardState = SDL_GetKeyboardState(0);
     for (keycode = 0; keycode < 256; ++keycode) {
-        if (keys[keycode / 8] & (1 << (keycode % 8))) {
-            SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode]);
-        } else {
-            SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode]);
+        SDL_Scancode scancode = viddata->key_layout[keycode];
+        SDL_bool x11KeyPressed = (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
+        SDL_bool sdlKeyPressed = keyboardState[scancode] == SDL_PRESSED;
+
+        if (x11KeyPressed && !sdlKeyPressed) {
+            SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+        } else if (!x11KeyPressed && sdlKeyPressed) {
+            SDL_SendKeyboardKey(SDL_RELEASED, scancode);
         }
     }
 }


More information about the commits mailing list