mirror of
https://github.com/dylanaraps/pywal.git
synced 2024-11-29 11:24:03 +01:00
Wallpaper: Add desktop environment support
This commit is contained in:
parent
fec7c01b25
commit
2fa954d2a8
94
wal
94
wal
@ -305,32 +305,84 @@ def send_sequences(colors, vte):
|
|||||||
# WALLPAPER SETTING {{{
|
# 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):
|
def set_wallpaper(img):
|
||||||
"""Set the wallpaper."""
|
"""Set the wallpaper."""
|
||||||
uname = os.uname
|
desktop = str(get_desktop_env()).lower()
|
||||||
|
|
||||||
if shutil.which("feh"):
|
if desktop:
|
||||||
subprocess.Popen(["feh", "--bg-fill", img])
|
set_desktop_wallpaper(desktop, 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])
|
|
||||||
|
|
||||||
elif uname == "Darwin":
|
|
||||||
subprocess.Popen(["osascript", "-e", "\"tell application \"Finder\" to set \
|
|
||||||
desktop picture to POSIX file\"" + img + "\""])
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
subprocess.Popen(["gsettings", "set", "org.gnome.desktop.background",
|
if os.uname == "Darwin":
|
||||||
"picture-uri", img])
|
subprocess.Popen(["osascript", "-e", "\"tell application \"Finder\" to set \
|
||||||
|
desktop picture to POSIX file\"" + img + "\""])
|
||||||
|
|
||||||
|
elif 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")
|
print("wallpaper: Set the new wallpaper")
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user