Replace KDE/WindowMaker with XFCE4/xloadimage
authorJames Bunton <jamesbunton@delx.net.au>
Tue, 11 Nov 2014 08:46:23 +0000 (19:46 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Tue, 11 Nov 2014 08:46:23 +0000 (19:46 +1100)
wallchanger.py

index caf7ddb..2bbd6f9 100755 (executable)
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
+
 # Copyright 2008 Greg Darke <greg@tsukasa.net.au>
 # Copyright 2008 James Bunton <jamesbunton@fastmail.fm>
 # Licensed for distribution under the GPL version 2, check COPYING for details
@@ -48,9 +49,9 @@ def init(*args, **kwargs):
                                # X11 is not running for this display
                                return
 
-       logging.debug("Testing for KDE")
-       if check_cmd("xwininfo -name 'KDE Desktop'"):
-               classes.append(KDEChanger)
+       logging.debug("Testing for XFCE4")
+       if check_cmd("xwininfo -name 'xfce4-session'"):
+               classes.append(Xfce4Changer)
 
        logging.debug("Testing for Gnome")
        if check_cmd("xwininfo -name 'gnome-settings-daemon'"):
@@ -59,10 +60,10 @@ def init(*args, **kwargs):
                else:
                        classes.append(Gnome2Changer)
 
-       logging.debug("Testing for WMaker")
-       if check_cmd("xlsclients | grep -qi wmaker"):
-               classes.append(WMakerChanger)
-       
+       logging.debug("Testing for xloadimage")
+       if check_cmd("which xloadimage"):
+               classes.append(XLoadImageChanger)
+
        if len(classes) == 0:
                raise Exception("Unknown window manager")
 
@@ -72,10 +73,9 @@ def init(*args, **kwargs):
 
 class BaseChanger(object):
        name = "undefined"
-       def __init__(self, background_color='black', permanent=False, convert=False):
+       def __init__(self, background_color='black', convert=False):
                logging.info('Determined the window manager is "%s"', self.name)
                self.background_color = background_color
-               self.permanent = permanent
                self.convert = convert
 
        try:
@@ -113,9 +113,9 @@ class BaseChanger(object):
                return output_name, True
 
 
-class WMakerChanger(BaseChanger):
-       name = "WindowMaker"
-       _ConvertedWallpaperLocation = '/tmp/wallpapers_wmaker/'
+class XLoadImageChanger(BaseChanger):
+       name = "xloadimage"
+       _ConvertedWallpaperLocation = '/tmp/wallpapers_xloadimage/'
        def remove_old_image_cache(self):
                """Cleans up any old temp images"""
                if not os.path.isdir(self._ConvertedWallpaperLocation):
@@ -130,7 +130,7 @@ class WMakerChanger(BaseChanger):
                """Convert the image to a png, and store it in a local place"""
                self.remove_old_image_cache()
                output_name = os.path.join(self._ConvertedWallpaperLocation, '%s.png' % time.time())
-               cmd = ["convert", '-resize', '1280', '-gravity', 'Center', '-crop', '1280x800+0+0', filename, output_name]
+               cmd = ["convert", filename, output_name]
                logging.debug("""Convert command: '"%s"'""", '" "'.join(cmd))
                return output_name, self._exec_cmd(cmd)
 
@@ -139,17 +139,13 @@ class WMakerChanger(BaseChanger):
                        filename, convert_status = self.convert_image_format(filename)
                        if convert_status:
                                logging.debug('Convert failed')
-               cmd = ["wmsetbg", 
-                       "-b", self.background_color, # Sets the background colour to be what the user specified
-                       "-S", # 'Smooth' (WTF?)
-                       "-e", # Center the image on the screen (only affects when the image in no the in the correct aspect ratio
-###                    "-a", # scale the image, keeping the aspect ratio
-                       "-u", # Force this to be the default background
-                       "-d"  # dither
-                       ]
-               if self.permanent:
-                       cmd += ["-u"] # update the wmaker database
-               cmd += [filename]
+               cmd = [
+                       "xloadimage",
+                       "-onroot",
+                       "-fullscreen",
+                       "-border", "black",
+                       filename,
+               ]
                logging.debug('''WMaker bgset command: "'%s'"''', "' '".join(cmd))
                return not self._exec_cmd(cmd)
 
@@ -267,25 +263,17 @@ class Gnome3Changer(BaseChanger):
                logging.debug(cmd)
                return not self._exec_cmd(cmd)
 
-class KDEChanger(BaseChanger):
-       name = "KDE"
+class Xfce4Changer(BaseChanger):
+       name = "XFCE4"
        def set_image(self, filename):
-               cmds = []
-               for group in ('Desktop0', 'Desktop0Screen0'):
-                       base = ['kwriteconfig', '--file', 'kdesktoprc', '--group', group, '--key']
-                       cmds.append(base + ['Wallpaper', filename])
-                       cmds.append(base + ['UseSHM', '--type', 'bool', 'true'])
-                       cmds.append(base + ['WallpaperMode', 'ScaleAndCrop'])
-                       cmds.append(base + ['MultiWallpaperMode', 'NoMulti'])
-
-               cmds.append(['dcop', 'kdesktop', 'KBackgroundIface', 'configure'])
-               for cmd in cmds:
-                       logging.debug(cmd)
-                       if self._exec_cmd(cmd) != 0:
-                               return False
-
-               return True
-
+               cmd = [
+                       "xfconf-query",
+                       "-c", "xfce4-desktop",
+                       "-p", "/backdrop/screen0/monitor0/image-path",
+                       "-s", filename,
+               ]
+               logging.debug(cmd)
+               return not self._exec_cmd(cmd)
 
 def main(filename):
        logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")