# HG changeset patch # User Bastien Bouclet # Date 1492883632 -7200 # Sat Apr 22 19:53:52 2017 +0200 # Node ID ad7268bd9f0b17822f4a78da8f856596342f06fc # Parent 2653833db94e05638c6ea8ff677e8ce083ec3658 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. diff -r 2653833db94e -r ad7268bd9f0b src/video/x11/SDL_x11events.c --- a/src/video/x11/SDL_x11events.c Thu Apr 20 21:31:44 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); } } }