From 33b1df8b6ba4eabe5c1d940036fa434daec4df0e Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Fri, 15 Jul 2022 18:30:47 +1000 Subject: [PATCH] small refactor + fixed dbus command path --- wallpaperctl.py | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/wallpaperctl.py b/wallpaperctl.py index 689e45f..1a5ba8a 100755 --- a/wallpaperctl.py +++ b/wallpaperctl.py @@ -18,6 +18,28 @@ def find_all_images(path): return images +def handle_feh(wallpapers): + cmd = "/usr/bin/feh --no-fehbg --bg-fill " + for wallpaper in wallpapers: + cmd += str(f"{wallpaper} ") + subprocess.call(cmd, shell=True) + +def handle_plasma(wallpapers): + fuckingGarbageJS = """ +var allDesktops = desktops(); +""" + for wallpaper in wallpapers: + wallpaperIndex = wallpapers.index(wallpaper) + fuckingGarbageJS += f"""allDesktops[{wallpaperIndex}].wallpaperPlugin = "org.kde.image"; +allDesktops[{wallpaperIndex}].currentConfigGroup = Array("Wallpaper", "org.kde.image", "General"); +allDesktops[{wallpaperIndex}].writeConfig("Image", "file://{wallpaper}"); +""" + cmd = f"/usr/bin/qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '{fuckingGarbageJS}'" + subprocess.call(cmd, shell=True) + +def handle_gnome(wallpapers): + raise NotImplementedError + conf_file = f"{os.environ['HOME']}/.config/wallpaperctl/wallpaperctl.ini" # Initialize config file @@ -61,28 +83,13 @@ for mon in monitors: match WALLPAPER_ENGINE: case 'feh': - cmd = "/usr/bin/feh --no-fehbg --bg-fill " - for wallpaper in wallpapers: - cmd += str(f"{wallpaper} ") - subprocess.call(cmd, shell=True) + handle_feh(wallpapers) + case 'plasma': - # Write code to handle changing wallpapers on plasmashell - fuckingGarbageJS = """ -var allDesktops = desktops(); -""" - for wallpaper in wallpapers: - wallpaperIndex = wallpapers.index(wallpaper) - fuckingGarbageJS += f"""allDesktops[{wallpaperIndex}].wallpaperPlugin = "org.kde.image"; -allDesktops[{wallpaperIndex}].currentConfigGroup = Array("Wallpaper", "org.kde.image", "General"); -allDesktops[{wallpaperIndex}].writeConfig("Image", "file://{wallpaper}"); -""" - cmd = f"qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '{fuckingGarbageJS}'" - subprocess.call(cmd, shell=True) - + handle_plasma(wallpapers) + case 'gnome': - # Write code to handle changing wallpapers on gnomeshell - cmd = "ls" - pass + handle_gnome(wallpapers) case _: print(f"Wallpaper engine {WALLPAPER_ENGINE} is not supported")