diff --git a/quickshell/services/WallpaperService.qml b/quickshell/services/WallpaperService.qml index 0cda4a4..09605a0 100644 --- a/quickshell/services/WallpaperService.qml +++ b/quickshell/services/WallpaperService.qml @@ -17,6 +17,27 @@ Item { running: true } + // Read saved user wallpaper on startup + Process { + id: readWallpaperProc + command: ["python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/read_wallpaper.py"] + running: true + stdout: SplitParser { + onRead: data => { + try { + let parsed = JSON.parse(data.trim()) + if (parsed && parsed.wallpaper && parsed.wallpaper !== "") { + root.activeCustomWallpaper = parsed.wallpaper + let fileUrl = parsed.wallpaper.startsWith("file://") ? parsed.wallpaper : "file://" + parsed.wallpaper + Theme.wallpaperPath = fileUrl + let rawPath = parsed.wallpaper.replace("file://", "") + Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath]) + } + } catch (e) {} + } + } + } + // Auto-scan wallpapers in ~/Pictures/Wallpapers and ~/.config/quickshell/wallpapers Process { id: scanProc @@ -43,6 +64,7 @@ Item { } Component.onCompleted: { + readWallpaperProc.running = true scanProc.running = true } @@ -53,6 +75,7 @@ Item { Theme.wallpaperPath = fileUrl let rawPath = filePath.replace("file://", "") Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath]) + Quickshell.execDetached(["python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/save_wallpaper.py", rawPath]) } function refresh() { diff --git a/quickshell/services/python/read_wallpaper.py b/quickshell/services/python/read_wallpaper.py new file mode 100755 index 0000000..49a72de --- /dev/null +++ b/quickshell/services/python/read_wallpaper.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import json +import os + +def read_wallpaper(): + user_file = os.path.expanduser('~/.config/quickshell_user_wallpaper.json') + if os.path.exists(user_file): + try: + with open(user_file, 'r', encoding='utf-8') as f: + data = json.load(f) + if isinstance(data, dict) and data.get("wallpaper"): + print(json.dumps(data), flush=True) + return + except Exception: + pass + print(json.dumps({"wallpaper": ""}), flush=True) + +if __name__ == '__main__': + read_wallpaper() diff --git a/quickshell/services/python/save_wallpaper.py b/quickshell/services/python/save_wallpaper.py new file mode 100755 index 0000000..6581917 --- /dev/null +++ b/quickshell/services/python/save_wallpaper.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import json +import os +import sys + +def save_wallpaper(): + if len(sys.argv) < 2: + return + wp_path = sys.argv[1] + user_file = os.path.expanduser('~/.config/quickshell_user_wallpaper.json') + data = {"wallpaper": wp_path} + try: + with open(user_file, 'w', encoding='utf-8') as f: + json.dump(data, f, indent=2) + except Exception: + pass + +if __name__ == '__main__': + save_wallpaper() diff --git a/quickshell/theme/Theme.qml b/quickshell/theme/Theme.qml index 62fa928..d6baf9d 100644 --- a/quickshell/theme/Theme.qml +++ b/quickshell/theme/Theme.qml @@ -165,9 +165,13 @@ Item { AppLauncherService.reload() let imgPath = getVariantWallpaper(v.name) - wallpaperPath = imgPath.startsWith("file://") ? imgPath : "file://" + imgPath - let rawPath = imgPath.replace("file://", "") - Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath]) + if (WallpaperService) { + WallpaperService.applyWallpaper(imgPath) + } else { + wallpaperPath = imgPath.startsWith("file://") ? imgPath : "file://" + imgPath + let rawPath = imgPath.replace("file://", "") + Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath]) + } Quickshell.execDetached(["sh", "-c", "wallust run '" + rawPath + "' || ~/.cargo/bin/wallust run '" + rawPath + "' 2>/dev/null || true"]) // Persist selected theme variant to disk