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 2997

Summary: X11 never gets focus event without a Window Manager
Product: SDL Reporter: Ryan C. Gordon <icculus>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: benoit.pierre, eimacdude
Version: HG 2.0Keywords: target-2.0.4
Hardware: All   
OS: Linux   
Attachments: fix window manager detection

Description Ryan C. Gordon 2015-05-29 17:47:39 UTC
If you have no window manager running, SDL apps never get a FocusIn event, so they never think they have keyboard focus.

As reported here:

    https://answers.unrealengine.com/questions/231361/keyboard-doesnt-work-without-display-manager-gnome.html#answer-232306

Apparently Chromium reacts to MapNotify to handle this scenario:
    http://src.chromium.org/svn/branches/1312/src/ui/aura/root_window_host_linux.cc

StackOverflow confirms:
    http://stackoverflow.com/questions/26863470/sdl2-input-focus

Must fix for 2.0.4.

--ryan.
Comment 1 Ryan C. Gordon 2015-05-29 19:22:46 UTC
This is now fixed in https://hg.libsdl.org/SDL/rev/aa4e4768c6c1

--ryan.
Comment 2 Ryan C. Gordon 2015-05-31 06:06:30 UTC
*** Bug 2993 has been marked as a duplicate of this bug. ***
Comment 3 Benoit Pierre 2015-07-03 10:57:14 UTC
Created attachment 2211 [details]
fix window manager detection

My SDL application does not start with this fix:

- my window manager is awesome (http://awesome.naquadah.org/)
- I get the following error:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  189
  Current serial number in output stream:  190

It seems the window manager detection code in X11_HasWindowManager does not detect awesome. The code mentions Chromium has being the source of the method, but after checking out the latest version, I could not find it. Instead, the latest version of Chromium is using _NET_SUPPORTING_WM_CHECK, which seems more in-line with the freedesktop documentation (http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472693600). In fact, the exact same method is already used in the SDL X11 video subsystem implementation (see X11_CheckWindowManager).

Consequently, the attached patch gets rid of X11_CheckWindowManager and reuse the result of the checks in X11_CheckWindowManager.

Tested both without a window manager, and with awesome and openbox.
Comment 4 Benoit Pierre 2015-07-03 10:59:00 UTC
Typo in my last comment: the patch gets rid of X11_HasWindowManager.
Comment 5 Sam Lantinga 2015-07-03 16:20:37 UTC
Thanks, your patch has been applied!
https://hg.libsdl.org/SDL/rev/025e28f516ce