--- ati-powermode.sh 2006-07-15 13:24:53.000000000 -0700 +++ /etc/acpi/ati-powermode.sh 2006-07-15 13:21:32.000000000 -0700 @@ -1,68 +1,103 @@ -#!/bin/bash - -# -# Control script for ACPI lid state and AC adapter state +#!/bin/bash +# Released under the GPLv2 or greater. +# +# Script to adjust power mode of ati graphic chips # +# This was originally taken from the suse package of ATI's binary package +# and modified by Ryan Neufeld June 2006. +# Changlog: +# June 7 2006 +# ------------------------------------- +# - update to use 'who' rather than 'finger' as it requires some users to install an extra package. +# - remove un-needed function references. +# - fixed location of aticonfig script. +# - added variables for LOWPOWER and HIGHPOWER +# - fixed formatting, changed all spaces to tabs +# - add support for radeontool +# - add support for XGL +# - piped aticonfig stderr to /dev/null +#------ Script start ------ + +ATICONFIG="/opt/ati/bin/aticonfig" + +# Valid settings are, from lowest to highest speeds, 1, 2, 3. +# This is dependent on your video card, use "aticonfig --lsp" to find out which settings your card supports +LOWPOWER=2 +HIGHPOWER=3 + +# If USE_RADEONTOOL is set to 1 then "radeontool light off" will be executed +# which should on mobility chipsets turn off the backlight +USE_RADEONTOOL=1 +RADEONTOOL="/usr/sbin/radeontool" + + +echo "Executing ati-powermode.sh" getXuser() { - user=`who| grep -m1 ":$displaynum " | awk '{print $1}'` - if [ x"$user" = x"" ]; then - user=`who| 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 + user=`who | grep -m1 ":$displaynum " | awk '{print $1}'` + if [ x"$user" = x"" ]; then + user=`who | 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 } grep -q closed /proc/acpi/button/lid/*/state if [ $? = 0 ]; then - lid_closed=1 - echo "Lid Closed" + lid_closed=1 + echo "Lid Closed" + if [ $USE_RADEONTOOL -eq 1 ]; then + $RADEONTOOL light off + fi else - lid_closed=0 - echo "Lid Open" + lid_closed=0 + echo "Lid Open" + if [ $USE_RADEONTOOL -eq 1 ]; then + $RADEONTOOL light on + fi fi grep -q off-line /proc/acpi/ac_adapter/*/state - if [ $? = 0 ]; then - echo "On DC" - on_dc=1 + echo "On DC" + on_dc=1 else - echo "On AC" - on_dc=0 + echo "On AC" + on_dc=0 fi if [ ${lid_closed} -eq 1 -o ${on_dc} -eq 1 ]; then - echo "Low power" - for x in /tmp/.X11-unix/*; do - displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` - getXuser; - if [ x"$XAUTHORITY" != x"" ]; then - if [ $(pgrep -x Xgl) != "" ]; then - displaynum=$(( $displaynum + 93 )); - fi - export DISPLAY=":$displaynum" - su $user -c "/opt/ati/bin/aticonfig --set-powerstate=1 --effective=now" - fi - done + echo "Low power" + for x in /tmp/.X11-unix/*; do + displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` + getXuser; + if [ x"$XAUTHORITY" != x"" ]; then + if [ $(pgrep -x Xgl ) != "" ]; then + displaynum=$(( $displaynum + 93 )); + fi + export DISPLAY=":$displaynum" + su $user -c "$ATICONFIG --set-powerstate=$LOWPOWER --effective=now 2> /dev/null" + fi + done else - echo "high power" + echo "High power" for x in /tmp/.X11-unix/*; do displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` getXuser; if [ x"$XAUTHORITY" != x"" ]; then if [ $(pgrep -x Xgl) != "" ]; then - displaynum=$(( $displaynum + 93 )); - fi + displaynum=$(( $displaynum + 93 )); + fi export DISPLAY=":$displaynum" - su $user -c "/opt/ati/bin/aticonfig --set-powerstate=3 --effective=now" + su $user -c "$ATICONFIG --set-powerstate=$HIGHPOWER --effective=now 2> /dev/null" fi done fi +