From 3f609332e7fecef296123845cc07559e6e355d71 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Sun, 4 Jan 2015 21:28:46 +0000 Subject: [PATCH] Fix use of freedesktop D-Bus service (issue #26805) --- scripts/Makefile.in | 1 + scripts/xdg-screensaver-freedesktop-helper | 16 ++++++ scripts/xdg-screensaver.in | 83 +++++++----------------------- 3 files changed, 37 insertions(+), 63 deletions(-) create mode 100755 scripts/xdg-screensaver-freedesktop-helper diff --git a/scripts/Makefile.in b/scripts/Makefile.in index d167393..7013d74 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -20,6 +20,7 @@ SCRIPTS = \ xdg-open \ xdg-email \ xdg-screensaver \ + xdg-screensaver-freedesktop-helper \ xdg-settings # xdg-su # xdg-copy \ diff --git a/scripts/xdg-screensaver-freedesktop-helper b/scripts/xdg-screensaver-freedesktop-helper new file mode 100755 index 0000000..761cd1d --- /dev/null +++ b/scripts/xdg-screensaver-freedesktop-helper @@ -0,0 +1,16 @@ +#!/usr/bin/perl +# Helper for xdg-screensaver to inhibit desktop idleness using freedesktop.org DBus interface +# N.B. This script sleeps forever, so it must be killed to stop the inhibition + +use strict; +use warnings; + +use Net::DBus; + +my $bus = Net::DBus->session; +my $service = $bus->get_service("org.freedesktop.ScreenSaver"); +my $manager = $service->get_object("/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver"); +$manager->Inhibit("org.freedesktop.xdg-screensaver", "xdg-screensaver suspend"); + +# Keep inhibiting until we're killed +sleep; diff --git a/scripts/xdg-screensaver.in b/scripts/xdg-screensaver.in index 7fcb734..4081a70 100644 --- a/scripts/xdg-screensaver.in +++ b/scripts/xdg-screensaver.in @@ -87,11 +87,16 @@ perform_action() case "$DE" in kde) if [ -n "${KDE_SESSION_VERSION}" ]; then - screensaver_freedesktop "$1" + screensaver_freedesktop "$1" "/ScreenSaver" else screensaver_kde3 "$1" fi ;; + + gnome) + screensaver_freedesktop "$1" "/org/freedesktop/ScreenSaver" + ;; + gnome_screensaver) screensaver_gnome_screensaver "$1" ;; @@ -222,87 +227,39 @@ screensaver_freedesktop() { case "$1" in suspend) - dbus-send --session \ - --dest=org.freedesktop.ScreenSaver \ - --type=method_call \ - --print-reply \ - --reply-timeout=2000 \ - /ScreenSaver \ - org.freedesktop.ScreenSaver.Inhibit \ - string:$window_id \ - string:xdg-screensaver \ - | grep uint32 | cut -d ' ' -f 5 >| "$screensaver_file.cookie" \ - 2> /dev/null + rm -f "$screensaver_file.pid" + xdg-screensaver-freedesktop-helper & + echo $! > "$screensaver_file.pid" result=$? ;; resume) - if [ -f "$screensaver_file.cookie" ] ; then - value=`cat "$screensaver_file.cookie"` - dbus-send --session \ - --dest=org.freedesktop.ScreenSaver \ - --type=method_call \ - /ScreenSaver \ - org.freedesktop.ScreenSaver.UnInhibit \ - uint32:$value \ - 2> /dev/null - rm -f "$screensaver_file.cookie" + if [ -f "$screensaver_file.pid" ] ; then + kill -HUP `cat "$screensaver_file.pid"` + rm -f "$screensaver_file.pid" fi result=$? ;; - activate) - dbus-send --session \ - --dest=org.freedesktop.ScreenSaver \ - --type=method_call \ - /ScreenSaver \ - org.freedesktop.ScreenSaver.SetActive \ - boolean:true \ - 2> /dev/null - result=$? - ;; - - lock) - dbus-send --session \ - --dest=org.freedesktop.ScreenSaver \ - --type=method_call \ - /ScreenSaver \ - org.freedesktop.ScreenSaver.Lock \ - 2> /dev/null + activate|lock) + echo "ERROR: Command '$1' is not implemented in the $DE environment" >&2 ;; reset) - if [ -f "$screensaver_file.cookie" ] ; then + if [ -f "$screensaver_file.pid" ] ; then value=`cat "$screensaver_file.cookie"` - dbus-send --session \ - --dest=org.freedesktop.ScreenSaver \ - --type=method_call \ - /ScreenSaver \ - org.freedesktop.ScreenSaver.UnInhibit \ - uint32:$value \ - 2> /dev/null - rm -f "$screensaver_file.cookie" + kill -HUP `cat "$screensaver_file.pid"` + rm -f "$screensaver_file.pid" fi result=$? ;; status) - status=`dbus-send --session \ - --dest=org.freedesktop.ScreenSaver \ - --type=method_call \ - --print-reply \ - --reply-timeout=2000 \ - /ScreenSaver \ - org.freedesktop.ScreenSaver.GetActive \ - | grep boolean | cut -d ' ' -f 5` - result=$? - if [ x"$status" = "xtrue" ]; then - echo "enabled" - elif [ x"$status" = "xfalse" ]; then + result=0 + if [ -f "$screensaver_file" ] ; then echo "disabled" else - echo "ERROR: dbus org.freedesktop.ScreenSaver.GetActive returned '$status'" >&2 - return 1 + echo "enabled" fi ;; -- 1.9.1