Hyprland-dotfiles/hypr/scripts/wallpaper.sh

110 lines
3.2 KiB
Bash
Raw Normal View History

2023-08-17 10:59:28 -04:00
#!/bin/bash
2023-11-10 16:12:15 -05:00
# _ _
# __ ____ _| | |_ __ __ _ _ __ ___ _ __
# \ \ /\ / / _` | | | '_ \ / _` | '_ \ / _ \ '__|
# \ V V / (_| | | | |_) | (_| | |_) | __/ |
# \_/\_/ \__,_|_|_| .__/ \__,_| .__/ \___|_|
# |_| |_|
2023-08-17 11:44:09 -04:00
#
# by Stephan Raabe (2023)
# -----------------------------------------------------
2023-08-17 10:59:28 -04:00
2023-12-21 05:05:20 -05:00
# Cache file for holding the current wallpaper
cache_file="$HOME/.cache/current_wallpaper"
rasi_file="$HOME/.cache/current_wallpaper.rasi"
# 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")
2023-11-10 16:12:15 -05:00
case $1 in
# Load wallpaper from .cache of last session
"init")
2023-12-21 05:05:20 -05:00
if [ -f $cache_file ]; then
wal -q -i $current_wallpaper
2023-11-10 16:12:15 -05:00
else
wal -q -i ~/wallpaper/
fi
;;
# Select wallpaper with rofi
"select")
2023-12-20 05:05:15 -05:00
2023-12-21 07:14:11 -05:00
selected=$( find "$HOME/wallpaper" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) -exec basename {} \; | sort -R | while read rfile
2023-12-20 05:05:15 -05:00
do
echo -en "$rfile\x00icon\x1f$HOME/wallpaper/${rfile}\n"
2023-12-21 07:14:11 -05:00
done | rofi -dmenu -replace -config ~/dotfiles/rofi/config-wallpaper.rasi)
2023-11-10 16:12:15 -05:00
if [ ! "$selected" ]; then
echo "No wallpaper selected"
exit
fi
wal -q -i ~/wallpaper/$selected
;;
# Randomly select wallpaper
*)
wal -q -i ~/wallpaper/
;;
esac
2023-08-17 11:44:09 -04:00
# -----------------------------------------------------
# Load current pywal color scheme
# -----------------------------------------------------
2023-08-17 10:59:28 -04:00
source "$HOME/.cache/wal/colors.sh"
echo ":: Wallpaper: $wallpaper"
2023-08-17 10:59:28 -04:00
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-12-21 05:05:20 -05:00
# Write selected wallpaper into .cache files
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-12-21 05:05:20 -05:00
echo "$wallpaper" > "$cache_file"
echo "* { current-image: url(\"$wallpaper\", height); }" > "$rasi_file"
2023-08-20 05:46:46 -04:00
2023-08-17 11:44:09 -04:00
# -----------------------------------------------------
2023-12-10 07:37:48 -05:00
# get wallpaper image name
2023-08-17 11:44:09 -04:00
# -----------------------------------------------------
newwall=$(echo $wallpaper | sed "s|$HOME/wallpaper/||g")
2023-08-17 10:59:28 -04:00
2023-08-17 11:44:09 -04:00
# -----------------------------------------------------
2023-11-10 16:12:15 -05:00
# Reload waybar with new colors
# -----------------------------------------------------
~/dotfiles/waybar/launch.sh
2023-08-17 11:44:09 -04:00
# -----------------------------------------------------
2023-11-10 16:12:15 -05:00
# Set the new wallpaper
# -----------------------------------------------------
transition_type="wipe"
# transition_type="outer"
# transition_type="random"
2023-10-01 05:21:02 -04:00
swww img $wallpaper \
--transition-bezier .43,1.19,1,.4 \
--transition-fps=60 \
2023-11-10 16:12:15 -05:00
--transition-type=$transition_type \
2023-10-01 05:21:02 -04:00
--transition-duration=0.7 \
--transition-pos "$( hyprctl cursorpos )"
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
# Send notification
# -----------------------------------------------------
2024-02-27 09:57:20 -05:00
if [ "$1" == "init" ] ;then
echo ":: Init"
else
sleep 1
notify-send "Colors and Wallpaper updated" "with image $newwall"
fi
2023-08-17 10:59:28 -04:00
2023-08-20 05:46:46 -04:00
echo "DONE!"