summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-20 17:38:43 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-20 17:38:43 +1000
commit2fa954d2a8dea1eef29415dad65edabb8859c02e (patch)
tree46ea9533881e81524934797ce6042a53c19febac
parentfec7c01b250118b32b30377e329292433e88ad26 (diff)
Wallpaper: Add desktop environment support
-rwxr-xr-xwal86
1 files changed, 69 insertions, 17 deletions
diff --git a/wal b/wal
index 98c5309..a183c9b 100755
--- a/wal
+++ b/wal
@@ -305,32 +305,84 @@ def send_sequences(colors, vte):
# WALLPAPER SETTING {{{
+def get_desktop_env():
+ """Identify the current running desktop environment."""
+ desktop = os.getenv("XDG_CURRENT_DESKTOP")
+ if desktop:
+ return desktop
+
+ desktop = os.getenv("DESKTOP_SESSION")
+ if desktop:
+ return desktop
+
+ desktop = os.getenv("GNOME_DESKTOP_SESSION_ID")
+ if desktop:
+ return "GNOME"
+
+ desktop = os.getenv("MATE_DESKTOP_SESSION_ID")
+ if desktop:
+ return "MATE"
+
+
+def set_desktop_wallpaper(desktop, img):
+ """Set the wallpaper for the desktop environment."""
+ if "xfce" in desktop or "xubuntu" in desktop:
+ subprocess.Popen(["xfconf-query", "--channel", "xfce4-desktop",
+ "--property",
+ "/backdrop/screen0/monitor0/image-path",
+ "--set", img])
+
+ # XFCE requires two commands since they differ between versions.
+ subprocess.Popen(["xfconf-query", "--channel", "xfce4-desktop",
+ "--property",
+ "/backdrop/screen0/monitor0/workspace0/last-image",
+ "--set", img])
+
+ elif "muffin" in desktop or "cinnamon" in desktop:
+ subprocess.Popen(["gsettings", "set",
+ "org.cinnamon.desktop.background",
+ "picture-uri", "file:///" + img])
+
+ elif "mate" in desktop:
+ subprocess.Popen(["gsettings", "set", "org.mate.background",
+ "picture-filename", img])
+
+ elif "gnome" in desktop:
+ subprocess.Popen(["gsettings", "set",
+ "org.gnome.desktop.background",
+ "picture-uri", "file:///" + img])
+
+
def set_wallpaper(img):
"""Set the wallpaper."""
- uname = os.uname
+ desktop = str(get_desktop_env()).lower()
- if shutil.which("feh"):
- subprocess.Popen(["feh", "--bg-fill", img])
+ if desktop:
+ set_desktop_wallpaper(desktop, img)
- elif shutil.which("nitrogen"):
- subprocess.Popen(["nitrogen", "--set-zoom-fill", img])
+ else:
+ if os.uname == "Darwin":
+ subprocess.Popen(["osascript", "-e", "\"tell application \"Finder\" to set \
+ desktop picture to POSIX file\"" + img + "\""])
- elif shutil.which("bgs"):
- subprocess.Popen(["bgs", img])
+ elif shutil.which("feh"):
+ subprocess.Popen(["feh", "--bg-fill", img])
- elif shutil.which("hsetroot"):
- subprocess.Popen(["hsetroot", "-fill", img])
+ elif shutil.which("nitrogen"):
+ subprocess.Popen(["nitrogen", "--set-zoom-fill", img])
- elif shutil.which("habak"):
- subprocess.Popen(["habak", "-mS", img])
+ elif shutil.which("bgs"):
+ subprocess.Popen(["bgs", img])
- elif uname == "Darwin":
- subprocess.Popen(["osascript", "-e", "\"tell application \"Finder\" to set \
- desktop picture to POSIX file\"" + img + "\""])
+ elif shutil.which("hsetroot"):
+ subprocess.Popen(["hsetroot", "-fill", img])
- else:
- subprocess.Popen(["gsettings", "set", "org.gnome.desktop.background",
- "picture-uri", img])
+ elif shutil.which("habak"):
+ subprocess.Popen(["habak", "-mS", img])
+
+ else:
+ print("error: No wallpaper setter found.")
+ return
print("wallpaper: Set the new wallpaper")
return 0