summaryrefslogtreecommitdiff
path: root/pywal/wallpaper.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-26 12:09:35 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-26 12:09:35 +1000
commit583a0c19ad2f67a54130a219eeeaccf53ea08ded (patch)
treea72b51a6cf219c46c55f8fe9033814c48d23d48b /pywal/wallpaper.py
parentd17282cdc01a41cc70e0919ace55715eac3dd6d1 (diff)
General: Split wal into multiple files.
Diffstat (limited to 'pywal/wallpaper.py')
-rw-r--r--pywal/wallpaper.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py
new file mode 100644
index 0000000..39c44bf
--- /dev/null
+++ b/pywal/wallpaper.py
@@ -0,0 +1,84 @@
+"""Set the wallpaper."""
+import os
+import shutil
+import subprocess
+
+
+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 xfconf(path, img):
+ """Call xfconf to set the wallpaper on XFCE."""
+ disown("xfconf-query", "--channel", "xfce4-desktop",
+ "--property", path, "--set", img)
+
+
+def set_desktop_wallpaper(desktop, img):
+ """Set the wallpaper for the desktop environment."""
+ desktop = str(desktop).lower()
+
+ if "xfce" in desktop or "xubuntu" in desktop:
+ # XFCE requires two commands since they differ between versions.
+ xfconf("/backdrop/screen0/monitor0/image-path", img)
+ xfconf("/backdrop/screen0/monitor0/workspace0/last-image", img)
+
+ elif "muffin" in desktop or "cinnamon" in desktop:
+ subprocess.Popen(["gsettings", "set",
+ "org.cinnamon.desktop.background",
+ "picture-uri", "file:///" + img])
+
+ elif "gnome" in desktop:
+ subprocess.Popen(["gsettings", "set",
+ "org.gnome.desktop.background",
+ "picture-uri", "file:///" + img])
+
+ elif "mate" in desktop:
+ subprocess.Popen(["gsettings", "set", "org.mate.background",
+ "picture-filename", img])
+
+
+def set_wallpaper(img):
+ """Set the wallpaper."""
+ desktop = get_desktop_env()
+
+ if desktop:
+ set_desktop_wallpaper(desktop, img)
+
+ else:
+ if shutil.which("feh"):
+ subprocess.Popen(["feh", "--bg-fill", img])
+
+ elif shutil.which("nitrogen"):
+ subprocess.Popen(["nitrogen", "--set-zoom-fill", img])
+
+ elif shutil.which("bgs"):
+ subprocess.Popen(["bgs", img])
+
+ elif shutil.which("hsetroot"):
+ subprocess.Popen(["hsetroot", "-fill", 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