2 # /etc/acpi/powerbtn.sh
3 # Taken from Debian's 2.0.4-1 diff file. This version handles KDE4.
4 # Power Button event handler.
5 # Checks to see if gnome or KDE are already handling the power button.
6 # If not, initiates a plain shutdown.
8 # getXuser gets the X user belonging to the display in $displaynum.
9 # If you want the foreground X user, use getXconsole!
11 # displaynum - X display number
13 # XUSER - the name of the user
14 # XAUTHORITY - full pathname of the user's .Xauthority file
16 user
=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
17 if [ x
"$user" = x
"" ]; then
18 startx
=`pgrep -n startx`
19 if [ x
"$startx" != x
"" ]; then
20 user
=`ps -o user --no-headers $startx`
23 if [ x
"$user" != x
"" ]; then
24 userhome
=`getent passwd $user | cut -d: -f6`
25 export XAUTHORITY
=$userhome/.Xauthority
32 # Gets the X display number for the active virtual terminal.
34 # DISPLAY - the X display number
35 # See getXuser()'s output.
38 displaynum
=`ps t tty$console | sed -n -re 's,.*/X .*:([0-9]+).*,\1,p'`
39 if [ x
"$displaynum" != x
"" ]; then
40 export DISPLAY
=":$displaynum"
45 # Skip if we are just in the middle of resuming.
46 test -f /var
/lock
/acpisleep
&& exit 0
48 # If the current X console user is running a power management daemon that
49 # handles suspend/resume requests, let them handle policy.
53 # A list of power management system process names.
54 PMS
="gnome-power-manager kpowersave xfce4-power-manager"
55 PMS
="$PMS guidance-power-manager.py dalston-power-applet"
57 # If one of those is running or any of several others,
58 if pidof x
$PMS > /dev
/null ||
59 ( test "$XUSER" != "" && pidof dcopserver
> /dev
/null
&& test -x /usr
/bin
/dcop
&& /usr
/bin
/dcop
--user $XUSER kded kded loadedModules |
grep -q klaptopdaemon
) ||
60 ( test "$XUSER" != "" && test -x /usr
/bin
/qdbus
&& test -r /proc
/$
(pidof kded4
)/environ
&& su
- $XUSER -c "eval $(echo -n 'export '; cat /proc/$(pidof kded4)/environ |tr '\0' '\n'|grep DBUS_SESSION_BUS_ADDRESS); qdbus org.kde.kded" |
grep -q powerdevil
) ; then
61 # Get out as the power manager that is running will take care of things.
65 # No power managment system appears to be running. Just initiate a plain
67 /sbin
/shutdown
-h now
"Power button pressed"