Files
hyprland-dotfiles/.config/hypr/scripts/wallpapers/wallpaper.sh
2025-10-16 20:50:11 +02:00

73 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# _ _ _ _____ __ __ _____ _____ _____ _____ _____
# | | | | _ | | | | | _ | _ | _ | __| __ |
# | | | | | |__| |__| __| | __| __| -|
# |_____|__|__|_____|_____|__| |__|__|__| |_____|__|__|
#
current_wp="$HOME/.config/hypr/scripts/wallpapers/current_wallpaper"
blurred_wp="$HOME/.config/hypr/scripts/wallpapers/current_wallpaper_blurred.png"
wallpapers_dir="$HOME/.config/hypr/scripts/wallpapers/wallpapers"
blur="50x30"
# write path to wp into file
if [ ! -f $current_wp ]; then
touch $current_wp
echo "$HOME/wallpapers/default.png" > "$current_wp"
fi
# current wallpaper path
current_wallpaper=$(cat "$current_wp")
# echo "$current_wallpaper"
wallpapers=$(ls "$wallpapers_dir"/*.png "$wallpapers_dir"/*.jpg 2>/dev/null)
# Convert the wallpapers list into an array
wallpapers_array=($wallpapers)
# Get the index of the current wallpaper in the array
current_index=-1
for i in "${!wallpapers_array[@]}"; do
if [ "${wallpapers_array[$i]}" == "$current_wallpaper" ]; then
current_index=$i
break
fi
done
# If current wallpaper is not found in the list, set it to the first wallpaper
if [ "$current_index" -eq -1 ]; then
current_index=0
fi
# Determine the next wallpaper (loop back to the start if we're at the end)
next_index=$(( (current_index + 1) % ${#wallpapers_array[@]} ))
next_wallpaper="${wallpapers_array[$next_index]}"
# Update the current wallpaper path in the file
echo "$next_wallpaper" > "$current_wp"
# echo "Current wallpaper is now: $next_wallpaper"
wal -q -i $next_wallpaper
# launch waybar based on new wallpaper colors
source "$HOME/.cache/wal/colors.sh"
~/.config/waybar/launch.sh &
# update soft link to cava colors based on wallpaper colors
# (cava needs to manually be restarted)
ln -sf "$HOME/.cache/wal/cava-colors" "$HOME/.config/cava/config"
hyprctl hyprpaper preload "$next_wallpaper"
hyprctl hyprpaper wallpaper ",$next_wallpaper"
# Create Blurred Wallpaper
magick $next_wallpaper -resize 3840x2160\! $next_wallpaper
echo ":: Resized"
echo "Next wallpaper path: $next_wallpaper"
echo "Blurred wallpaper path: $blurred_wp"
if [ ! "$blur" == "0x0" ] ; then
magick $next_wallpaper -blur $blur $blurred_wp
echo ":: Blurred"
fi