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 3287 - In 2.0.4 Fullscreen/ShowWindow started causing repeat SDL_KEYDOWN on X11
Summary: In 2.0.4 Fullscreen/ShowWindow started causing repeat SDL_KEYDOWN on X11
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86_64 Linux
: P2 blocker
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-10 21:35 UTC by Kevin Locke
Modified: 2017-11-11 18:40 UTC (History)
4 users (show)

See Also:


Attachments
Example program which causes the issue by pressing f (5.04 KB, text/x-csrc)
2016-03-10 21:35 UTC, Kevin Locke
Details
Example program output for changeset 6ab4d6f34afb (1.63 KB, text/plain)
2016-03-10 21:35 UTC, Kevin Locke
Details
Example program output for changeset 1021c9bd0f64 (2.34 KB, text/plain)
2016-03-10 21:36 UTC, Kevin Locke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Locke 2016-03-10 21:35:05 UTC
Created attachment 2391 [details]
Example program which causes the issue by pressing f

Starting in the 2.0.4 release, toggling fullscreen in response to an SDL_KEYDOWN event can cause a repeat SDL_KEYDOWN event to be fired immediately on X11 when the mouse cursor is not inside the (non-fullscreen) window.

I bisected the issue down to changeset 1021c9bd0f64 <http://hg.libsdl.org/SDL/rev/1021c9bd0f64> which introduced handling of the X11 KeymapNotify event.  I presume a KeymapNotify is sent as part of the fullscreen+enter events which causes keydown to be emitted again immediately, but I am not familiar enough with the details to know for sure. 

The attachment sdl-repeat-keydown-fullscreen.c demonstrates the issue on my system.  On 2.0.4, when the window has focus and the user presses 'f' to toggle fullscreen, the window becomes fullscreen then a repeat SDL_KEYDOWN event is emitted, then the window becomes non-fullscreen again.  On 2.0.3 and earlier pressing 'f' toggles fullscreen and no repeat SDL_KEYDOWN event is emitted leaving the window in fullscreen.

The attachment output-1021c9bd0f64.txt has the event output produced for changeset 1021c9bd0f64 and output-6ab4d6f34afb.txt for 6ab4d6f34afb (its parent).

An obvious workaround is to prevent repeat keypresses from toggling fullscreen, and I am making that change to my affected programs, but I assumed the behavior was unintentional and may be worth fixing to save other SDL developers the effort of tracking down this issue.

Thanks,
Kevin
Comment 1 Kevin Locke 2016-03-10 21:35:46 UTC
Created attachment 2392 [details]
Example program output for changeset 6ab4d6f34afb
Comment 2 Kevin Locke 2016-03-10 21:36:06 UTC
Created attachment 2393 [details]
Example program output for changeset 1021c9bd0f64
Comment 3 Cole Robinson 2016-05-06 15:18:21 UTC
qemu is suffering from the same problem, and I can confirm that changeset 1021c9bd0f64 is the culprit for SDL_SetWindowFullscreen

qemu has another similar issue with repeat KEYDOWN events on ShowWindow. I bisected to just a few commits earlier:

  https://hg.libsdl.org/SDL/rev/e55dad50b3ae
  Author: Sam Lantinga <slouken@libsdl.org>
  Date:   Thu May 28 09:52:48 2015 -0700

      Fixed X11 build, added code to print initial modifiers to checkkeys

  https://hg.libsdl.org/SDL/rev/7099e2df7b29
  Author: Sam Lantinga <slouken@libsdl.org>
  Date:   Thu May 28 09:33:47 2015 -0700

      Fixed bug 2736 - X11 doesn't set KMOD_NUM and KMOD_CAPS to system state


Since the commits overlap I assume it's the same root issue.

CCing Ryan C. Gordon who was commenting in the referenced bug #2736
Comment 4 Alex Smith 2016-09-21 10:57:24 UTC
Also seeing this bug here on 2.0.4 and latest HG. Worked around by ignoring repeat keypresses for fullscreen toggling.
Comment 5 Sam Lantinga 2016-10-01 19:50:39 UTC
Hey Ryan, can you fix this for 2.0.5? This is a pretty critical regression.
Comment 6 Cole Robinson 2017-10-20 12:48:50 UTC
The fullscreen issue seems fixed with 2.0.6, at least the SDL2-2.0.6-2 version in Fedora 27. The similar ShowWindow issues I mentioned in Comment #3 are still present though and are the more crippling problem for qemu's SDL usage...
Comment 7 Andrey Alexeyev 2017-11-11 18:20:24 UTC
This is still not fixed as of SDL 2.0.7 / 2.0.8dev.
Comment 8 Andrey Alexeyev 2017-11-11 18:40:15 UTC
Seems like user events, at least those generated when handling a legit SDL_KEYDOWN, are affected by this as well. I'll see if I can construct a test case later.