Files
nixos/Droidnix/assets/traveldroid/Wallpapers/scripts/workspace-wallpapers.sh
T
2026-03-29 23:27:43 +00:00

42 lines
1.4 KiB
Bash
Executable File

#!/run/current-system/sw/bin/bash
set -euo pipefail
currentpath=/run/current-system/sw/bin
PICTURES_DIR="$HOME/Wallpapers/pictures"
NAMESPACE="main"
: "${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR is not set}"
: "${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE is not set}"
IPC_SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
while [ ! -S "$IPC_SOCKET" ]; do sleep 1; done
echo $IPC_SOCKET
# Start swww-daemon only if not already running for this namespace
if [ ! -S "$XDG_RUNTIME_DIR/swww/$NAMESPACE.sock" ]; then
"$currentpath/swww-daemon" --namespace "$NAMESPACE" &
sleep 0.5
fi
# Load wallpapers
mapfile -t IMAGES < <(find "$PICTURES_DIR" -type f \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \))
[ "${#IMAGES[@]}" -eq 0 ] && exit 1
# Subscribe to workspace events
{
echo '{"subscribe":["workspace"]}'
"$currentpath/socat" - UNIX-CONNECT:"$IPC_SOCKET"
} | while read -r line; do
# Only parse lines starting with '{' (JSON)
if [[ "$line" =~ ^\{ ]]; then
WS_NUM=$(echo "$line" | "$currentpath/jq" -e -r 'select(.type=="workspace" and .active==true) | .workspace' 2>/dev/null || true)
if [ -n "$WS_NUM" ]; then
RAND_IMAGE="${IMAGES[RANDOM % ${#IMAGES[@]}]}"
MONITOR=$(echo "$line" | "$currentpath/jq" -r '.monitor')
"$currentpath/swww" img "$RAND_IMAGE" --resize stretch --transition-type random --namespace "$WS_NUM"
fi
fi
done