[PATCH xdg-screensaver] Replace dbus-send with mate-screensaver-command in screensaver_mate_screensaver()

Alex Malykh a2m.dev at yandex.ru
Sun Dec 15 10:17:30 PST 2013


Hi, all.

As of commit 2064906430..., screensaver suspend/resume is not working in MATE
desktop (v1.6.1 is used). I have done a little debugging using "dbus-monitor"
and "mate-screensaver-command" and found out that MATE screensaver's D-bus
interface is buggy and inconsistent.

This patch removes "dbus-send"-based stuff from "screensaver_mate_screensaver()"
function and replaces it with calls of "mate-screensaver-command". The latter
inhibits the screensaver well and allows to get rid of iterative "poking" within
"screensaver_suspend_loop()".
--8<-------
Subject: xdg-screensaver: screensaver_mate_screensaver: dbus-send is replaced with mate-screensaver-command
---
 scripts/xdg-screensaver.in | 70 +++++++++++++++++++---------------------------
 1 file changed, 29 insertions(+), 41 deletions(-)

diff --git a/scripts/xdg-screensaver.in b/scripts/xdg-screensaver.in
index b05ab2c..e84330e 100644
--- a/scripts/xdg-screensaver.in
+++ b/scripts/xdg-screensaver.in
@@ -510,34 +510,34 @@ screensaver_gnome_screensaver()
 
 screensaver_mate_screensaver()
 {
-# DBUS interface for mate-screensaver
-# This is same as gnome's for now but may change in the future as MATE
-# does not follow gnome's developement necessarily.
+    local inhibitor_pidfile="$screensaver_file.inhibitor-pid"
     case "$1" in
         suspend)
-        screensaver_suspend_loop \
-        dbus-send --session \
-                  --dest=org.mate.ScreenSaver \
-                  --type=method_call \
-                  /org/mate/ScreenSaver \
-                  org.mate.ScreenSaver.SimulateUserActivity \
-                  2> /dev/null
-        result=$?
+        if [ ! -f "$inhibitor_pidfile" ]; then
+            mate-screensaver-command --inhibit \
+                --application-name="xdg-screensaver" \
+                --reason="outer suspend request to xdg-screensaver" \
+                2> /dev/null &
+            result=$?
+            [ $result -eq 0 ] && echo -n $! > "$inhibitor_pidfile"
+        else
+            result=0
+        fi
         ;;
 
         resume)
-        # Automatic resume when $screensaver_file disappears
-        result=0
+        if [ -s "$inhibitor_pidfile" ]; then
+            ( kill -TERM $(cat "$inhibitor_pidfile") ; \
+              rm -f "$inhibitor_pidfile" ; \
+              mate-screensaver-command --poke ) 2> /dev/null
+            result=$?
+        else
+            result=0
+        fi
         ;;
 
         activate)
-        dbus-send --session \
-                  --dest=org.mate.ScreenSaver \
-                  --type=method_call \
-                  /org/mate/ScreenSaver \
-                  org.mate.ScreenSaver.SetActive \
-                  boolean:true \
-                  2> /dev/null
+        mate-screensaver-command --activate > /dev/null 2> /dev/null
         result=$?
         ;;
 
@@ -548,32 +548,20 @@ screensaver_mate_screensaver()
 
         reset)
         # Turns the screensaver off right now
-        dbus-send --session \
-                  --dest=org.mate.ScreenSaver \
-                  --type=method_call \
-                  /org/mate/ScreenSaver \
-                  org.mate.ScreenSaver.SimulateUserActivity \
-                 2> /dev/null
+        mate-screensaver-command --deactivate > /dev/null 2> /dev/null
         result=$?
         ;;
 
         status)
-        status=`dbus-send --session \
-                          --dest=org.mate.ScreenSaver \
-                          --type=method_call \
-                          --print-reply \
-                          --reply-timeout=2000 \
-                          /org/mate/ScreenSaver \
-                          org.mate.ScreenSaver.GetActive \
-                          | grep boolean | cut -d ' ' -f 5`
-        result=$?
-        if [ x"$status" = "xtrue" -o x"$status" = "xfalse" ]; then
-            echo "enabled"
-        elif [ x"$result" != "x0" ]; then
-            echo "ERROR: dbus org.mate.ScreenSaver.GetActive returned '$status'" >&2
-            return 1
-        else
+        # NOTE: following code relies on text output of `mate-screensaver-command --query`;
+        #       probably might replaced with DBus call to org.mate.ScreenSaver.GetInhibitors
+        result=0
+        if [ -f "$inhibitor_pidfile" ]; then
+            echo "disabled"
+        elif [ $(mate-screensaver-command --query 2> /dev/null | wc -l) -gt 2 ]; then
             echo "disabled"
+        else
+            echo "enabled"
         fi
         ;;
 
-- 
1.8.3.2



More information about the xdg mailing list