Regenerated

This commit is contained in:
2026-03-29 23:27:43 +00:00
parent 3f616e610f
commit 8fcaf6d838
7 changed files with 466 additions and 343 deletions
@@ -1,50 +1,41 @@
#!/run/current-system/sw/bin/bash
set -euo pipefail
echo "Running as $(whoami)"
currentuser=$(whoami) # or set manually
currentpath=/run/current-system/sw/bin
while [ ! -S "$IPC_SOCKET" ]; do
echo "Waiting for Hyprland socket..."
sleep 1
done
# -----------------------------
# Configuration
# -----------------------------
PICTURES_DIR="$HOME/Wallpapers/pictures"
NAMESPACE="main" # Fixed swww namespace
MONITOR=$($currentpath/hyprctl monitors -j | $currentpath/jq -r '.[0].name')
NAMESPACE="main"
# -----------------------------
# Start swww-daemon if not running
# -----------------------------
if ! pgrep -x $currentpath/swww-daemon >/dev/null; then
echo "Starting swww-daemon..."
$currentpath/swww-daemon --namespace "$NAMESPACE" &
sleep 0.5 # give socket time to appear
fi
: "${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR is not set}"
: "${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE is not set}"
# -----------------------------
# 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..."
$currentpath/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"
$currentpath/swww img "$RAND_IMAGE" --resize stretch --transition-type random --namespace "$WS"
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