From cb982e9f860fb34e088b867741deef0281ddb304 Mon Sep 17 00:00:00 2001
From: Heitor Augusto <IAm.HeitorALN@proton.me>
Date: Sat, 30 Nov 2024 19:41:07 -0300
Subject: [PATCH] feat(workspace): add `wallpaperBackground` support for
 `wallpaper`

---
 modules/workspace.nix | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/modules/workspace.nix b/modules/workspace.nix
index 4e37f333..4fa0e4a6 100644
--- a/modules/workspace.nix
+++ b/modules/workspace.nix
@@ -448,17 +448,33 @@ in
 
         desktopScript."wallpaper_picture" = (
           lib.mkIf (cfg.workspace.wallpaper != null) {
-            # We just put this here as we need this script to be a desktop-script in
-            # order to link it together with the other desktop-script (namely
-            # panels). Adding a comment with the wallpaper makes it so that when the
-            # wallpaper changes, the sha256sum also changes for the js file, which
-            # gives us the correct behavior with last_run files.
-            text = "// Wallpaper to set later: ${cfg.workspace.wallpaper}";
-            postCommands = ''
-              plasma-apply-wallpaperimage ${cfg.workspace.wallpaper} ${
-                lib.optionalString (
-                  cfg.workspace.wallpaperFillMode != null
-                ) "--fill-mode ${cfg.workspace.wallpaperFillMode}"
+            text = ''
+              let allDesktops = desktops();
+              for (const desktop of allDesktops) {
+                  desktop.wallpaperPlugin = "org.kde.image";
+                  desktop.currentConfigGroup = ["Wallpaper", "org.kde.image", "General"];
+                  desktop.writeConfig("Image", "file://${cfg.workspace.wallpaper}");
+                  ${
+                    lib.optionalString (cfg.workspace.wallpaperFillMode != null)
+                      ''desktop.writeConfig("FillMode", "${
+                        toString wallpaperFillModeTypes.${cfg.workspace.wallpaperFillMode}
+                      }");''
+                  }
+                  ${
+                    lib.optionalString
+                      (cfg.workspace.wallpaperBackground != null || cfg.workspace.wallpaperBackground != { })
+                      ''desktop.writeConfig("${
+                        if cfg.workspace.wallpaperBackground ? blur && cfg.workspace.wallpaperBackground.blur != null then
+                          "Blur"
+                        else
+                          "Color"
+                      }", "${
+                        if cfg.workspace.wallpaperBackground ? blur && cfg.workspace.wallpaperBackground.blur != null then
+                          lib.boolToString cfg.workspace.wallpaperBackground.blur
+                        else
+                          cfg.workspace.wallpaperBackground.color
+                      }");''
+                  }
               }
             '';
             priority = 3;