#!/bin/bash # # Control script for ACPI lid state and AC adapter state # getXuser() { # AWK is better than grep since it split the line in fields user=$(who| awk "\$2 == \":$displaynum\" {print \$1; exit}") if [ x"$user" != x"" ]; then userhome=$(getent passwd $user | cut -d: -f6) export XAUTHORITY=$userhome/.Xauthority else export XAUTHORITY="" fi } aticonfig='/opt/ati/bin/aticonfig' grep -q closed /proc/acpi/button/lid/*/state if [ $? = 0 ]; then lid_closed=1 else lid_closed=0 fi grep -q off-line /proc/acpi/ac_adapter/*/state if [ $? = 0 ]; then on_dc=1 else on_dc=0 fi # We build a list of all the active displays displays=$(ls /tmp/.X11-unix/* | sed s#/tmp/.X11-unix/X##) if [ ${lid_closed} -eq 1 -o ${on_dc} -eq 1 ]; then logger "ATI: Entering low power mode..." for x in $displays; do getXuser; if [ x"$XAUTHORITY" != x"" ]; then export DISPLAY=":$displaynum" low_voltage_state=$(su $user -c "$aticonfig --lsp | grep 'low voltage' | cut -c 3") su $user -c "$aticonfig --set-powerstate=$low_voltage_state" fi done else echo "ATI: Entering high power mode..." for x in $displays; do getXuser; if [ x"$XAUTHORITY" != x"" ]; then export DISPLAY=":$displaynum" performance_state=$(su $user -c "$aticonfig --lsp | grep 'performance mode' | cut -c 3") su $user -c "$aticonfig --set-powerstate=$performance_state" fi done fi