[PATCH] xdg-screensaver: fix inhibition for freedesktop(BR102124)

David Kis cf.paintech at gmail.com
Thu Sep 27 22:08:49 UTC 2018


According to the spec the dbus-send approach is not working for inhibition.
This will change that to a perl solution similiar to the gnome case.
Also fix `reset` to call `SimulateUserActivity`
---
I have yet to grok the codebase, but this fix my issues under KDE.

 scripts/xdg-screensaver.in | 73 ++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 35 deletions(-)

diff --git a/scripts/xdg-screensaver.in b/scripts/xdg-screensaver.in
index 9e68196..6ba6c26 100644
--- a/scripts/xdg-screensaver.in
+++ b/scripts/xdg-screensaver.in
@@ -236,33 +236,41 @@ 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
-        result=$?
+        perl -e '
+use strict;
+use warnings;
+use IO::File;
+use Net::DBus;
+
+my ($window_id, $screensaver_file) = @ARGV;
+
+my $bus = Net::DBus->session();
+my $ss_svc = $bus->get_service("org.freedesktop.ScreenSaver");
+my $ss = $ss_svc->get_object("/org/freedesktop/ScreenSaver",
+           "org.freedesktop.ScreenSaver");
+$ss->Inhibit($window_id, "xdg-screensaver");
+
+# Wait until removed from the status file.
+while (1) {
+  sleep(10);
+  my $status = new IO::File($screensaver_file, "r")
+    or exit 0;
+  my $found;
+  while (<$status>) {
+    if (/^$window_id:/) {
+      $found = 1;
+      last;
+    }
+  }
+  exit 0 unless $found;
+}
+' $window_id $screensaver_file &
+        result=0
         ;;
 
         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"
-        fi
-        result=$?
+        # Automatic resume when $screensaver_file disappears
+        result=0
         ;;
 
         activate)
@@ -286,17 +294,12 @@ screensaver_freedesktop()
         ;;
 
         reset)
-        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"
-        fi
+        dbus-send --session \
+                  --dest=org.freedesktop.ScreenSaver \
+                  --type=method_call \
+                  /ScreenSaver \
+                  org.freedesktop.ScreenSaver.SimulateUserActivity \
+                 2> /dev/null
         result=$?
         ;;
 
-- 
2.19.0



More information about the xdg mailing list