Proper Gnome3 support
authorJames Bunton <jamesbunton@delx.net.au>
Sun, 13 May 2012 00:04:31 +0000 (10:04 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sun, 13 May 2012 00:04:31 +0000 (10:04 +1000)
wallchanger.py

index 66232e6..8230f48 100755 (executable)
@@ -22,6 +22,9 @@ def set_image(filename):
                if not changer.set_image(filename):
                        logging.warning("Failed to set background: wallchanger.set_image(%s), changer=%s", filename, changer)
 
+def check_cmd(cmd):
+       return commands.getstatusoutput(cmd)[0] == 0
+
 def init(*args, **kwargs):
        """Desktop Changer factory"""
 
@@ -30,7 +33,7 @@ def init(*args, **kwargs):
                return
 
        logging.debug("Testing for OSX (NonX11)")
-       if commands.getstatusoutput("ps ax -o command -c|grep -q WindowServer")[0] == 0:
+       if check_cmd("ps ax -o command -c|grep -q WindowServer"):
                changers.append(OSXChanger(*args, **kwargs))
 
        if 'DISPLAY' not in os.environ or os.environ['DISPLAY'].startswith('/tmp/launch'):
@@ -39,24 +42,23 @@ def init(*args, **kwargs):
        else:
                if os.uname()[0] == 'Darwin':
                        # Try to detect if the X11 server is running on OSX
-                       if commands.getstatusoutput("ps ax -o command|grep -q '^/.*X11 .* %s'" % os.environ['DISPLAY'])[0] != 0:
+                       if check_cmd("ps ax -o command|grep -q '^/.*X11 .* %s'" % os.environ['DISPLAY']):
                                # X11 is not running for this display
                                return
 
        logging.debug("Testing for KDE")
-       if commands.getstatusoutput("xwininfo -name 'KDE Desktop'")[0] == 0:
+       if check_cmd("xwininfo -name 'KDE Desktop'"):
                changers.append(KDEChanger(*args, **kwargs))
 
-       logging.debug("Testing for Unity")
-       if commands.getstatusoutput("xlsclients | grep -qi unity")[0] == 0:
-               changers.append(UnityChanger(*args, **kwargs))
-
        logging.debug("Testing for Gnome")
-       if commands.getstatusoutput("xwininfo -name 'gnome-settings-daemon'")[0] == 0:
-               changers.append(GnomeChanger(*args, **kwargs))
+       if check_cmd("xwininfo -name 'gnome-settings-daemon'"):
+               if check_cmd("gsettings get org.gnome.desktop.background picture-uri"):
+                       changers.append(Gnome3Changer(*args, **kwargs))
+               else:
+                       changers.append(Gnome2Changer(*args, **kwargs))
 
        logging.debug("Testing for WMaker")
-       if commands.getstatusoutput("xlsclients | grep -qi wmaker")[0] == 0:
+       if check_cmd("xlsclients | grep -qi wmaker"):
                changers.append(WMakerChanger(*args, **kwargs))
        
        if len(changers) == 0:
@@ -246,15 +248,15 @@ class WIN32Changer(BaseChanger):
                )
                return True
 
-class GnomeChanger(BaseChanger):
+class Gnome2Changer(BaseChanger):
        name = "Gnome"
        def set_image(self, filename):
                cmd = ['gconftool-2', '--type', 'string', '--set', '/desktop/gnome/background/picture_filename', filename]
                logging.debug(cmd)
                return not self._exec_cmd(cmd)
 
-class UnityChanger(BaseChanger):
-       name = "Unity"
+class Gnome3Changer(BaseChanger):
+       name = "Gnome3"
        def set_image(self, filename):
                cmd = ['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://'+filename]
                logging.debug(cmd)