This commit is contained in:
pika 2025-06-19 15:20:20 +02:00
parent 9b3171425d
commit 9117240088
6 changed files with 93 additions and 139 deletions

View file

@ -32,12 +32,29 @@ init() {
fi
}
get-wall-dir() {
local dirs=()
dirs=(
"$HOME/.wallpapers"
"$HOME/.wallpaper"
)
for d in "${dirs[@]}"; do
if [ -d "$d" ]; then
echo "$d"
break
fi
done
}
randomSwww() {
: "${SWWW_EXCLUDED_DIRS:=Anime,Colorful,Gaming,Gifs,Logos,Nordic,Windoof}"
# if [ -z "$1" ]; then
# ─< random wallpaper selection >─────────────────────────────────────────────────────────
local wall_dir="$HOME/.wallpaper"
# local wall_dir="$HOME/.wallpaper"
local wall_dir="$(get-wall-dir)"
# ─< Create an array of directories to exclude >──────────────────────────────────────────
IFS=',' read -ra EXCLUDED_DIRS <<<"$SWWW_EXCLUDED_DIRS"
@ -57,6 +74,7 @@ randomSwww() {
# local pic=$(eval "$find_cmd" | shuf -n 1)
# Alternative approach using shopt
shopt -s globstar nullglob
local pics=()
for pic in "$wall_dir"/**/*.{png,jpg,jpeg,gif}; do
# Skip excluded directories
@ -118,6 +136,17 @@ randomSwww() {
# fi
}
swww-path() {
# ─< executing swww with the random $pic >────────────────────────────────────────────────
if swww img "$1" --transition-fps "$SWWW_TRANSITION_FPS" --transition-step "$SWWW_TRANSITION_STEP" --transition-type "$SWWW_TRANSITION"; then
notify-send "󰸉 " "Changed wallpaper to ${pic##*/}"
notify-send " " "Not sourcing from: $SWWW_EXCLUDED_DIRS"
else
notify-send "ERROR" "Failed to set wallpaper: $pic"
return 1
fi
}
# Main logic
if [ -z "$1" ]; then
init
@ -131,7 +160,11 @@ if [ -z "$1" ]; then
# exit 1
# fi
elif [ "$1" == "random" ]; then
randomSwww
if ! randomSwww; then
if ! pgrep swww; then
swww-daemon && randomSwww
fi
fi
# Use a random wallpaper
# wall_dir="$HOME/.wallpaper"
# IFS=',' read -ra EXCLUDED_DIRS <<<"$SWWW_EXCLUDED_DIRS"
@ -153,16 +186,10 @@ elif [ "$1" == "random" ]; then
else
# Use the specified path
if [ -f "$1" ]; then
# ─< executing swww with the random $pic >────────────────────────────────────────────────
if swww img "$1" --transition-fps "$SWWW_TRANSITION_FPS" --transition-step "$SWWW_TRANSITION_STEP" --transition-type "$SWWW_TRANSITION"; then
notify-send "󰸉 " "Changed wallpaper to ${pic##*/}"
notify-send " " "Not sourcing from: $SWWW_EXCLUDED_DIRS"
else
notify-send "ERROR" "Failed to set wallpaper: $pic"
return 1
if ! swww-path "$1"; then
if ! pgrep swww; then
swww-daemon && swww-path "$1"
fi
fi
else
log_notify "critical" "Error" "File not found: $1"
exit 1
fi
fi