Last week I won an award from my college sponsor Končar Electrical Engineering Institute for my graduate work on the topic of creating an advanced web social networking system using open source technologies. I must express my gratitude to the fine people on my college who nominated me and to the Končar Electrical Engineering Institute for rewarding my effort. By the way, this social networking system is work in progress and when ready, I will set it up for testing because I value your feedback for my little projects like Quick Chat.
What did I do with my reward you ask? I bought myself a laptop. My laptop selection priorities were low price and Linux operating system compatibility. I have selected HP Compaq Presario CQ56 with Suse Enterprise Linux11 factory installed. It is really good laptop for the price and very Linux friendly if any of you Linux fans are on a Laptop hunt. I might post a review on this great piece of hardware when I find some available time. Yesterday I've installed Ubuntu Maverick on this laptop and everything works great. But when everything works great, we people usually go to the picky side and start inventing problems. So to create myself some work, I've given myself a task of creating script to turn Compiz off when on battery, and turn it back on when on AC. My goal was extending my shiny new battery life for a few minutes and have fun in the process of creating this script. So here it is...
I'm not gonna get into a details of inner working on this commands, but I will try to explain basic things.
#!/bin/bash export DISPLAY=:0.0 if on_ac_power; then su -p -c 'notify-send -u critical -i "notification-message-IM" "On AC: Desktop compositing" "Turning desktop composition on"' username sleep 1 su -p -c '/usr/bin/compiz --replace &' username else su -p -c 'notify-send -u critical -i "notification-message-IM" "On battery: Desktop compositing" "Turning desktop composition off"' username sleep 1 su -p -c '/usr/bin/metacity --replace &' username fi exit 0
What we need to do now is to put our script in the path for the scripts that are executed every time you plug/unplug you laptop to/from the AC. So lets create this script file and paste contents from the upper code block.
gksudo gedit '/etc/pm/power.d/99_compiz'
Now we paste code from the upper bash code block, replace username with your username and then save our changes. After our script is in place we will mark it as executable using
sudo chmod +x /etc/pm/power.d/99_compiz
One last but very important thing. Like all other system scripts, this script is launched as root and it controls compz by using su to execute commands as you non root user. We can't control another users X application like Compiz even as root users (this is security messure, a good one if you ask me). So we must allow X connections to localhost using command like
xhost +127.0.0.1. If you don't want to enter this manually every time you start your laptop, this command must be placed in your
.bashrc file using following command:
echo "xhost +127.0.0.1 > /dev/null" >> /home/$USER/.bashrc
Now restart your laptop and try pulling a plug on AC adapter from your laptop. If it works great, if not comment here and maybe me or someone else can assist. Wish you all best!