[PATCH] Grabbing the keyboard in X11

Hi,

At the moment, SDL grabs both the keyboard and mouse on X11 when
SDL_SetWindowGrab() is called, but only grabs the mouse on win32 and
other platforms. This means that Alt+Tab (and similar WM keys) don’t
work, which is a bit of a pain. While the old-style X11 fullscreen code
(for WMs which aren’t ICCCM-2.0 compliant) needs the keyboard grabbed,
otherwise simply grabbing the mouse suffices.

There are a couple of different ways of resolving this: allowing the
user to grab the mouse and keyboard separately, perhaps with something
like SDL_SetWindowGrab(w, SDL_GRAB_KEYBOARD | SDL_GRAB_MOUSE), or by
simply making the X11 backend only grab the keyboard when in old-style
fullscreen mode. I have implemented the latter — the patch is attached
— and it seems to work quite well.

What do you think the right way forward is?

Cheers,
– David
-------------- next part --------------
A non-text attachment was scrubbed…
Name: no-x11-kbd-grab.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120612/86f5a851/attachment.bin

Hey,

I have just noticed that the Alt-Tab window management key combination
does not do its job of switching windows on X11 (with the Unity shell on
Ubuntu 12.04), in case window input is grabbed for a fullscreen window
using SDL_SetWindowGrab.

The reason: Keyboard input is grabbed. At least, you cannot change to a
different window using Alt-Tab, although other key combinations used for
desktop/window management seem to work (like Ctrl-Alt-RightArrow for
changing to a different workspace).

This post is also (sort of) an attempt to reply to an older post on the
list, which also had a minor patch. A copy of the patch, along with the
original post, may currently be found here (yeah, the “bin” file should
be opened as a textual one):

http://comments.gmane.org/gmane.comp.lib.sdl/56621

In case you don’t trust this, I have also attached a copy of the patch
to this mail (using what is apparently the original filename).

Apart from this patch, there is a problematic workaround I can suggest:
Call SDL_SetWindowGrab(SDL_FALSE) if the window is fullscreen. There is
one limitation with that (which may not be the only one): If
SDL_SetRelativeMouseMode(SDL_TRUE) has also been called, then no
relative mouse motion event arrives while a mouse button is pressed. I
can’t tell for sure what’s the case with SDL_FALSE, as it’s less relevant.

Thanks,
NY
-------------- next part --------------
A non-text attachment was scrubbed…
Name: no-x11-kbd-grab.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130701/2e9a2dbb/attachment.bin