80 lines
1.4 KiB
Bash
Executable File
80 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
WP_DIR="$HOME/Pictures/Wallpapers"
|
|
aspect_name() {
|
|
local w="$1"
|
|
local h="$2"
|
|
local a="$w"
|
|
local b="$h"
|
|
local t
|
|
local aspect
|
|
|
|
while (( b != 0 )); do
|
|
t=$b
|
|
b=$(( a % b ))
|
|
a=$t
|
|
done
|
|
|
|
aspect="$(( w / a ))x$(( h / a ))"
|
|
|
|
case "$aspect" in
|
|
64x27|43x18)
|
|
echo "21x9"
|
|
;;
|
|
8x5)
|
|
echo "16x10"
|
|
;;
|
|
*)
|
|
echo "$aspect"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
process_wallpapers() {
|
|
wallpapers=()
|
|
while read -r line; do
|
|
if [[ "$line" == *"+*"* ]]; then
|
|
role="primary"
|
|
else
|
|
role="secondary"
|
|
fi
|
|
|
|
geom="$(awk '{print $3}' <<< "$line")"
|
|
|
|
width="${geom%%/*}"
|
|
rest="${geom#*x}"
|
|
height="${rest%%/*}"
|
|
|
|
aspect="$(aspect_name "$width" "$height")"
|
|
wallpapers+=("$WP_DIR/$aspect-$role.png")
|
|
done < <(xrandr --listmonitors | tail -n +2)
|
|
|
|
count="${#wallpapers[@]}"
|
|
|
|
modes=()
|
|
for (( i=0; i<${#wallpapers[@]}; i++ )); do
|
|
modes+=("zoom")
|
|
done
|
|
|
|
echo "${wallpapers[@]}"
|
|
|
|
hydrapaper --cli "${wallpapers[@]}" --mode "${modes[@]}"
|
|
}
|
|
|
|
last_applied=""
|
|
pending=""
|
|
|
|
while true; do
|
|
current="$(xrandr --query 2>/dev/null | grep ' connected' || true)"
|
|
|
|
if [[ "$current" != "$pending" ]]; then
|
|
pending="$current"
|
|
elif [[ "$current" != "$last_applied" ]]; then
|
|
last_applied="$current"
|
|
process_wallpapers
|
|
fi
|
|
|
|
sleep 1
|
|
done
|