summaryrefslogtreecommitdiff
path: root/home-config/hypr/wallpaper-daemon.sh
diff options
context:
space:
mode:
Diffstat (limited to 'home-config/hypr/wallpaper-daemon.sh')
-rwxr-xr-xhome-config/hypr/wallpaper-daemon.sh75
1 files changed, 2 insertions, 73 deletions
diff --git a/home-config/hypr/wallpaper-daemon.sh b/home-config/hypr/wallpaper-daemon.sh
index 39b2aae..b793c5a 100755
--- a/home-config/hypr/wallpaper-daemon.sh
+++ b/home-config/hypr/wallpaper-daemon.sh
@@ -3,58 +3,17 @@
3# Script initialization 3# Script initialization
4# Check if animated wallpapers exist, set env var if so 4# Check if animated wallpapers exist, set env var if so
5# Sleep for swww init to finish 5# Sleep for swww init to finish
6sleep 3
7script_init() {
8 if [ `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | wc -l` -gt 0 ]; then
9 echo "true" > /tmp/$USER-desktop-anim
10 ANIM_READY=true
11 else
12 # Download or bail here?
13 echo "no animations found, static only!"
14 fi
15}
16# check if on ac or battery
17check_if_ac() {
18 ON_AC=`cat /sys/class/power_supply/AC/online`
19 if [ $ON_AC -eq 1 ] && [ "$ANIM_READY" = true ]; then
20 echo "Anim"
21 init_anim
22 else
23 echo "Static"
24 init_static
25 fi
26}
27
28init_static() { 6init_static() {
29 # On battery or missing wallpapers, just load a random image 7 # On battery or missing wallpapers, just load a random image
30 IMG=`find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` 8 IMG=`find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
31 echo $IMG >> /tmp/$USER-desktop-anim 9 echo $IMG >> /tmp/$USER-desktop-anim
32 swww img $IMG 10 swww img $IMG
33 # This is hacky but sometimes we get into a race condition where the
34 # animated background will load anyways, so this will ensure we stay static
35 # until we definitely control swww and its state is known
36 sleep 60
37 swww img $IMG
38}
39
40init_anim() {
41 # Preload a static image until the animated one is ready
42 swww img --transition-step 255 `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
43 sleep 2
44 IMG=`find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1`
45 echo $IMG >> /tmp/$USER-desktop-anim
46 swww img $IMG
47} 11}
48 12
49begin_randomizer() { 13begin_randomizer() {
50 while :; do 14 while :; do
51 echo "Invoke selector"
52 sleep 3600 15 sleep 3600
53 if [ `cat /sys/class/power_supply/AC/online` -eq 1 ] && [ `cat /tmp/$USER-desktop-anim | head -n1` == "true" ]; then 16 switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
54 switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1`
55 else
56 switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
57 fi
58 done 17 done
59} 18}
60 19
@@ -72,35 +31,5 @@ switch_check() {
72 fi 31 fi
73} 32}
74 33
75check_load() { 34init_static
76 # If system is under stress, disable animated wallpaper. If not, allow them
77 while :; do
78 sleep 60
79 ANIM_ENABLE=`cat /tmp/$USER-desktop-anim`
80 LOAD=`cat /proc/loadavg | cut -d' ' -f1`
81
82 if [ "$ANIM_ENABLE" == "true" ] && [ $LOAD -gt 8.00 ] && [ $ANIM_READY = true ]; then
83 sed -i '1c\false' /tmp/$USER-desktop-anim
84 switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
85 elif [ "$ANIM_ENABLE" == "false" ] && [ $LOAD -lt 8.00 ] && [ $ANIM_READY = true ]; then
86 sed -i '1c\true' /tmp/$USER-desktop-anim
87 switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1`
88 fi
89 done
90}
91
92script_init
93check_if_ac
94begin_randomizer & 35begin_randomizer &
95check_load &
96
97dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',sender=':1.2',path='/org/freedesktop/UPower/devices/line_power_AC'" 2>/dev/null | stdbuf -o0 awk -F' ' '/variant boolean/ {print $(NF)}' |
98while read -r line; do
99 if [ "$line" == "true" ]; then
100 echo "switching to ac"
101 switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1`
102 elif [ "$line" == "false" ]; then
103 echo "switching to bat"
104 switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
105 fi
106done