summaryrefslogtreecommitdiff
path: root/home-config/hypr/wallpaper-daemon.sh
blob: b793c5ab120e697a7620d47b1efb0c7e9bd56780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash

# Script initialization
# Check if animated wallpapers exist, set env var if so
# Sleep for swww init to finish
init_static() {
    # On battery or missing wallpapers, just load a random image
    IMG=`find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
    echo $IMG >> /tmp/$USER-desktop-anim
    swww img $IMG
}

begin_randomizer() {
    while :; do
        sleep 3600
        switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
    done
}

switch_check() {
    # Simply query what image is displayed and make sure we do not overwrite
    # it. This is more for animated wallpapers since it causes corruption
    CURRENT_FILE=`swww query | awk -F'/' '{print $NF}'`
    SELECTION=`echo $1 | awk -F'/' '{print $NF}'`

    if ! [ "$CURRENT_FILE" == "$SELECTION" ]; then
        # Update the file
        sed -i '2c'"$1" /tmp/$USER-desktop-anim
        # Set the background!
        swww img $1
    fi
}

init_static
begin_randomizer &