[linux] SDL fullscreen keyboard grab breaks alt-tabbing

Discuss problems related to FTL here. If you are having a problem or experiencing a bug PLEASE READ THE "MUST READ" POST.
Post Reply
Zorael
Posts: 4
Joined: Wed Oct 17, 2012 1:23 am

[linux] SDL fullscreen keyboard grab breaks alt-tabbing

Post by Zorael »

When you fullscreen FTL, it really really fullscreens, and as such grabs complete control of keyboard input. It bypasses all other shims such as global shortcut daemons or window managers, and is expected behavior of SDL and X.org both.
- "Fake" fullscreen: Wine apps, Firefox, Totem. They don't grab the
keyboard. Basically, they hide the window decoration and fill the screen
with the window.

- "True" fullscreen: Games. They grab the keyboard control, so Gnome
can't do anything. If an app like this crashes, you can't even call
System Monitor to kill it (like ctrl + alt + del in Windows).
[source]

The cause is that the game grabs all mouse and keyboard input with
SDL_WM_GrabInput() to lock the mouse to the window, which is desirable,
but which then prevents the window managers from registering Alt-Tab
requests.

Unfortunately, Alt-Tab wasn't set as a standard by SDL leaving the
games to support Alt-Tab themselves in their own input routines. And
they mostly don't...
[source]


Would it be possible to implement a faux alt-tab for such fullscreen cases? As in, when alt-tab is pressed, minimize and give focus to the root window? Maybe also listen and react to common keys, like XF86AudioRaiseVolume and friends (refer to /usr/include/X11/XF86keysym.h) -- or simply let everything not relevant to FTL pass through?


The best workaround I've found so far is to patch SDL to always allow for alt-tab to seep through, but obviously it would be neater with a fix built into FTL proper. There's also a preload hack if you don't want to compile stuff yourself, but this way I also nail other SDL games I play.

...well, the neatest way would be if X.org was a bit more lenient. But there seems to be valid reasons for this stringency.
boa13
Posts: 808
Joined: Mon Sep 17, 2012 11:42 pm

Re: [linux] SDL fullscreen keyboard grab breaks alt-tabbing

Post by boa13 »

For your information, I have my screen set at 1280x720 resolution (native game resolution), and I use the KDE options to remove the window decorations, so I effectively get a full-screen experience, with full Alt-Tab support (and it's nice to see the game keeps running while fancy window 3D effects are going on).

Still, it would be nice to have some form of Alt-Tab support for those who use the "real" fullscreen option.
Forum janitor — If you spot spam, PM me the URL and/or the username of the spammer.
I have powers, moderator powers. I am not keen on using them, but will do so if needed.
Zorael
Posts: 4
Joined: Wed Oct 17, 2012 1:23 am

Re: [linux] SDL fullscreen keyboard grab breaks alt-tabbing

Post by Zorael »

My native resolution on this laptop is 1920x1080. As you say, I could lower resolution and do borderless fullscreen; this I concede. I could probably also have KWin zoom into the window to enlargen it.

On the topic of windowed mode, the mouse grab feature that Alt+G triggers is very convenient. With it enabled, your mouse cursor is trapped inside the game window until you hit Alt+G again or Alt+Tab.

If someone does end up patching, what I failed to mention in the original post was that FTL will by default load its bundled SDL library file, located at data/<arch>/lib/libSDL-1.2.so.0. If you want to override it you could LD_PRELOAD your patched library, replace the bundled file outright, or simply rename it to have the game search the normal library locations. That's assuming it finds your patched version there.

(Also don't forget to set the needed environment variables. Refer to the patch link.)
Post Reply