home/sway: better random wallpaper handling

This commit is contained in:
Aly Raffauf 2024-07-21 22:10:28 -04:00
parent 8b88138f03
commit fdd4b61a43
4 changed files with 34 additions and 52 deletions

View file

@ -4,8 +4,6 @@
pkgs, pkgs,
... ...
}: { }: {
imports = [./randomWallpaper.nix];
config = lib.mkIf config.ar.home.desktop.sway.enable { config = lib.mkIf config.ar.home.desktop.sway.enable {
ar.home.theme.gtk.hideTitleBar = ar.home.theme.gtk.hideTitleBar =
if config.wayland.windowManager.sway.package == pkgs.sway if config.wayland.windowManager.sway.package == pkgs.sway

View file

@ -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}";}
];
};
}

View file

@ -22,4 +22,36 @@ in {
else ''\'' 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
'';
} }

View file

@ -228,7 +228,8 @@ in {
] ]
++ lib.optional cfg.desktop.sway.redShift ++ lib.optional cfg.desktop.sway.redShift
{command = "${lib.getExe pkgs.gammastep} -l 33.74:-84.38";} {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 = { output = {
"BOE 0x095F Unknown".scale = "1.5"; "BOE 0x095F Unknown".scale = "1.5";