summaryrefslogtreecommitdiff
path: root/home-config/hypr/wallpaper-daemon-animated-old.sh
diff options
context:
space:
mode:
authorRyan Schanzenbacher <ryan@rschanz.org>2024-01-16 15:55:06 -0500
committerRyan Schanzenbacher <ryan@rschanz.org>2024-01-16 15:55:06 -0500
commit8dbf39bcaa3fda0c4b09f713ec8001a67dfd5134 (patch)
tree6fc6b5bd32f9223c546119bec27e3f5d7205f746 /home-config/hypr/wallpaper-daemon-animated-old.sh
parentbc562fccc35cacc7f926e1aebc73b9a74fc158a9 (diff)
got rid of animated wallpapers for the time being. Too buggy and too
much storage
Diffstat (limited to 'home-config/hypr/wallpaper-daemon-animated-old.sh')
-rwxr-xr-xhome-config/hypr/wallpaper-daemon-animated-old.sh106
1 files changed, 106 insertions, 0 deletions
diff --git a/home-config/hypr/wallpaper-daemon-animated-old.sh b/home-config/hypr/wallpaper-daemon-animated-old.sh
new file mode 100755
index 0000000..39b2aae
--- /dev/null
+++ b/home-config/hypr/wallpaper-daemon-animated-old.sh
@@ -0,0 +1,106 @@
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
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() {
29 # On battery or missing wallpapers, just load a random image
30 IMG=`find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1`
31 echo $IMG >> /tmp/$USER-desktop-anim
32 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}
48
49begin_randomizer() {
50 while :; do
51 echo "Invoke selector"
52 sleep 3600
53 if [ `cat /sys/class/power_supply/AC/online` -eq 1 ] && [ `cat /tmp/$USER-desktop-anim | head -n1` == "true" ]; then
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
59}
60
61switch_check() {
62 # Simply query what image is displayed and make sure we do not overwrite
63 # it. This is more for animated wallpapers since it causes corruption
64 CURRENT_FILE=`swww query | awk -F'/' '{print $NF}'`
65 SELECTION=`echo $1 | awk -F'/' '{print $NF}'`
66
67 if ! [ "$CURRENT_FILE" == "$SELECTION" ]; then
68 # Update the file
69 sed -i '2c'"$1" /tmp/$USER-desktop-anim
70 # Set the background!
71 swww img $1
72 fi
73}
74
75check_load() {
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 &
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