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.
This commit is contained in:
Bastien Bouclet 2017-04-22 19:53:52 +02:00
parent 5dc350133f
commit 545fba7886

View file

@ -348,6 +348,7 @@ X11_ReconcileKeyboardState(_THIS)
Window junk_window; Window junk_window;
int x, y; int x, y;
unsigned int mask; unsigned int mask;
const Uint8 *keyboardState;
X11_XQueryKeymap(display, keys); X11_XQueryKeymap(display, keys);
@ -357,11 +358,16 @@ X11_ReconcileKeyboardState(_THIS)
SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0); SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0);
} }
keyboardState = SDL_GetKeyboardState(0);
for (keycode = 0; keycode < 256; ++keycode) { for (keycode = 0; keycode < 256; ++keycode) {
if (keys[keycode / 8] & (1 << (keycode % 8))) { SDL_Scancode scancode = viddata->key_layout[keycode];
SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode]); SDL_bool x11KeyPressed = (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
} else { SDL_bool sdlKeyPressed = keyboardState[scancode] == SDL_PRESSED;
SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode]);
if (x11KeyPressed && !sdlKeyPressed) {
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
} else if (!x11KeyPressed && sdlKeyPressed) {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
} }
} }
} }