home-config/hypr/wallpaper-daemon.sh
51bdc7674c132f013c02c8b5b4c5f671a5a2de1c
· 1004 B · 35 lines
raw
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Script initialization |
| 4 | # Check if animated wallpapers exist, set env var if so |
| 5 | # Sleep for swww init to finish |
| 6 | init_static() { |
| 7 | # On battery or missing wallpapers, just load a random image |
| 8 | IMG=`find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` |
| 9 | echo $IMG >> /tmp/$USER-desktop-anim |
| 10 | swww img $IMG |
| 11 | } |
| 12 | |
| 13 | begin_randomizer() { |
| 14 | while :; do |
| 15 | sleep 3600 |
| 16 | switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` |
| 17 | done |
| 18 | } |
| 19 | |
| 20 | switch_check() { |
| 21 | # Simply query what image is displayed and make sure we do not overwrite |
| 22 | # it. This is more for animated wallpapers since it causes corruption |
| 23 | CURRENT_FILE=`swww query | awk -F'/' '{print $NF}'` |
| 24 | SELECTION=`echo $1 | awk -F'/' '{print $NF}'` |
| 25 | |
| 26 | if ! [ "$CURRENT_FILE" == "$SELECTION" ]; then |
| 27 | # Update the file |
| 28 | sed -i '2c'"$1" /tmp/$USER-desktop-anim |
| 29 | # Set the background! |
| 30 | swww img $1 |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | init_static |
| 35 | begin_randomizer & |