Files
nixos/Droidnix/assets/traveldroid/Wallpapers/scripts/set-wallpapers.sh
T
2026-03-29 15:48:40 +00:00

55 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# -----------------------------
# Configuration
# -----------------------------
PICTURES_DIR="$HOME/Wallpapers/pictures"
NAMESPACE="main" # Base namespace for swww-daemon
MONITOR=$(hyprctl monitors -j | jq -r '.[0].name') # First monitor
# -----------------------------
# Start swww-daemon if not running
# -----------------------------
if ! pgrep -x swww-daemon >/dev/null; then
echo "Starting swww-daemon..."
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
# -----------------------------
# Pre-assign wallpapers to each workspace
# -----------------------------
declare -A WS_WALLPAPER
for ws in $(hyprctl workspaces -j | jq -r '.[].id'); do
RAND_IMAGE="${IMAGES[RANDOM % ${#IMAGES[@]}]}"
WS_WALLPAPER["$ws"]="$RAND_IMAGE"
echo "Pre-assigning wallpaper for workspace $ws: $RAND_IMAGE"
swww img "$RAND_IMAGE" --resize stretch --transition-type random --namespace "$ws"
done
# -----------------------------
# Listen for workspace events
# -----------------------------
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]}"
# Use the pre-assigned wallpaper for this workspace
RAND_IMAGE="${WS_WALLPAPER[$WS]}"
echo "Workspace $WS active → setting wallpaper: $RAND_IMAGE"
swww img "$RAND_IMAGE" --resize stretch --transition-type random --namespace "$WS"
fi
done