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