diff options
| author | loner <loner.games@gmail.com> | 2025-03-20 20:01:28 +0800 |
|---|---|---|
| committer | loner <loner.games@gmail.com> | 2025-03-20 20:01:28 +0800 |
| commit | a953e38d3dd49c8891b7f666e2329904bd75bbeb (patch) | |
| tree | 0c4c56b5985f37dd84e2c020f1a2ba22ce70e9ed /config/hypr/UserScripts/WallpaperSelect.sh | |
| parent | d23a644072d5d6774f373bce8f7d5734905bf659 (diff) | |
Fixed the preview of wallpaper
Diffstat (limited to 'config/hypr/UserScripts/WallpaperSelect.sh')
| -rwxr-xr-x | config/hypr/UserScripts/WallpaperSelect.sh | 247 |
1 files changed, 132 insertions, 115 deletions
diff --git a/config/hypr/UserScripts/WallpaperSelect.sh b/config/hypr/UserScripts/WallpaperSelect.sh index 4dde34f8..34e44353 100755 --- a/config/hypr/UserScripts/WallpaperSelect.sh +++ b/config/hypr/UserScripts/WallpaperSelect.sh @@ -1,5 +1,5 @@ #!/bin/bash -# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ +# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ # This script for selecting wallpapers (SUPER W) # WALLPAPERS PATH @@ -21,8 +21,8 @@ SWWW_PARAMS="--transition-fps $FPS --transition-type $TYPE --transition-duration # Check if package bc exists if ! command -v bc &>/dev/null; then - notify-send -i "$iDIR/error.png" "bc missing" "Install package bc first" - exit 1 + notify-send -i "$iDIR/error.png" "bc missing" "Install package bc first" + exit 1 fi # Variables @@ -31,8 +31,8 @@ focused_monitor=$(hyprctl monitors -j | jq -r '.[] | select(.focused) | .name') # Ensure focused_monitor is detected if [[ -z "$focused_monitor" ]]; then - notify-send -i "$iDIR/error.png" "E-R-R-O-R" "Could not detect focused monitor" - exit 1 + notify-send -i "$iDIR/error.png" "E-R-R-O-R" "Could not detect focused monitor" + exit 1 fi # Monitor details @@ -45,24 +45,24 @@ rofi_override="element-icon{size:${adjusted_icon_size}%;}" # Kill existing wallpaper daemons for video kill_wallpaper_for_video() { - swww kill 2>/dev/null - pkill mpvpaper 2>/dev/null - pkill swaybg 2>/dev/null - pkill hyprpaper 2>/dev/null + swww kill 2>/dev/null + pkill mpvpaper 2>/dev/null + pkill swaybg 2>/dev/null + pkill hyprpaper 2>/dev/null } # Kill existing wallpaper daemons for image kill_wallpaper_for_image() { - pkill mpvpaper 2>/dev/null - pkill swaybg 2>/dev/null - pkill hyprpaper 2>/dev/null + pkill mpvpaper 2>/dev/null + pkill swaybg 2>/dev/null + pkill hyprpaper 2>/dev/null } # Retrieve wallpapers (both images & videos) mapfile -d '' PICS < <(find -L "${wallDIR}" -type f \( \ - -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o \ - -iname "*.bmp" -o -iname "*.tiff" -o -iname "*.webp" -o \ - -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \) -print0) + -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o \ + -iname "*.bmp" -o -iname "*.tiff" -o -iname "*.webp" -o \ + -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \) -print0) RANDOM_PIC="${PICS[$((RANDOM % ${#PICS[@]}))]}" RANDOM_PIC_NAME=". random" @@ -72,150 +72,167 @@ rofi_command="rofi -i -show -dmenu -config $rofi_theme -theme-str $rofi_override # Sorting Wallpapers menu() { - IFS=$'\n' sorted_options=($(sort <<<"${PICS[*]}")) - - printf "%s\x00icon\x1f%s\n" "$RANDOM_PIC_NAME" "$RANDOM_PIC" - - for pic_path in "${sorted_options[@]}"; do - pic_name=$(basename "$pic_path") - printf "%s\x00icon\x1f%s\n" "$(echo "$pic_name" | cut -d. -f1)" "$pic_path" - done + IFS=$'\n' sorted_options=($(sort <<<"${PICS[*]}")) + + printf "%s\x00icon\x1f%s\n" "$RANDOM_PIC_NAME" "$RANDOM_PIC" + + for pic_path in "${sorted_options[@]}"; do + pic_name=$(basename "$pic_path") + if [[ "$pic_name" =~ \.gif$ ]]; then + cache_gif_image="$HOME/.cache/gif_preview/${pic_name}.png" + if [[ ! -f "$cache_gif_image" ]]; then + mkdir -p "$HOME/.cache/gif_preview" + magick "$pic_path[0]" -resize 1920x1080 "$cache_gif_image" + fi + printf "%s\x00icon\x1f%s\n" "$pic_name" "$cache_gif_image" + elif [[ "$pic_name" =~ \.(mp4|mkv|mov|webm|MP4|MKV|MOV|WEBM)$ ]]; then + cache_preview_image="$HOME/.cache/video_preview/${pic_name}.png" + if [[ ! -f "$cache_preview_image" ]]; then + mkdir -p "$HOME/.cache/video_preview" + ffmpeg -v error -y -i "$pic_path" -ss 00:00:01.000 -vframes 1 "$cache_preview_image" + fi + printf "%s\x00icon\x1f%s\n" "$pic_name" "$cache_preview_image" + else + printf "%s\x00icon\x1f%s\n" "$(echo "$pic_name" | cut -d. -f1)" "$pic_path" + fi + done } # Offer SDDM Sequioa Wallpaper Option (only for non-video wallpapers) set_sddm_wallpaper() { - sleep 1 - sddm_sequoia="/usr/share/sddm/themes/sequoia_2" + sleep 1 + sddm_sequoia="/usr/share/sddm/themes/sequoia_2" - if [ -d "$sddm_sequoia" ]; then + if [ -d "$sddm_sequoia" ]; then - # Check if yad is running to avoid multiple notifications - if pidof yad > /dev/null; then - killall yad - fi - - if yad --info --text="Set current wallpaper as SDDM background?\n\nNOTE: This only applies to SEQUOIA SDDM Theme" \ - --text-align=left \ - --title="SDDM Background" \ - --timeout=5 \ - --timeout-indicator=right \ - --button="yes:0" \ - --button="no:1"; then + # Check if yad is running to avoid multiple notifications + if pidof yad >/dev/null; then + killall yad + fi + + if yad --info --text="Set current wallpaper as SDDM background?\n\nNOTE: This only applies to SEQUOIA SDDM Theme" \ + --text-align=left \ + --title="SDDM Background" \ + --timeout=5 \ + --timeout-indicator=right \ + --button="yes:0" \ + --button="no:1"; then - # Check if terminal exists - if ! command -v "$terminal" &>/dev/null; then - notify-send -i "$iDIR/error.png" "Missing $terminal" "Install $terminal to enable setting of wallpaper background" - exit 1 - fi + # Check if terminal exists + if ! command -v "$terminal" &>/dev/null; then + notify-send -i "$iDIR/error.png" "Missing $terminal" "Install $terminal to enable setting of wallpaper background" + exit 1 + fi - # Open terminal to enter password - $terminal -e bash -c "echo 'Enter your password to set wallpaper as SDDM Background'; \ + # Open terminal to enter password + $terminal -e bash -c "echo 'Enter your password to set wallpaper as SDDM Background'; \ sudo cp -r $wallpaper_current '$sddm_sequoia/backgrounds/default' && \ notify-send -i '$iDIR/ja.png' 'SDDM' 'Background SET'" - fi fi + fi } modify_startup_config() { - local selected_file="$1" - local startup_config="$HOME/.config/hypr/UserConfigs/Startup_Apps.conf" + local selected_file="$1" + local startup_config="$HOME/.config/hypr/UserConfigs/Startup_Apps.conf" - # Check if it's a live wallpaper (video) - if [[ "$selected_file" =~ \.(mp4|mkv|mov|webm)$ ]]; then - # For video wallpapers: - sed -i '/^\s*exec-once\s*=\s*swww-daemon\s*--format\s*xrgb.*$/s/^/\#/' "$startup_config" - sed -i '/^\s*#\s*exec-once\s*=\s*mpvpaper\s*.*$/s/^#\s*//;' "$startup_config" + # Check if it's a live wallpaper (video) + if [[ "$selected_file" =~ \.(mp4|mkv|mov|webm)$ ]]; then + # For video wallpapers: + sed -i '/^\s*exec-once\s*=\s*swww-daemon\s*--format\s*xrgb.*$/s/^/\#/' "$startup_config" + sed -i '/^\s*#\s*exec-once\s*=\s*mpvpaper\s*.*$/s/^#\s*//;' "$startup_config" - # Update the livewallpaper variable with the selected video path (using $HOME) - selected_file="${selected_file/#$HOME/\$HOME}" # Replace /home/user with $HOME - sed -i "s|^\$livewallpaper=.*|\$livewallpaper=\"$selected_file\"|" "$startup_config" + # Update the livewallpaper variable with the selected video path (using $HOME) + selected_file="${selected_file/#$HOME/\$HOME}" # Replace /home/user with $HOME + sed -i "s|^\$livewallpaper=.*|\$livewallpaper=\"$selected_file\"|" "$startup_config" - echo "Configured for live wallpaper (video)." - else - # For image wallpapers: - sed -i '/^\s*#\s*exec-once\s*=\s*swww-daemon\s*--format\s*xrgb.*$/s/^#\s*//;' "$startup_config" - sed -i '/^\s*exec-once\s*=\s*mpvpaper\s*.*$/s/^/\#/' "$startup_config" + echo "Configured for live wallpaper (video)." + else + # For image wallpapers: + sed -i '/^\s*#\s*exec-once\s*=\s*swww-daemon\s*--format\s*xrgb.*$/s/^#\s*//;' "$startup_config" + sed -i '/^\s*exec-once\s*=\s*mpvpaper\s*.*$/s/^/\#/' "$startup_config" - echo "Configured for static wallpaper (image)." - fi + echo "Configured for static wallpaper (image)." + fi } # Apply Image Wallpaper apply_image_wallpaper() { - local image_path="$1" + local image_path="$1" - kill_wallpaper_for_image + kill_wallpaper_for_image - if ! pgrep -x "swww-daemon" > /dev/null; then - echo "Starting swww-daemon..." - swww-daemon --format xrgb & - fi - - swww img -o "$focused_monitor" "$image_path" $SWWW_PARAMS + if ! pgrep -x "swww-daemon" >/dev/null; then + echo "Starting swww-daemon..." + swww-daemon --format xrgb & + fi + + swww img -o "$focused_monitor" "$image_path" $SWWW_PARAMS - # Run additional scripts - "$SCRIPTSDIR/WallustSwww.sh" - sleep 2 - "$SCRIPTSDIR/Refresh.sh" - sleep 1 + # Run additional scripts + "$SCRIPTSDIR/WallustSwww.sh" + sleep 2 + "$SCRIPTSDIR/Refresh.sh" + sleep 1 - set_sddm_wallpaper + set_sddm_wallpaper } apply_video_wallpaper() { - local video_path="$1" + local video_path="$1" - # Check if mpvpaper is installed - if ! command -v mpvpaper &> /dev/null; then - notify-send -i "$iDIR/error.png" "E-R-R-O-R" "mpvpaper not found" - return 1 - fi - kill_wallpaper_for_video + # Check if mpvpaper is installed + if ! command -v mpvpaper &>/dev/null; then + notify-send -i "$iDIR/error.png" "E-R-R-O-R" "mpvpaper not found" + return 1 + fi + kill_wallpaper_for_video - # Apply video wallpaper using mpvpaper - mpvpaper '*' -o "load-scripts=no no-audio --loop" "$video_path" & + # Apply video wallpaper using mpvpaper + mpvpaper '*' -o "load-scripts=no no-audio --loop" "$video_path" & } # Main function main() { - choice=$(menu | $rofi_command) - choice=$(echo "$choice" | xargs) - RANDOM_PIC_NAME=$(echo "$RANDOM_PIC_NAME" | xargs) + choice=$(menu | $rofi_command) + choice=$(echo "$choice" | xargs) + RANDOM_PIC_NAME=$(echo "$RANDOM_PIC_NAME" | xargs) - if [[ -z "$choice" ]]; then - echo "No choice selected. Exiting." - exit 0 - fi + if [[ -z "$choice" ]]; then + echo "No choice selected. Exiting." + exit 0 + fi - # Handle random selection correctly - if [[ "$choice" == "$RANDOM_PIC_NAME" ]]; then - choice=$(basename "$RANDOM_PIC") - fi + # Handle random selection correctly + if [[ "$choice" == "$RANDOM_PIC_NAME" ]]; then + choice=$(basename "$RANDOM_PIC") + fi - choice_basename=$(basename "$choice" | sed 's/\(.*\)\.[^.]*$/\1/') + choice_basename=$(basename "$choice" | sed 's/\(.*\)\.[^.]*$/\1/') - # Search for the selected file in the wallpapers directory, including subdirectories - selected_file=$(find "$wallDIR" -iname "$choice_basename.*" -print -quit) + # Search for the selected file in the wallpapers directory, including subdirectories + selected_file=$(find "$wallDIR" -iname "$choice_basename.*" -print -quit) - if [[ -z "$selected_file" ]]; then - echo "File not found. Selected choice: $choice" - exit 1 - fi + if [[ -z "$selected_file" ]]; then + echo "File not found. Selected choice: $choice" + exit 1 + fi - # Modify the Startup_Apps.conf file based on wallpaper type - modify_startup_config "$selected_file" + # Modify the Startup_Apps.conf file based on wallpaper type + modify_startup_config "$selected_file" - # **CHECK FIRST** if it's a video or an image **before calling any function** - if [[ "$selected_file" =~ \.(mp4|mkv|mov|webm|MP4|MKV|MOV|WEBM)$ ]]; then - apply_video_wallpaper "$selected_file" - else - apply_image_wallpaper "$selected_file" - fi + # **CHECK FIRST** if it's a video or an image **before calling any function** + if [[ "$selected_file" =~ \.(mp4|mkv|mov|webm|MP4|MKV|MOV|WEBM)$ ]]; then + apply_video_wallpaper "$selected_file" + else + apply_image_wallpaper "$selected_file" + fi } # Check if rofi is already running -if pidof rofi > /dev/null; then - pkill rofi +if pidof rofi >/dev/null; then + pkill rofi fi -main
\ No newline at end of file +main + |
