Suspending Compiz

  • March 8, 2008
  • Avatar for jacob
    Jacob
    Peddicord

There are times when you find a game that for some reason just doesn't work well with Compiz. It may flicker over other windows, become distorted, or it may crash. The real fix for these comes in new X.Org drivers in the works, but for now the best solution is to suspend Compiz while you run a game.

Let's think of a way to do this. First, we'll obviously want to start Metacity and replace Compiz. Then, we want the game to run. And when we're done, Compiz should start up again. The most logical script would be this:

#!/bin/bash
metacity --replace
game_name
compiz --replace

If you try to run the script above, you'd notice that Metacity would start, but nothing else would happen. This is because the commands are run synchronously, that is, when one finishes the next starts. Metacity will never finish unless you stop it. So, let's make it run in the background:

#!/bin/bash
metacity --replace &
game_name
compiz --replace

The ampersand makes Metacity run in the background, allowing other commands to run. We then can run the game. The game shouldn't be run in the background, however, because Compiz would immediately replace Metacity again.

At the end of the script, we start up Compiz again. This is where you don't want to run the script in a terminal for once, because as soon as you close the terminal Compiz will quit. So, let's make a menu item for it. I'm a big fan of StepMania, so I'm going to run the version I have installed in my home directory:

#!/bin/bash
metacity --replace &
cd ~/bin/stepmania
./stepmania
compiz --replace

If you run a command that requires a path, make sure to put the full path name in or your script may not run. We then add a menu entry in the Games menu:

sm-launcher.png

Now whenever I decide to play StepMania, all desktop effects will be shut off. When I am finished, they will be switched back on again. This can be applied to almost any situation where Compiz needs to be off in your own scripts.

Avatar for jacob Jacob Peddicord

Home » Articles »