Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 140554 | Differences between
and this patch

Collapse All | Expand All

(-)ati-powermode.sh (-39 / +74 lines)
Lines 1-68 Link Here
1
#!/bin/bash 
1
#!/bin/bash
2
2
# Released under the GPLv2 or greater.
3
#
3
# 
4
# Control script for ACPI lid state and AC adapter state
4
# Script to adjust power mode of ati graphic chips
5
#
5
#
6
# This was originally taken from the suse package of ATI's binary package 
7
# and modified by Ryan Neufeld June 2006.
8
# Changlog:
9
# June 7 2006
10
# -------------------------------------
11
# - update to use 'who' rather than 'finger' as it requires some users to install an extra package.
12
# - remove un-needed function references.
13
# - fixed location of aticonfig script.
14
# - added variables for LOWPOWER and HIGHPOWER
15
# - fixed formatting, changed all spaces to tabs
16
# - add support for radeontool
17
# - add support for XGL
18
# - piped aticonfig stderr to /dev/null
19
#------ Script start ------
20
21
ATICONFIG="/opt/ati/bin/aticonfig"
22
23
# Valid settings are, from lowest to highest speeds, 1, 2, 3. 
24
# This is dependent on your video card, use "aticonfig --lsp" to find out which settings your card supports
25
LOWPOWER=2
26
HIGHPOWER=3
27
28
# If USE_RADEONTOOL is set to 1 then "radeontool light off" will be executed 
29
# which should on mobility chipsets turn off the backlight
30
USE_RADEONTOOL=1
31
RADEONTOOL="/usr/sbin/radeontool"
32
33
34
echo "Executing ati-powermode.sh"
6
35
7
getXuser() {
36
getXuser() {
8
        user=`who| grep -m1 ":$displaynum " | awk '{print $1}'`
37
	user=`who | grep -m1 ":$displaynum " | awk '{print $1}'`
9
        if [ x"$user" = x"" ]; then
38
	if [ x"$user" = x"" ]; then
10
                user=`who| grep -m1 ":$displaynum" | awk '{print $1}'`
39
		user=`who | grep -m1 ":$displaynum" | awk '{print $1}'`
11
        fi
40
	fi
12
        if [ x"$user" != x"" ]; then
41
	if [ x"$user" != x"" ]; then
13
                userhome=`getent passwd $user | cut -d: -f6`
42
		userhome=`getent passwd $user | cut -d: -f6`
14
                export XAUTHORITY=$userhome/.Xauthority
43
		export XAUTHORITY=$userhome/.Xauthority
15
        else
44
	else
16
                export XAUTHORITY=""
45
		export XAUTHORITY=""
17
        fi
46
	fi
18
}
47
}
19
48
20
49
21
grep -q closed /proc/acpi/button/lid/*/state
50
grep -q closed /proc/acpi/button/lid/*/state
22
if [ $? = 0 ]; then
51
if [ $? = 0 ]; then
23
 lid_closed=1
52
	lid_closed=1
24
 echo "Lid Closed"
53
	echo "Lid Closed"
54
	if [ $USE_RADEONTOOL -eq 1 ]; then
55
		$RADEONTOOL light off
56
	fi
25
else
57
else
26
 lid_closed=0
58
	lid_closed=0
27
 echo "Lid Open"
59
	echo "Lid Open"
60
	if [ $USE_RADEONTOOL -eq 1 ]; then
61
		$RADEONTOOL light on
62
	fi
28
fi
63
fi
29
64
30
grep -q off-line /proc/acpi/ac_adapter/*/state 
65
grep -q off-line /proc/acpi/ac_adapter/*/state 
31
32
if [ $? = 0 ]; then
66
if [ $? = 0 ]; then
33
   echo "On DC"
67
	echo "On DC"
34
   on_dc=1
68
	on_dc=1
35
else
69
else
36
   echo "On AC"
70
	echo "On AC"
37
   on_dc=0
71
	on_dc=0
38
fi
72
fi
39
73
40
74
41
75
42
if [ ${lid_closed} -eq 1 -o ${on_dc} -eq 1 ]; then
76
if [ ${lid_closed} -eq 1 -o ${on_dc} -eq 1 ]; then
43
    echo "Low power"
77
	echo "Low power"
44
    for x in /tmp/.X11-unix/*; do
78
	for x in /tmp/.X11-unix/*; do
45
	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
79
		displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
46
	getXuser;
80
		getXuser;
47
	if [ x"$XAUTHORITY" != x"" ]; then
81
		if [ x"$XAUTHORITY" != x"" ]; then
48
		if [ $(pgrep -x Xgl) != "" ]; then
82
			if [ $(pgrep -x Xgl ) != "" ]; then
49
                        displaynum=$(( $displaynum + 93 ));
83
				displaynum=$(( $displaynum + 93 ));
50
                fi
84
			fi
51
	    export DISPLAY=":$displaynum"	    
85
			export DISPLAY=":$displaynum"
52
	    su $user -c "/opt/ati/bin/aticonfig --set-powerstate=1 --effective=now"
86
			su $user -c "$ATICONFIG --set-powerstate=$LOWPOWER --effective=now 2> /dev/null"
53
	fi
87
		fi
54
    done
88
	done
55
else
89
else
56
    echo "high power"
90
    echo "High power"
57
    for x in /tmp/.X11-unix/*; do
91
    for x in /tmp/.X11-unix/*; do
58
	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
92
	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
59
	getXuser;
93
	getXuser;
60
	if [ x"$XAUTHORITY" != x"" ]; then
94
	if [ x"$XAUTHORITY" != x"" ]; then
61
		if [ $(pgrep -x Xgl) != "" ]; then
95
		if [ $(pgrep -x Xgl) != "" ]; then
62
                        displaynum=$(( $displaynum + 93 ));
96
			displaynum=$(( $displaynum + 93 ));
63
                fi
97
		fi
64
	    export DISPLAY=":$displaynum"
98
	    export DISPLAY=":$displaynum"
65
	    su $user -c "/opt/ati/bin/aticonfig --set-powerstate=3 --effective=now"
99
	    su $user -c "$ATICONFIG --set-powerstate=$HIGHPOWER --effective=now 2> /dev/null"
66
	fi
100
	fi
67
    done
101
    done
68
fi
102
fi
103

Return to bug 140554