small refactor + fixed dbus command path

This commit is contained in:
Benjamyn Love 2022-07-15 18:30:47 +10:00
parent e4d8bccdab
commit 33b1df8b6b

View File

@ -18,6 +18,28 @@ def find_all_images(path):
return images 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" conf_file = f"{os.environ['HOME']}/.config/wallpaperctl/wallpaperctl.ini"
# Initialize config file # Initialize config file
@ -61,28 +83,13 @@ for mon in monitors:
match WALLPAPER_ENGINE: match WALLPAPER_ENGINE:
case 'feh': case 'feh':
cmd = "/usr/bin/feh --no-fehbg --bg-fill " handle_feh(wallpapers)
for wallpaper in wallpapers:
cmd += str(f"{wallpaper} ")
subprocess.call(cmd, shell=True)
case 'plasma': case 'plasma':
# Write code to handle changing wallpapers on plasmashell 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"qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '{fuckingGarbageJS}'"
subprocess.call(cmd, shell=True)
case 'gnome': case 'gnome':
# Write code to handle changing wallpapers on gnomeshell handle_gnome(wallpapers)
cmd = "ls"
pass
case _: case _:
print(f"Wallpaper engine {WALLPAPER_ENGINE} is not supported") print(f"Wallpaper engine {WALLPAPER_ENGINE} is not supported")