feat: kde fixes, icon, logging

This commit is contained in:
Kat Inskip 2024-02-05 19:28:12 -08:00
parent bfb74c7aca
commit a461bf400f
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
5 changed files with 64 additions and 15 deletions

View file

@ -1,16 +1,55 @@
import subprocess
import dbus
from konawall.module_loader import add_environment
# https://powersnail.com/2023/set-plasma-wallpaper/
SCRIPT_GET_DESKTOPS = """
function getDesktops() {
return desktops()
.filter(d => d.screen != -1)
.sort((a, b) => screenGeometry(a.screen).left - screenGeometry(b.screen).left);
}
"""
SCRIPT_SET_WALLPAPER = """
function setWallpaper(desktop, path) {
desktop.wallpaperPlugin = "org.kde.image"
desktop.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General")
desktop.writeConfig("Image", path)
}
"""
SCRIPT_ALL = f"""
{SCRIPT_GET_DESKTOPS}
{SCRIPT_SET_WALLPAPER}
const imageList = IMAGE_LIST;
getDesktops().forEach((desktop, i) => setWallpaper(desktop, imageList[i % imageList.length]));
"""
SCRIPT_ONE = f"""
{SCRIPT_GET_DESKTOPS}
{SCRIPT_SET_WALLPAPER}
setWallpaper(getDesktops()[DESKTOP_ID], IMAGE);
"""
"""
This sets the wallpaper on KDE.
"""
def quote(s):
return "'" + s + "'"
def plasma_dbus():
bus = dbus.SessionBus()
plasma = dbus.Interface(
bus.get_object("org.kde.plasmashell", "/PlasmaShell"), dbus_interface="org.kde.PlasmaShell"
)
return plasma
@add_environment("kde_setter")
def set_wallpapers(files: list, displays: list):
for file in files:
kde_script = f"""
for (const desktop of desktops()) {{
desktop.currentConfigGroup = ["Wallpaper", "org.kde.image", "General"]
desktop.writeConfig("Image", "{file}")
}}
"""
subprocess.run(["qdbus", "org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell.evaluateScript", kde_script])
image_list_string = "[" + ",".join(quote(p) for p in files) + "]"
script = SCRIPT_ALL.replace("IMAGE_LIST", image_list_string)
plasma_dbus().evaluateScript(script)