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 2993

Summary: SDL2 fails to get focus when running in X11 directly
Product: SDL Reporter: Dank Maymays <eimacdude>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED DUPLICATE QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: 2.0.3   
Hardware: x86_64   
OS: Linux   

Description Dank Maymays 2015-05-22 22:16:31 UTC
Many applications using SDL rely on SDL_Event.key.windowID matching the ID of the application's SDL_Window. The keyboard focus is set to a particular SDL window after a focusIn event is received from the X server (see X11_DispatchEvent() in SDL_x11events.c). However, if you're running X11 without a window manager, this focusIn event is never generated by the X-server as noted at http://stackoverflow.com/questions/18234136/focusin-focusout-not-generated

First, this behavior is not correct, as many X11 applications run fine and get and lose focus correctly without any window manager. An example is xterm: moving the mouse in and out of its area when it's run without Gnome/KDE/twm/anything still puts it in/out of focus and lets it/stops it from receiving typing.

Second, running X11 without a window manager has important use cases for kiosks, embedded applications, and so on, so saying this bug is not important because it will not affect anyone is unacceptable.

One possible fix is to add to X11_RaiseWindow() in SDL_x11windows.c the following:

X11_XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime); SDL_SetKeyboardFocus(data->window);
Comment 1 Ryan C. Gordon 2015-05-31 06:06:30 UTC
Whoops, I didn't see this bug report, and had opened another one when I fixed the issue. This should be good to go now.

--ryan.

*** This bug has been marked as a duplicate of bug 2997 ***