- Catch and process sleep event correctly, even if no X is
running. OBS-URL: https://build.opensuse.org/package/show/Base:System/acpid?expand=0&rev=56
This commit is contained in:
42
sleep_button
Normal file
42
sleep_button
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Sleep button suspend script, adapted from
|
||||
# /usr/lib/acpid/power_button
|
||||
#
|
||||
# Copyright (C) 2008 Holger Macht <hmacht@suse.de>
|
||||
#
|
||||
# This file is released under the GPLv2.
|
||||
#
|
||||
|
||||
EXEC=/usr/sbin/pm-suspend
|
||||
|
||||
# iterate over all sessions. If a active X session is found, do nothing
|
||||
while read A; do
|
||||
SESSION=`echo $A | sed 's/\(Session[0-9]*\)://g'`
|
||||
[ -z "$SESSION" ] || continue
|
||||
|
||||
SESSION=`echo $A | sed 's/\(Session[0-9]*\):/\1/g'`
|
||||
IS_X=`dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit \
|
||||
/org/freedesktop/ConsoleKit/$SESSION \
|
||||
org.freedesktop.ConsoleKit.Session.GetX11Display`
|
||||
|
||||
# check if this is a X session, if not, go on
|
||||
DISP=`echo $IS_X | sed -e 's/^.* string "\(.*\)"/\1/'`
|
||||
[ -n "$DISP" ] || continue
|
||||
|
||||
IS_ACTIVE=`dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit \
|
||||
/org/freedesktop/ConsoleKit/$SESSION \
|
||||
org.freedesktop.ConsoleKit.Session.IsActive`
|
||||
IS_ACTIVE=`echo $IS_ACTIVE | sed -e 's/^.* boolean \(.*\)$/\1/'`
|
||||
|
||||
if [ "$IS_ACTIVE" = "true" -a -n "$DISP" ]; then
|
||||
# additional check, if none of these two apps are running, go on
|
||||
if [ -n "`pidof kpowersave`" -o -n "`pidof gnome-power-manager`" -o -n "`pidof kded4`" ]; then
|
||||
echo doing nothing...
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
done < <(ck-list-sessions)
|
||||
|
||||
logger -s "Sleep Button event received, running $EXEC."
|
||||
$EXEC
|
Reference in New Issue
Block a user