Desktop environment manipulation from the command line
January 9th 2011
I recently discovered Regnum Online, a very good MMORPG, with two interesting properties: it has a native Linux version, and is free to download and play (NGD, its owner, gets revenue through so called "premium items", which are sold for real money. Premium items are not really necessary to play, but include convenience items like mounts, to travel faster than on foot).
It so happens that Regnum can be played either in windowed mode, or fullscreen. Obviously the latter takes advantage of the whole screen, but sadly it can not be minimized or alt-tabbed to a different window. Being able to minimize the Regnum window and switching to another task is interesting, for example, to leave your character resting after a battle (it takes some time to heal back to normality), and checking your e-mail meanwhile. However, playing in windowed mode feels uncomfortable, with not all the screen being used, and having your desktop bars above and/or below the window you are playing on.
To have the advantages of both windowed and fullscreen mode at the same time (and none of their disadvantages), I thought of the following: I can play on 1440x900 resolution (my whole screen), hiding the top and bottom bars (I use GNOME, with both bars), and getting rid of the window decoration of the Regnum window (which would eat some of the 900 vertical pixels). While we are at it, it would be cool to stop Compiz Fusion before running Regnum (to dedicate the whole video card to the game), and starting it again after closing it.
The problem is, I do not like to have autohiding panels in GNOME, and I like window decorations and Compiz effects, so the desktop settings for playing would have to be turned on before playing, and off after that. The next problem in the line is that I don't like performing repetitive tasks such as pointing, clicking and choosing options from menus every time I feel like playing a game. Since I already click a button to start Regnum, it would be cool to have all configuration stuff happen by just clicking that same button. Obviously, that means automating all the configuration by placing the corresponding commands in a script, and making the Regnum button execute that script.
That part was easy. We want to switch from Compiz to Metacity, which can be done with:
Autohiding GNOME panels
Some googling yielded this ubuntu-tutorials page, which led me to:
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "true"
Eliminating window decorations
All you can google about it will lead you to a little wonder called Devil's Pie. In short, it's a kind of daemon that checks for windows that match some user-defined rules, and performs on them the corresponding user-defined actions.
In my case, I defined a rule (in ~/.devilspie/regnum.ds):
(if (is (application_name) "Untitled window") (begin (undecorate) ) )
Running devilspie from the command line will show the properties of all open windows, which will help you create the appropriate condition for the rule. In my case, apparently the final Regnum window is identified only as "Untitled window".
Running Regnum, and waiting for it to finish
Waiting for Regnum to finish is not trivial, since once fully running it returns the control to the shell. For that reason, the following will not work:
$ echo "start" $ regnum-online $ echo "end"
It will echo "start", then start Regnum, then echo "end", while Regnum is still running. To fix that, I added a loop to my script, which only exits once Regnum has finished. There must be more elegant and less hacky ways of doing it, but this one works:
while [[ -n "`ps aux| grep -e regnum-online -e "./game" | grep -v grep`" ]] do sleep 5 done
Every 5 seconds, it runs some ps command, and exits when the output is empty. The command itself is a simple grep to a ps, adding the grep -v grep so that the grep command is not catched by itself.
After closing Regnum, and whole script
So, after the while loop above exits, all we have to do is undo the settings changes we just did, and exit. The whole script would read:
#!/bin/bash # Substitute Compiz with Metacity: metacity --replace & # Autohide top and bottom pannels: gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true" gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "true" # Run devilspie, to remove decoration in Regnum Online windows: /usr/bin/devilspie & # Run Regnum Online: /usr/bin/regnum-online # Wait until RO finishes: while [[ -n "`ps aux| grep -e regnum-online -e "./game" | grep -v grep`" ]] do sleep 5 done # Kill devilspie: killall devilspie # Show top and bottom pannels: gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "false" gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false" # Run Compiz again: compiz --replace --sm-disable --ignore-desktop-hints ccp --loose-binding --indirect-rendering &
Finally, I just named this script "RegnumRun.sh", made it executable, placed it in a suitable place, and associated the Regnum icon on my top panel with RegnumRun.sh, instead of with regnum-online directly, and voilà: every time I click on that icon I get to play Regnum with purpose-chosen settings, and I get my regular settings back once I exit Regnum.Tags: about me, cli, Compiz, en, gaming, gnome, howto, interface, linux, regnum online, software
No Comments yet »