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 - [PATCH] Duplicate SDL_KEYDOWN when the window state changes
Summary: [PATCH] Duplicate SDL_KEYDOWN when the window state changes
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-22 17:58 UTC by bastien.bouclet
Modified: 2017-05-29 22:32 UTC (History)
3 users (show)

See Also:


Attachments
Possible fix (1.70 KB, patch)
2017-04-22 17:58 UTC, bastien.bouclet
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.