nixos/home/common/optional/desktop/wayland/swww-wallpaper-changer.nix

38 lines
1.2 KiB
Nix
Raw Normal View History

2024-05-11 20:55:27 +01:00
{
2024-05-12 11:09:46 +01:00
pkgs,
...
}:
{
systemd.user.services.wallpaper-changer = {
Unit = {
Description = "Script to change wallpaper using swww";
PartOf = [ "hyprland-session.target" ];
After = [ "hyprland-session.target" ]; # or "wayland.target", depending on your system setup
2024-05-12 11:09:46 +01:00
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
Type = [ "simple" ];
ExecStart = "${pkgs.writeShellScript "swww-wallpaper-changer" ''
2024-05-12 11:09:46 +01:00
export WAYLAND_DISPLAY="wayland-1"
wallpaper_dir="$HOME/.local/share/bg/"
[ -d "$wallpaper_dir" ] || mkdir -p "$wallpaper_dir"
# Allow some time for desktop to start
sleep 3
echo "starting daemon..."
${pkgs.swww}/bin/swww-daemon &
2024-05-12 11:09:46 +01:00
while true; do
find "$wallpaper_dir" -type f -follow \( -iname \*.jpg -o -iname \*.png -o -iname \*.gif -o -iname \*.bmp \) | shuf | while read -r file; do
${pkgs.swww}/bin/swww img "$file" --transition-step 10 --transition-fps 60
2024-05-16 11:55:24 +01:00
[ $? != 0 ] && echo "swww failed, reloading daemon" && ${pkgs.swww}/bin/swww-daemon &
sleep 600
2024-05-12 11:09:46 +01:00
done
done
''}";
};
2024-05-11 20:55:27 +01:00
};
}