Files
nixos/Droidnix/assets/traveldroid/Wallpapers/scripts/workspace-wallpapers.sh
T
2026-03-29 21:14:24 +00:00

47 lines
1.6 KiB
Bash
Executable File

#!/run/current-system/sw/bin/bash
set -euo pipefail
echo "Running as $(whoami)"
currentuser=$(whoami) # or set manually
currentprofile=/run/current-system/sw/bin
# -----------------------------
# Configuration
# -----------------------------
PICTURES_DIR="$HOME/Wallpapers/pictures"
NAMESPACE="main" # Fixed swww namespace
MONITOR=$($currentprofile/hyprctl monitors -j | $currentprofile/jq -r '.[0].name')
# -----------------------------
# Start swww-daemon if not running
# -----------------------------
if ! pgrep -x swww-daemon >/dev/null; then
echo "Starting swww-daemon..."
$currentprofile/swww-daemon --namespace "$NAMESPACE" &
sleep 0.5 # give socket time to appear
fi
# -----------------------------
# Gather wallpapers
# -----------------------------
mapfile -t IMAGES < <(find "$PICTURES_DIR" -type f \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \))
if [ "${#IMAGES[@]}" -eq 0 ]; then
echo "No images found in $PICTURES_DIR"
exit 1
fi
# -----------------------------
# Workspace event listener
# -----------------------------
IPC_SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
echo "Listening for workspace events on $IPC_SOCKET..."
socat -u UNIX-CONNECT:"$IPC_SOCKET" STDOUT | while read -r line; do
if [[ "$line" =~ workspace\#([0-9]+) ]]; then
WS="${BASH_REMATCH[1]}"
RAND_IMAGE="${IMAGES[RANDOM % ${#IMAGES[@]}]}"
echo "Workspace $WS active → setting wallpaper: $RAND_IMAGE"
$currentprofile/swww img "$RAND_IMAGE" --resize stretch --transition-type random --namespace "$WS"
fi
done