From 8dbf39bcaa3fda0c4b09f713ec8001a67dfd5134 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Tue, 16 Jan 2024 15:55:06 -0500 Subject: [PATCH] got rid of animated wallpapers for the time being. Too buggy and too much storage --- .../hypr/wallpaper-daemon-animated-old.sh | 106 ++++++++++++++++++ home-config/hypr/wallpaper-daemon.sh | 75 +------------ 2 files changed, 108 insertions(+), 73 deletions(-) create mode 100755 home-config/hypr/wallpaper-daemon-animated-old.sh 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 @@ +#!/usr/bin/env bash + +# Script initialization +# Check if animated wallpapers exist, set env var if so +# Sleep for swww init to finish +sleep 3 +script_init() { + if [ `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | wc -l` -gt 0 ]; then + echo "true" > /tmp/$USER-desktop-anim + ANIM_READY=true + else + # Download or bail here? + echo "no animations found, static only!" + fi +} +# check if on ac or battery +check_if_ac() { + ON_AC=`cat /sys/class/power_supply/AC/online` + if [ $ON_AC -eq 1 ] && [ "$ANIM_READY" = true ]; then + echo "Anim" + init_anim + else + echo "Static" + init_static + fi +} + +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 + # This is hacky but sometimes we get into a race condition where the + # animated background will load anyways, so this will ensure we stay static + # until we definitely control swww and its state is known + sleep 60 + swww img $IMG +} + +init_anim() { + # Preload a static image until the animated one is ready + swww img --transition-step 255 `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` + sleep 2 + IMG=`find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` + echo $IMG >> /tmp/$USER-desktop-anim + swww img $IMG +} + +begin_randomizer() { + while :; do + echo "Invoke selector" + sleep 3600 + if [ `cat /sys/class/power_supply/AC/online` -eq 1 ] && [ `cat /tmp/$USER-desktop-anim | head -n1` == "true" ]; then + switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` + else + switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` + fi + 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 +} + +check_load() { + # If system is under stress, disable animated wallpaper. If not, allow them + while :; do + sleep 60 + ANIM_ENABLE=`cat /tmp/$USER-desktop-anim` + LOAD=`cat /proc/loadavg | cut -d' ' -f1` + + if [ "$ANIM_ENABLE" == "true" ] && [ $LOAD -gt 8.00 ] && [ $ANIM_READY = true ]; then + sed -i '1c\false' /tmp/$USER-desktop-anim + switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` + elif [ "$ANIM_ENABLE" == "false" ] && [ $LOAD -lt 8.00 ] && [ $ANIM_READY = true ]; then + sed -i '1c\true' /tmp/$USER-desktop-anim + switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` + fi + done +} + +script_init +check_if_ac +begin_randomizer & +check_load & + +dbus-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)}' | +while read -r line; do + if [ "$line" == "true" ]; then + echo "switching to ac" + switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` + elif [ "$line" == "false" ]; then + echo "switching to bat" + switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` + fi +done 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 @@ # Script initialization # Check if animated wallpapers exist, set env var if so # Sleep for swww init to finish -sleep 3 -script_init() { - if [ `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | wc -l` -gt 0 ]; then - echo "true" > /tmp/$USER-desktop-anim - ANIM_READY=true - else - # Download or bail here? - echo "no animations found, static only!" - fi -} -# check if on ac or battery -check_if_ac() { - ON_AC=`cat /sys/class/power_supply/AC/online` - if [ $ON_AC -eq 1 ] && [ "$ANIM_READY" = true ]; then - echo "Anim" - init_anim - else - echo "Static" - init_static - fi -} - 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 - # This is hacky but sometimes we get into a race condition where the - # animated background will load anyways, so this will ensure we stay static - # until we definitely control swww and its state is known - sleep 60 - swww img $IMG -} - -init_anim() { - # Preload a static image until the animated one is ready - swww img --transition-step 255 `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` - sleep 2 - IMG=`find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` - echo $IMG >> /tmp/$USER-desktop-anim - swww img $IMG } begin_randomizer() { while :; do - echo "Invoke selector" sleep 3600 - if [ `cat /sys/class/power_supply/AC/online` -eq 1 ] && [ `cat /tmp/$USER-desktop-anim | head -n1` == "true" ]; then - switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` - else - switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` - fi + switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` done } @@ -72,35 +31,5 @@ switch_check() { fi } -check_load() { - # If system is under stress, disable animated wallpaper. If not, allow them - while :; do - sleep 60 - ANIM_ENABLE=`cat /tmp/$USER-desktop-anim` - LOAD=`cat /proc/loadavg | cut -d' ' -f1` - - if [ "$ANIM_ENABLE" == "true" ] && [ $LOAD -gt 8.00 ] && [ $ANIM_READY = true ]; then - sed -i '1c\false' /tmp/$USER-desktop-anim - switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` - elif [ "$ANIM_ENABLE" == "false" ] && [ $LOAD -lt 8.00 ] && [ $ANIM_READY = true ]; then - sed -i '1c\true' /tmp/$USER-desktop-anim - switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` - fi - done -} - -script_init -check_if_ac +init_static begin_randomizer & -check_load & - -dbus-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)}' | -while read -r line; do - if [ "$line" == "true" ]; then - echo "switching to ac" - switch_check `find ~/.config/hypr/Wallpapers/animated/ -name '*.gif' | sort -R | tail -n1` - elif [ "$line" == "false" ]; then - echo "switching to bat" - switch_check `find ~/.config/hypr/Wallpapers/static/ -type f | sort -R | tail -n1` - fi -done