We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3637

Summary: [PATCH] Duplicate SDL_KEYDOWN when the window state changes
Product: SDL Reporter: bastien.bouclet
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: drmccoy, icculus, ori
Version: HG 2.1   
Hardware: x86_64   
OS: Linux   
Attachments: Possible fix

Description bastien.bouclet 2017-04-22 17:58:49 UTC
Created attachment 2725 [details]
Possible fix

SDL sends duplicate SDL_KEYDOWN events with 'repeat = true' when the window gets focus.

This is caused by X11_ReconcileKeyboardState calling SDL_SendKeyboardKey even for keys which are already known to be pressed by SDL, and for which the application has already been notified.

In the case of our application toggling fullscreen is triggered by the 'alt+return' shortcut. SDL sends two SDL_KEYDOWN events causing the application to go fullscreen and immediatly back to windowed mode.

The attached patch contains a possible fix.
Comment 1 Ryan C. Gordon 2017-05-29 21:13:00 UTC
This patch looks reasonable to me; I wonder if we refactored this to make the higher level keypress handler deal with repeat keys at some point, and ReconcileKeyboardState was still assuming the higher level would throw the existing presses away.

--ryan.
Comment 2 Ryan C. Gordon 2017-05-29 22:29:37 UTC
(In reply to Ryan C. Gordon from comment #1)
> This patch looks reasonable to me; I wonder if we refactored this to make
> the higher level keypress handler deal with repeat keys at some point, and
> ReconcileKeyboardState was still assuming the higher level would throw the
> existing presses away.

If this was the culprit, this has been broken since SDL 1.3.  :(

https://hg.libsdl.org/SDL/rev/e2d46c5c7483

--ryan.
Comment 3 Ryan C. Gordon 2017-05-29 22:32:16 UTC
This patch is now https://hg.libsdl.org/SDL/rev/1f2cb42aa5d3, thanks!

--ryan.