From d696bad7f3f403b1c5bfa2ac91a9c2b62de48618 Mon Sep 17 00:00:00 2001 From: Malte Brandy Date: Sat, 9 May 2020 17:01:10 +0200 Subject: [PATCH] Improve wallpaper change --- home/desktop/wallpaper.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/home/desktop/wallpaper.nix b/home/desktop/wallpaper.nix index d42eb4cb..9e06527f 100644 --- a/home/desktop/wallpaper.nix +++ b/home/desktop/wallpaper.nix @@ -6,12 +6,16 @@ let imports = [ "System.Random" ]; bins = [ pkgs.coreutils pkgs.sway ]; } '' + linkPath = "/home/maralorn/volatile/wallpaper.jpg" main = do mode <- cat "/home/maralorn/tmp/mode" |> captureTrim (lines . decodeUtf8 -> files) <- ls ([i|/home/maralorn/.wallpapers/#{mode}|] :: String) |> captureTrim ((files Unsafe.!!) -> file) <- getStdRandom $ randomR (0, length files - 1) - cp ([i|/home/maralorn/.wallpapers/#{mode}/#{file}|] :: String) "/home/maralorn/volatile/wallpaper.jpg" - swaymsg "output * bg /home/maralorn/volatile/wallpaper.jpg fill" + (decodeUtf8 -> current) <- readlink linkPath |> captureTrim + let new = [i|/home/maralorn/.wallpapers/#{mode}/#{file}|] :: String + when (new /= current) $ do + ln "-s" new linkPath + swaymsg "output * bg /home/maralorn/volatile/wallpaper.jpg fill" ''; in { home.packages = [ randomWallpaper ];