diff --git a/.gitignore b/.gitignore index 68ee706..746d54b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ current home-config/sway/monitors +*.gif diff --git a/home-config/hypr/Wallpapers/above-clouds.jpg b/home-config/hypr/Wallpapers/static/above-clouds.jpg similarity index 100% rename from home-config/hypr/Wallpapers/above-clouds.jpg rename to home-config/hypr/Wallpapers/static/above-clouds.jpg diff --git a/home-config/hypr/Wallpapers/mountains.jpg b/home-config/hypr/Wallpapers/static/mountains.jpg similarity index 100% rename from home-config/hypr/Wallpapers/mountains.jpg rename to home-config/hypr/Wallpapers/static/mountains.jpg diff --git a/home-config/hypr/autostart.sh b/home-config/hypr/autostart.sh index b05b71d..e09ef2b 100755 --- a/home-config/hypr/autostart.sh +++ b/home-config/hypr/autostart.sh @@ -10,10 +10,12 @@ mako & swww init & +~/.config/hypr/wallpaper-daemon.sh & + swayidle -w timeout 300 'swaylock --screenshots --clock --indicator --grace 3 --fade-in 1 --effect-blur 7x5 --effect-greyscale' timeout 600 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' before-sleep 'swaylock -f -c 000000' & syncthing serve --no-browser & wl-clip-persist -c regular & -kanshi -c ~/.config/hypr/kanshi.conf +~/.config/guix/home-config/hypr/hyprland-monitor-attached ~/.config/hypr/wallpaper.sh ~/.config/hypr/wallpaper.sh & diff --git a/home-config/hypr/hyprland-monitor-attached b/home-config/hypr/hyprland-monitor-attached new file mode 100755 index 0000000..9c22710 Binary files /dev/null and b/home-config/hypr/hyprland-monitor-attached differ diff --git a/home-config/hypr/kanshi.conf b/home-config/hypr/kanshi.conf deleted file mode 100644 index 6a2cbfe..0000000 --- a/home-config/hypr/kanshi.conf +++ /dev/null @@ -1,4 +0,0 @@ -profile { - output * enable - exec ~/.config/hypr/wallpaper.sh -} diff --git a/home-config/hypr/wallpaper-daemon.sh b/home-config/hypr/wallpaper-daemon.sh new file mode 100755 index 0000000..5f53d33 --- /dev/null +++ b/home-config/hypr/wallpaper-daemon.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash + +# Script initialization +rm /tmp/$USER-desktop-anim +# 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 +} + +script_init +check_if_ac +begin_randomizer & + +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.sh b/home-config/hypr/wallpaper.sh index 7d9ea21..ac2c627 100755 --- a/home-config/hypr/wallpaper.sh +++ b/home-config/hypr/wallpaper.sh @@ -1,6 +1,9 @@ #!/bin/sh -# Eventually allow for multiple animated backgrounds to be rotated. -# Right now just reset the current image for when outputs are changed +sleep 2 -swww img ~/.config/hypr/Wallpapers/above-clouds.jpg +# Get currently loaded image +IMG=`cat /tmp/$USER-desktop-anim | tail -n1` + +# Load it for the monitors +swww img $IMG