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:
action=/etc/acpi/ %e

Secondly, (on a lid button event) calls Yes I know I could call directly from /etc/acpi/events/default, but I like to have all my event decisions in one file. 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}'`
if [ x"$user" != x"" ]; then
userhome=`getent passwd $user | cut -d: -f6`
export XAUTHORITY=$userhome/.Xauthority
export XAUTHORITY=""

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

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


# this "highlevel" makes us more hardware independant. Thanks to
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
# echo "Lid Closed"
# echo "Lid Open"

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

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