diff options
| author | Ja.KooLit <85185940+JaKooLit@users.noreply.github.com> | 2024-08-14 00:48:44 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-14 00:48:44 +0900 |
| commit | ac062ecf708b28d10cc3275fcf9e18c736d568f4 (patch) | |
| tree | d80f5d1f469304bd625b4a8fd2c49085e24f3285 /config/hypr/UserScripts/WallpaperSelect.sh | |
| parent | f9ff441fe41e4af112411b4bef55bca98c2f7474 (diff) | |
| parent | 69a7793deddb102d9643d5ee047bde81ba25bcbd (diff) | |
Merge pull request #402 from JaKooLit/main
Main to AGS-Dev
Diffstat (limited to 'config/hypr/UserScripts/WallpaperSelect.sh')
| -rwxr-xr-x | config/hypr/UserScripts/WallpaperSelect.sh | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/config/hypr/UserScripts/WallpaperSelect.sh b/config/hypr/UserScripts/WallpaperSelect.sh index d2ca7c28..25ef30e9 100755 --- a/config/hypr/UserScripts/WallpaperSelect.sh +++ b/config/hypr/UserScripts/WallpaperSelect.sh @@ -4,11 +4,10 @@ # WALLPAPERS PATH wallDIR="$HOME/Pictures/wallpapers" +SCRIPTSDIR="$HOME/.config/hypr/scripts" # variables -SCRIPTSDIR="$HOME/.config/hypr/scripts" focused_monitor=$(hyprctl monitors | awk '/^Monitor/{name=$2} /focused: yes/{print name}') - # swww transition config FPS=60 TYPE="any" @@ -21,24 +20,28 @@ if pidof swaybg > /dev/null; then pkill swaybg fi -# Retrieve image files -PICS=($(find "${wallDIR}" -type f \( -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png -o -iname \*.gif \))) +# Retrieve image files using null delimiter to handle spaces in filenames +mapfile -d '' PICS < <(find "${wallDIR}" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \) -print0) + RANDOM_PIC="${PICS[$((RANDOM % ${#PICS[@]}))]}" RANDOM_PIC_NAME=". random" # Rofi command rofi_command="rofi -i -show -dmenu -config ~/.config/rofi/config-wallpaper.rasi" - # Sorting Wallpapers menu() { - sorted_options=($(printf '%s\n' "${PICS[@]}" | sort)) + # Sort the PICS array + IFS=$'\n' sorted_options=($(sort <<<"${PICS[*]}")) + # Place ". random" at the beginning with the random picture as an icon printf "%s\x00icon\x1f%s\n" "$RANDOM_PIC_NAME" "$RANDOM_PIC" + for pic_path in "${sorted_options[@]}"; do pic_name=$(basename "$pic_path") + # Displaying .gif to indicate animated images - if [[ -z $(echo "$pic_name" | grep -i "\.gif$") ]]; then + if [[ ! "$pic_name" =~ \.gif$ ]]; then printf "%s\x00icon\x1f%s\n" "$(echo "$pic_name" | cut -d. -f1)" "$pic_path" else printf "%s\n" "$pic_name" @@ -51,15 +54,25 @@ swww query || swww-daemon --format xrgb # Choice of wallpapers main() { - choice=$(menu | ${rofi_command}) + choice=$(menu | $rofi_command) + + # Trim any potential whitespace or hidden characters + choice=$(echo "$choice" | xargs) + RANDOM_PIC_NAME=$(echo "$RANDOM_PIC_NAME" | xargs) + # No choice case - if [[ -z $choice ]]; then + if [[ -z "$choice" ]]; then + echo "No choice selected. Exiting." exit 0 fi # Random choice case - if [ "$choice" = "$RANDOM_PIC_NAME" ]; then - swww img -o $focused_monitor "${RANDOM_PIC}" $SWWW_PARAMS + if [[ "$choice" == "$RANDOM_PIC_NAME" ]]; then + swww img -o "$focused_monitor" "$RANDOM_PIC" $SWWW_PARAMS; + sleep 0.5 + "$SCRIPTSDIR/WallustSwww.sh" + sleep 0.2 + "$SCRIPTSDIR/Refresh.sh" exit 0 fi @@ -74,7 +87,7 @@ main() { done if [[ $pic_index -ne -1 ]]; then - swww img -o $focused_monitor "${PICS[$pic_index]}" $SWWW_PARAMS + swww img -o "$focused_monitor" "${PICS[$pic_index]}" $SWWW_PARAMS else echo "Image not found." exit 1 @@ -84,12 +97,14 @@ main() { # Check if rofi is already running if pidof rofi > /dev/null; then pkill rofi - exit 0 + sleep 1 # Allow some time for rofi to close fi main sleep 0.5 -${SCRIPTSDIR}/WallustSwww.sh +"$SCRIPTSDIR/WallustSwww.sh" + sleep 0.2 -${SCRIPTSDIR}/Refresh.sh +"$SCRIPTSDIR/Refresh.sh" + |
