From fdd4b61a4341790d1839fe6abd43102c88aef5c9 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Sun, 21 Jul 2024 22:10:28 -0400 Subject: [PATCH] home/sway: better random wallpaper handling --- homeManagerModules/desktop/sway/default.nix | 2 - .../desktop/sway/randomWallpaper.nix | 49 ------------------- homeManagerModules/desktop/sway/scripts.nix | 32 ++++++++++++ homeManagerModules/desktop/sway/settings.nix | 3 +- 4 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 homeManagerModules/desktop/sway/randomWallpaper.nix diff --git a/homeManagerModules/desktop/sway/default.nix b/homeManagerModules/desktop/sway/default.nix index 68661e4e..99297b81 100644 --- a/homeManagerModules/desktop/sway/default.nix +++ b/homeManagerModules/desktop/sway/default.nix @@ -4,8 +4,6 @@ pkgs, ... }: { - imports = [./randomWallpaper.nix]; - config = lib.mkIf config.ar.home.desktop.sway.enable { ar.home.theme.gtk.hideTitleBar = if config.wayland.windowManager.sway.package == pkgs.sway diff --git a/homeManagerModules/desktop/sway/randomWallpaper.nix b/homeManagerModules/desktop/sway/randomWallpaper.nix deleted file mode 100644 index 8b2523a2..00000000 --- a/homeManagerModules/desktop/sway/randomWallpaper.nix +++ /dev/null @@ -1,49 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: let - sway-randomWallpaper = pkgs.writeShellScriptBin "sway-randomWallpaper" '' - kill `pidof swaybg` - - OLD_PIDS=() - directory=${config.xdg.dataHome}/backgrounds - - if [ -d "$directory" ]; then - while true; do - NEW_PIDS=() - - monitor=`${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"} -t get_outputs -p | grep Output | awk '{print $2}'` - for m in ''${monitor[@]}; do - random_background=$(ls $directory/*.{png,jpg} | shuf -n 1) - ${lib.getExe pkgs.swaybg} -o $m -i $random_background -m fill & - NEW_PIDS+=($!) - done - - if [[ ''${OLD_PIDS[@]} -gt 0 ]]; then - sleep 5 - fi - - for pid in ''${OLD_PIDS[@]}; do - kill $pid - done - - OLD_PIDS=$NEW_PIDS - - sleep 895 - done - fi - ''; -in { - config = lib.mkIf config.ar.home.desktop.sway.randomWallpaper { - home.packages = [ - pkgs.swaybg - sway-randomWallpaper - ]; - - wayland.windowManager.sway.config.startup = [ - {command = "${lib.getExe sway-randomWallpaper}";} - ]; - }; -} diff --git a/homeManagerModules/desktop/sway/scripts.nix b/homeManagerModules/desktop/sway/scripts.nix index 78c6d014..96c29f57 100644 --- a/homeManagerModules/desktop/sway/scripts.nix +++ b/homeManagerModules/desktop/sway/scripts.nix @@ -22,4 +22,36 @@ in { else ''\'' } ''; + + randomWallpaper = pkgs.writeShellScript "sway-randomWallpaper" '' + kill `pidof swaybg` + + OLD_PIDS=() + directory=${config.xdg.dataHome}/backgrounds + + if [ -d "$directory" ]; then + while true; do + NEW_PIDS=() + + monitor=`${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"} -t get_outputs -p | grep Output | awk '{print $2}'` + for m in ''${monitor[@]}; do + random_background=$(ls $directory/*.{png,jpg} | shuf -n 1) + ${lib.getExe pkgs.swaybg} -o $m -i $random_background -m fill & + NEW_PIDS+=($!) + done + + if [[ ''${OLD_PIDS[@]} -gt 0 ]]; then + sleep 5 + fi + + for pid in ''${OLD_PIDS[@]}; do + kill $pid + done + + OLD_PIDS=$NEW_PIDS + + sleep 895 + done + fi + ''; } diff --git a/homeManagerModules/desktop/sway/settings.nix b/homeManagerModules/desktop/sway/settings.nix index 119b64dc..d68897ca 100644 --- a/homeManagerModules/desktop/sway/settings.nix +++ b/homeManagerModules/desktop/sway/settings.nix @@ -228,7 +228,8 @@ in { ] ++ lib.optional cfg.desktop.sway.redShift {command = "${lib.getExe pkgs.gammastep} -l 33.74:-84.38";} - ++ lib.optional cfg.desktop.sway.randomWallpaper {command = "${lib.getExe pkgs.swaybg} -i ${cfg.theme.wallpaper}";}; + ++ lib.optional cfg.desktop.sway.randomWallpaper {command = "${scripts.randomWallpaper}";} + ++ lib.optional (!cfg.desktop.sway.randomWallpaper) {command = "${lib.getExe pkgs.swaybg} -i ${cfg.theme.wallpaper}";}; output = { "BOE 0x095F Unknown".scale = "1.5";