diff options
author | Vi0L0 | 2015-11-09 20:45:46 +0100 |
---|---|---|
committer | Vi0L0 | 2015-11-09 20:45:46 +0100 |
commit | 7566f4f49cafe3405a9cc9b04c098938f3b5a94d (patch) | |
tree | c9b8189b138400a75e60510ae62b7cb79d13533c /ati-powermode.sh | |
parent | 52556ab70c9a6830fc91886f8a39dcc3cddf55a8 (diff) | |
download | aur-7566f4f49cafe3405a9cc9b04c098938f3b5a94d.tar.gz |
added 4.2 and 4.3 kernel support
Diffstat (limited to 'ati-powermode.sh')
-rwxr-xr-x | ati-powermode.sh | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/ati-powermode.sh b/ati-powermode.sh new file mode 100755 index 000000000000..ded996c43057 --- /dev/null +++ b/ati-powermode.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# +# Control script for ACPI lid state and AC adapter state +# + +getXuser() { + user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'` + if [ x"$user" = x"" ]; then + startx=`pgrep -n startx` + if [ x"$startx" != x"" ]; then + user=`ps -o user --no-headers $startx` + fi + fi + if [ x"$user" != x"" ]; then + userhome=`getent passwd $user | cut -d: -f6` + export XAUTHORITY=$userhome/.Xauthority + else + export XAUTHORITY="" + fi + export XUSER=$user +} + +#Find the right XServer to be configured. +getXserver() { +for x in /tmp/.X11-unix/*; do + displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` + getXuser; + if [ x"$XAUTHORITY" != x"" ]; then + export DISPLAY=":$displaynum" + fi +done +} + +#If PPLIB is enabled +checkPPLIB() { +su $user -c '/usr/bin/aticonfig --pplib-cmd="get version"' | grep PPLIB +if [ $? = 0 ]; then + echo "Has PPLIB" + has_pplib=1 +else + echo "No PPLIB" + has_pplib=0 +fi +} + +case "$1" in + ac_adapter) + case "$2" in + AC|ACAD|ADP0) + case "$4" in + 00000000) + logger 'AC unpluged' + getXserver; + checkPPLIB; + if [ ${has_pplib} -eq 1 ]; then + su $user -c '/usr/bin/aticonfig --pplib-cmd="notify psrc dc"' + else + su $user -c "/usr/bin/aticonfig --set-powerstate=1 --effective=now" + fi + ;; + 00000001) + logger 'AC pluged' + getXserver; + checkPPLIB; + if [ ${has_pplib} -eq 1 ]; then + su $user -c '/usr/bin/aticonfig --pplib-cmd="notify psrc ac"' + else + su $user -c "/usr/bin/aticonfig --set-powerstate=3 --effective=now" + fi + ;; + esac + ;; + *) + logger "ACPI action undefined: $2" + ;; + esac + ;; + button/lid) + case "$3" in + close) + logger 'LID closed' + getXserver; + checkPPLIB; + if [ ${has_pplib} -eq 1 ]; then + su $user -c '/usr/bin/aticonfig --pplib-cmd="notify psrc dc"' + else + su $user -c "/usr/bin/aticonfig --set-powerstate=1 --effective=now" + fi + ;; + open) + logger 'LID opened' + getXserver; + checkPPLIB; + if [ ${has_pplib} -eq 1 ]; then + su $user -c '/usr/bin/aticonfig --pplib-cmd="notify psrc ac"' + else + su $user -c "/usr/bin/aticonfig --set-powerstate=3 --effective=now" + fi + ;; + *) + logger "ACPI action undefined: $3" + ;; + esac + ;; +esac
\ No newline at end of file |