Regenerated
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
WALLPAPER_DIR="$HOME/Wallpapers/pictures"
|
||||
echo "Wallpaper dir = $WALLPAPER_DIR"
|
||||
|
||||
randomize_and_rename_wallpapers() {
|
||||
echo "Randomizing JPG filenames..."
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
# Grab all jpg/JPG files
|
||||
files=("$WALLPAPER_DIR"/*.[jJ][pP][gG])
|
||||
|
||||
if [ ${#files[@]} -eq 0 ]; then
|
||||
echo "No JPG files found in $WALLPAPER_DIR"
|
||||
return
|
||||
fi
|
||||
|
||||
# Shuffle the array
|
||||
mapfile -t files < <(printf "%s\n" "${files[@]}" | shuf)
|
||||
|
||||
tmp_names=()
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
ext="${file##*.}"
|
||||
|
||||
# generate a random 16-character alphanumeric name
|
||||
while : ; do
|
||||
rand_name=$(head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c16)
|
||||
new_path="$WALLPAPER_DIR/$rand_name.$ext"
|
||||
if [[ ! -e "$new_path" ]]; then
|
||||
mv "$file" "$new_path"
|
||||
tmp_names+=("$new_path")
|
||||
echo "Renamed $file -> $new_path"
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# Sequentially rename to 01.jpg ... 99.jpg
|
||||
counter=1
|
||||
for file in "${tmp_names[@]}"; do
|
||||
new_name=$(printf "%02d.jpg" "$counter")
|
||||
mv "$file" "$WALLPAPER_DIR/$new_name"
|
||||
echo "Final rename $file -> $WALLPAPER_DIR/$new_name"
|
||||
((counter++))
|
||||
[[ $counter -gt 99 ]] && break
|
||||
done
|
||||
|
||||
echo "Randomization complete."
|
||||
}
|
||||
|
||||
randomize_and_rename_wallpapers
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
set -euo pipefail
|
||||
|
||||
WALLPAPER_DIR="$HOME/Wallpapers"
|
||||
|
||||
# -----------------------------
|
||||
# Set wallpaper on all monitors
|
||||
# -----------------------------
|
||||
set_wallpaper_all_monitors() {
|
||||
pic="$1"
|
||||
monitors=$(hyprctl monitors -j | jq -r '.[].name') # list all monitor names
|
||||
for m in $monitors; do
|
||||
swww img -o "$m" -t fade --transition-duration 1 "$pic"
|
||||
done
|
||||
}
|
||||
|
||||
# -----------------------------
|
||||
# Handle workspace events
|
||||
# -----------------------------
|
||||
handle() {
|
||||
case $1 in
|
||||
workspace*)
|
||||
workspace="${1: -1}" # last character
|
||||
pic=""
|
||||
case $workspace in
|
||||
1) pic="$WALLPAPER_DIR/01.jpg" ;;
|
||||
2) pic="$WALLPAPER_DIR/02.jpg" ;;
|
||||
3) pic="$WALLPAPER_DIR/03.jpg" ;;
|
||||
4) pic="$WALLPAPER_DIR/04.jpg" ;;
|
||||
5) pic="$WALLPAPER_DIR/05.jpg" ;;
|
||||
6) pic="$WALLPAPER_DIR/06.jpg" ;;
|
||||
7) pic="$WALLPAPER_DIR/07.jpg" ;;
|
||||
8) pic="$WALLPAPER_DIR/08.jpg" ;;
|
||||
9) pic="$WALLPAPER_DIR/09.jpg" ;;
|
||||
10) pic="$WALLPAPER_DIR/10.jpg" ;;
|
||||
esac
|
||||
|
||||
[ -n "$pic" ] && set_wallpaper_all_monitors "$pic"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# -----------------------------
|
||||
# Listen to Hyprland socket events
|
||||
# -----------------------------
|
||||
socat -U - UNIX-CONNECT:"$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do
|
||||
handle "$line"
|
||||
done
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user