Comment 21 for bug 197209

The actual bug is an interaction with chvt, which is the first thing pm-utils does. One has to get in before chvt and invoke metacity. One way to do that is something like this file, which would go in /etc/pm/config.d/00-compiz-stop

# override the real chvt to stop compiz before doing anything
chvt() {
    # invoke metacity as user "dave"
    sudo -b -H -u dave XAUTHORITY=/home/dave/.Xauthority DISPLAY=:0 metacity --replace gconf

    # wait until compiz.real actually dies
    while pgrep compiz.real; do sleep 0.1; done

    # forget this function definition
    unset -f chvt

    # call the real chvt
    chvt "$1"

The above is a proof-of-concept hack. Tomorrow I should have a "real" version that also properly restores compiz on all the screens where it has been killed.