-#!/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
# 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'"):
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")
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:
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):
"""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)
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)
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")