Update: A less intrusive way can be found here.

Some years ago I wrote an article about how to prevent libsdl from grabbing all your input devices to allow task-switching in commercial and non-commercial games. I use it for several years now (since around 2004) and this approach has proven to work very well. Today I want to give you an update on this since the original article is not available any more. First I will tell you which changes I made and after that I will give you my patch. I also have ready to use 32 and 64 bit binaries at the end. I used libsdl 1.2.13 because libsdl 1.2.14, which is shipped in Ubuntu 10.04 has a bug which prevents mouse-clicks in Battle for Wesnoth when the game is not in fullscreen mode.
The result will be libsdl 1.2.13 with the complete audio stack from 1.2.14. Applications, which demand fullscreen will simply get a border-less window and input grabbing will be disabled to allow task-switching, changing volume etc. in the same way you know it from M$ Windows.

I changed the following things:

  • Audio
    I had no sound using my custom 1.2.13 in Lucid. Copying the audio tree over from 1.2.14 solved this issue for me. I really just copied over the whole audio directory after deleting it in 1.2.13. I ran in no problems and it seems to work very well.
  • Kill real fullscreen
    This is the patch you will know already if you have read my article about it a few years ago. All video functions, which get "Uint32 flags" as a parameter unset the SDL_FULLSCREEN flag and instead set the SDL_NOFRAME flag, if the applications demands fullscreen. All of these functions are now starting with the following

    if (flags & SDL_FULLSCREEN) {
         flags = flags^SDL_FULLSCREEN;
         flags = flags^SDL_NOFRAME;
    }
    
  • Disable Input-grabbing
    The final change I did was removing the ability to grab the keyboard and mouse completely. X11 offers this functionality through X11_GrabInput. In SDL this sucks as it simply is often used when it shouldn't be. To remove it I altered the file src/video/x11/SDL_x11video.c where I changed

    device->GrabInput = X11_GrabInput;

    into

    device->GrabInput = NULL;
Compile it yourself

OK, now as promised, here is the patch: libsdl1.2_1.2.13-4ubuntu4_nofullscreen.patch
This patch is made against libsdl1.2_1.2.13-4ubuntu4, so you have to apply that patch first before applying mine. You will find the original files at http://packages.ubuntu.com/source/karmic/libsdl1.2

To get, patch and build everything, open a shell and do (preferably in an empty folder)

wget http://archive.ubuntu.com/ubuntu/pool/main/libs/libsdl1.2/libsdl1.2_1.2.13.orig.tar.gz
wget http://archive.ubuntu.com/ubuntu/pool/main/libs/libsdl1.2/libsdl1.2_1.2.13-4ubuntu4.diff.gz
wget http://moritz4.homeip.net/moritzmolch.de/files/libsdl1.2_1.2.13-4ubuntu4_nofullscreen.patch
tar -xzf libsdl1.2_1.2.13.orig.tar.gz
cd SDL-1.2.13/
gzip -cd ../libsdl1.2_1.2.13-4ubuntu4.diff.gz | patch -p1
patch -p1 < ../libsdl1.2_1.2.13-4ubuntu4_nofullscreen.patch
./configure && make

The resulting file will be build/.libs/libSDL-1.2.so.0.11.2

Note: You should do this on a 32bit system or in a 32bit chroot, since most (commercial) games are still 32 bit. Especially all old games. For games in the repository this will work though.

Supported games

I use this patch currently with Aquaria, Battle for Wesnoth and Ankh 1&2 but it should work with Neverwinter Nights, CivCTP and everything else which dynamically links in libsdl. At least my old version worked with all of them. Note though, that this approach works only for games, which are controlled by a mouse-pointer or which are keyboard-only since shooters and the like needs to grab the mouse otherwise you won't be able to turn around completely.

  • Here is a screenshot of Aquaria in window picking mode. Normally this is not possible, because the game grabs all input devices.
  • Battle for Wesnoth as fullscreen window on virtual desktop nr. 5. (Normally it covers the taskbar. Gnome-screenshot was stealing the focus here.)

Ready to use binaries
If you don't want to compile it yourself, here are the 32 and 64 bit versions, compiled on lucid:

If you have any problems or questions about my patch, feel free to leave a comment.


4 Responses to “Lucid Lynx and my “task-switch” libsdl patch”

  1. Antoni Ten
    October 7th, 2010 at 00:00
    1

    I’m very interested in this.

    I wanted to get Aquaria and World of Goo to work without changing my display configuration (I have two monitors, and when they grab the input, they switch one of the monitors off). Changing the libSDL-1.2 that comes in their respective directories and running them in windowed mode actually makes them run better in my system! Many thanks for the tip.

    P.S. Running Ubuntu Lucid

  2. Moritz
    October 8th, 2010 at 00:50
    2

    I’m glad to hear that it works fine for you. Btw., I wrapped my World of Goo executable inside a script which changes the screen resolution to 800×600 via xrandr to have it covering the whole screen.

  3. Eemil
    December 23rd, 2010 at 21:23
    3

    Thanks for getting me Aquaria with task switching.
    The prebuilt 32-bit binary works in Maverick 64-bit, but I had to create some symlinks because of newer dependency versions.

1 trackbacks


Leave a Comment

I respect your privacy
I don't run any trackers on this site.

Your questionable browsing-history should remain between you and the NSA ;-)
Contact