-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyprpaper.sh
executable file
·70 lines (63 loc) · 2.79 KB
/
hyprpaper.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
XDG_PICTURES_DIR="${XDG_PICTURES_DIR:-$HOME/Pictures}"
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
WALLPAPERS="$XDG_PICTURES_DIR/wallpapers/"
current_bg="$(cat $XDG_CACHE_HOME/current.bg)"
# colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
DELAY=1800
while true; do
if hyprctl hyprpaper | grep invalid; then
echo -e "${RED}hyprpaper not running, launching it... - BEGIN${NC}"
hyprpaper &
fi
wallpappath=$(find "$WALLPAPERS" | shuf -n 1)
if ! [ $current_bg ]; then
echo -e "${RED}current.bg not set, setting it to $wallpappath${NC}"
echo $wallpappath > $XDG_CACHE_HOME/current.bg
echo -e "${GREEN}Regenerating wallpappath${NC}"
wallpappath=$(find "$WALLPAPERS" | shuf -n 1)
fi
# make it wallpaper the already preloaded one and preload for next time
# hyprctl hyprpaper wallpaper ", $(hyprctl hyprpaper listloaded)"
# hyprctl hyprpaper unload $(hyprctl hyprpaper listloaded)
# hyprctl hyprpaper preload $wallpappath
# while ! hyprctl hyprpaper wallpaper ", $(cat $XDG_CACHE_HOME/current.bg)"; do hyprpaper & hyprctl hyprpaper preload $(cat $XDG_CACHE_HOME/current.bg); done
tmpreturn=$(hyprctl hyprpaper wallpaper ", $(cat $XDG_CACHE_HOME/current.bg)")
while ! hyprctl hyprpaper listactive | grep $(cat $XDG_CACHE_HOME/current.bg); do
if [[ $tmpreturn == *"preload"* ]]; then
echo -e "${RED}preload failed, retrying...${NC}"
hyprctl hyprpaper preload $(cat $XDG_CACHE_HOME/current.bg)
tmpreturn=$(hyprctl hyprpaper wallpaper ", $(cat $XDG_CACHE_HOME/current.bg)")
elif [[ $tmpreturn != "ok" ]]; then
echo -e "${RED}wallpaper failed, re(try) launching hyprpaper and retrying...${NC}"
echo -e "${RED}failed with: $tmpreturn${NC}"
hyprpaper &
tmpreturn=$(hyprctl hyprpaper wallpaper ", $(cat $XDG_CACHE_HOME/current.bg)")
fi
done
hyprctl hyprpaper unload $(cat $XDG_CACHE_HOME/current.bg) | grep "ok" || hyprctl hyprpaper unload all
hyprctl hyprpaper preload $wallpappath
current_bg=$(cat $XDG_CACHE_HOME/current.bg)
if [[ $current_bg == *.jpg ]]; then
magick convert $current_bg $XDG_CACHE_HOME/bg.png &
else
cp $current_bg $XDG_CACHE_HOME/bg.png
fi
echo $wallpappath > $XDG_CACHE_HOME/current.bg
# update hyprlock
killall -SIGUSR2 hyprlock
# hyprctl hyprpaper unload $(hyprctl hyprpaper listloaded) || hyprctl hyprpaper unload all
# hyprctl hyprpaper preload $wallpappath
# hyprctl hyprpaper wallpaper ", $wallpappath"
# for hyprlock sake
if hyprctl hyprpaper; then
sleep $DELAY
else
echo -e "${RED}hyprpaper not running, skipping sleep - END${NC}"
hyprpaper &
fi
done