Friday, 6 July 2007

controlling ATI LCD output when laptop lid is closed

A little while ago, I overwrote my custom acpi scripts by mistake, (I don't keep backups just to keep myself on my toes...) so I spent some time today redoing them.

These are fairly hardware specific, for my Dell Inspiron 9100, so take what you like. If you break it, you get to keep the pieces. Also, I've taken from examples on the web that should be in the public domain.

Firstly, I keep /etc/acpi/events rather empty, with only one file /etc/acpi/events/default:
event=.*
action=/etc/acpi/default.sh %e


Secondly, default.sh (on a lid button event) calls lidaction.sh. Yes I know I could call lidaction.sh directly from /etc/acpi/events/default, but I like to have all my event decisions in one file.

lidaction.sh looks like this:

#
# uses xset to blank / unblank any X displays when lid is closed / opened.
#

getXuser() {
user=`finger| grep -m1 ":$displaynum " | awk '{print $1}'`
if [ x"$user" = x"" ]; then
user=`finger| grep -m1 ":$displaynum" | awk '{print $1}'`
fi
if [ x"$user" != x"" ]; then
userhome=`getent passwd $user | cut -d: -f6`
export XAUTHORITY=$userhome/.Xauthority
else
export XAUTHORITY=""
fi
}

setStates () {
for display in /tmp/.X11-unix/*; do
displaynum=`echo $display | sed s#/tmp/.X11-unix/X##`
# logger "/usr/bin/xset -display :$displaynum dpms force $1"
/usr/bin/xset -display :$displaynum dpms force $1
/usr/sbin/radeontool light $1

getXuser;
if [ x"$XAUTHORITY" != x"" ]; then
export DISPLAY=":$displaynum"
su $user -c "/opt/bin/aticonfig --set-powerstate=$2 --effective=now"
fi

done
}

# this "highlevel" makes us more hardware independant. Thanks to http://bugs.archlinux.org/task/7243.
highlevel=$(aticonfig --lsp | grep ":" | tail -1 | cut -d':' -f 1 | sed -e "s/\*//g" -e "s/ *//g")
[ -z "$highlevel" ] && highlevel=3

grep -q closed /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
lid_closed=1
# echo "Lid Closed"
else
lid_closed=0
# echo "Lid Open"
fi

if [ ${lid_closed} -eq 1 ]; then
logger $0: lid just closed
setStates "off" 1
else
logger $0: lid just opened
setStates "on" $highlevel
fi

That's it! I hope you see something useful. The three important bits are radeontool, xset, and aticonfig.

This has the advantage over gnome-power-manager, because it will work regardless of who is logged in, and even on the console.

No comments:

 
Copyright 2009 Another Blog. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan