125 lines
3.6 KiB
Bash
Executable File
125 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# _ _
|
|
# __ ____ _| | |_ __ __ _ _ __ ___ _ __
|
|
# \ \ /\ / / _` | | | '_ \ / _` | '_ \ / _ \ '__|
|
|
# \ V V / (_| | | | |_) | (_| | |_) | __/ |
|
|
# \_/\_/ \__,_|_|_| .__/ \__,_| .__/ \___|_|
|
|
# |_| |_|
|
|
#
|
|
# by Stephan Raabe (2023)
|
|
# -----------------------------------------------------
|
|
|
|
# Cache file for holding the current wallpaper
|
|
cache_file="$HOME/.cache/current_wallpaper"
|
|
blurred="$HOME/.cache/blurred_wallpaper.png"
|
|
rasi_file="$HOME/.cache/current_wallpaper.rasi"
|
|
blur_file="$HOME/dotfiles/.settings/blur.sh"
|
|
|
|
blur="50x30"
|
|
blur=$(cat $blur_file)
|
|
|
|
# Create cache file if not exists
|
|
if [ ! -f $cache_file ] ;then
|
|
touch $cache_file
|
|
echo "$HOME/wallpaper/default.jpg" > "$cache_file"
|
|
fi
|
|
|
|
# Create rasi file if not exists
|
|
if [ ! -f $rasi_file ] ;then
|
|
touch $rasi_file
|
|
echo "* { current-image: url(\"$HOME/wallpaper/default.jpg\", height); }" > "$rasi_file"
|
|
fi
|
|
|
|
current_wallpaper=$(cat "$cache_file")
|
|
|
|
case $1 in
|
|
|
|
# Load wallpaper from .cache of last session
|
|
"init")
|
|
if [ -f $cache_file ]; then
|
|
wal -q -i $current_wallpaper
|
|
else
|
|
wal -q -i ~/wallpaper/
|
|
fi
|
|
;;
|
|
|
|
# Select wallpaper with rofi
|
|
"select")
|
|
sleep 0.2
|
|
selected=$( find "$HOME/wallpaper" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) -exec basename {} \; | sort -R | while read rfile
|
|
do
|
|
echo -en "$rfile\x00icon\x1f$HOME/wallpaper/${rfile}\n"
|
|
done | rofi -dmenu -i -replace -config ~/dotfiles/rofi/config-wallpaper.rasi)
|
|
if [ ! "$selected" ]; then
|
|
echo "No wallpaper selected"
|
|
exit
|
|
fi
|
|
wal -q -i ~/wallpaper/$selected
|
|
;;
|
|
|
|
# Randomly select wallpaper
|
|
*)
|
|
wal -q -i ~/wallpaper/
|
|
;;
|
|
|
|
esac
|
|
|
|
# -----------------------------------------------------
|
|
# Load current pywal color scheme
|
|
# -----------------------------------------------------
|
|
source "$HOME/.cache/wal/colors.sh"
|
|
echo ":: Wallpaper: $wallpaper"
|
|
|
|
# -----------------------------------------------------
|
|
# get wallpaper image name
|
|
# -----------------------------------------------------
|
|
newwall=$(echo $wallpaper | sed "s|$HOME/wallpaper/||g")
|
|
|
|
# -----------------------------------------------------
|
|
# Reload waybar with new colors
|
|
# -----------------------------------------------------
|
|
~/dotfiles/waybar/launch.sh
|
|
|
|
# -----------------------------------------------------
|
|
# Set the new wallpaper
|
|
# -----------------------------------------------------
|
|
transition_type="wipe"
|
|
# transition_type="outer"
|
|
# transition_type="random"
|
|
|
|
swww img $wallpaper \
|
|
--transition-bezier .43,1.19,1,.4 \
|
|
--transition-fps=60 \
|
|
--transition-type=$transition_type \
|
|
--transition-duration=0.7 \
|
|
--transition-pos "$( hyprctl cursorpos )"
|
|
|
|
# -----------------------------------------------------
|
|
# Created blurred wallpaper
|
|
# -----------------------------------------------------
|
|
magick $wallpaper -resize 75% $blurred
|
|
echo ":: Resized to 75%"
|
|
if [ ! "$blur" == "0x0" ] ;then
|
|
magick $blurred -blur $blur $blurred
|
|
echo ":: Blurred"
|
|
fi
|
|
|
|
|
|
# -----------------------------------------------------
|
|
# Write selected wallpaper into .cache files
|
|
# -----------------------------------------------------
|
|
echo "$wallpaper" > "$cache_file"
|
|
echo "* { current-image: url(\"$blurred\", height); }" > "$rasi_file"
|
|
|
|
# -----------------------------------------------------
|
|
# Send notification
|
|
# -----------------------------------------------------
|
|
|
|
if [ "$1" == "init" ] ;then
|
|
echo ":: Init"
|
|
else
|
|
notify-send "Colors and Wallpaper updated" "with image $newwall"
|
|
fi
|
|
|
|
echo "DONE!"
|