Hyprland-dotfiles/qtile/scripts/wallpaper.sh

98 lines
3.2 KiB
Bash
Raw Normal View History

2023-03-09 03:25:31 -05:00
#!/bin/bash
# ____ _ _____ _
# / ___| |__ __ _ _ __ __ _ ___ |_ _| |__ ___ _ __ ___ ___
# | | | '_ \ / _` | '_ \ / _` |/ _ \ | | | '_ \ / _ \ '_ ` _ \ / _ \
# | |___| | | | (_| | | | | (_| | __/ | | | | | | __/ | | | | | __/
# \____|_| |_|\__,_|_| |_|\__, |\___| |_| |_| |_|\___|_| |_| |_|\___|
# |___/
#
# by Stephan Raabe (2023)
# -----------------------------------------------------
2023-02-09 04:27:03 -05:00
2023-12-21 05:05:20 -05:00
# Cache file for holding the current wallpaper
2024-05-23 09:42:03 -04:00
wallpaper_folder="$HOME/wallpaper"
if [ -f ~/dotfiles/.settings/wallpaper-folder.sh ] ;then
source ~/dotfiles/.settings/wallpaper-folder.sh
fi
2023-12-21 05:05:20 -05:00
cache_file="$HOME/.cache/current_wallpaper"
2024-03-07 15:26:02 -05:00
blurred="$HOME/.cache/blurred_wallpaper.png"
2023-12-21 05:05:20 -05:00
rasi_file="$HOME/.cache/current_wallpaper.rasi"
# Create cache file if not exists
if [ ! -f $cache_file ] ;then
touch $cache_file
2024-05-23 09:42:03 -04:00
echo "$wallpaper_folder/default.jpg" > "$cache_file"
2023-12-21 05:05:20 -05:00
fi
# Create rasi file if not exists
if [ ! -f $rasi_file ] ;then
touch $rasi_file
2024-05-23 09:42:03 -04:00
echo "* { current-image: url(\"$wallpaper_folder/default.jpg\", height); }" > "$rasi_file"
2023-12-21 05:05:20 -05:00
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
2024-05-23 09:42:03 -04:00
wal -q -i $wallpaper_folder
2023-11-10 16:12:15 -05:00
fi
;;
# Select wallpaper with rofi
"select")
2024-05-23 09:42:03 -04:00
selected=$( find "$wallpaper_folder" -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
2024-05-23 09:42:03 -04:00
echo -en "$rfile\x00icon\x1f$wallpaper_folder/${rfile}\n"
2023-12-20 05:05:15 -05:00
done | rofi -dmenu -replace -l 6 -config ~/dotfiles/rofi/config-wallpaper.rasi)
2023-11-10 16:12:15 -05:00
if [ ! "$selected" ]; then
echo "No wallpaper selected"
exit
fi
2024-05-23 09:42:03 -04:00
wal -q -i $wallpaper_folder/$selected
2023-11-10 16:12:15 -05:00
;;
# Randomly select wallpaper
*)
2024-05-23 09:42:03 -04:00
wal -q -i $wallpaper_folder/
2023-11-10 16:12:15 -05:00
;;
esac
2023-02-09 04:27:03 -05:00
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-02-09 04:27:03 -05:00
# Reload qtile to color bar
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-02-09 04:27:03 -05:00
qtile cmd-obj -o cmd -f reload_config
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-04-08 10:26:43 -04:00
# Get new theme
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-04-08 10:26:43 -04:00
source "$HOME/.cache/wal/colors.sh"
2023-11-10 16:12:15 -05:00
echo "Wallpaper: $wallpaper"
2023-04-11 04:27:01 -04:00
newwall=$(echo $wallpaper | sed "s|$HOME/wallpaper/||g")
2023-10-02 04:51:16 -04:00
2024-03-07 15:26:02 -05:00
# -----------------------------------------------------
# Created blurred wallpaper
# -----------------------------------------------------
2024-03-08 04:31:55 -05:00
magick $wallpaper -resize 50% $blurred
echo ":: Resized to 50%"
magick $blurred -blur 50x30 $blurred
echo ":: Blurred"
2023-10-02 04:51:16 -04:00
# -----------------------------------------------------
2023-12-21 05:05:20 -05:00
# Write selected wallpaper into .cache files
2023-10-02 04:51:16 -04:00
# -----------------------------------------------------
2023-12-21 05:05:20 -05:00
echo "$wallpaper" > "$cache_file"
2024-03-07 15:26:02 -05:00
echo "* { current-image: url(\"$blurred\", height); }" > "$rasi_file"
2023-10-02 04:51:16 -04:00
2023-09-18 16:13:15 -04:00
sleep 1
2023-04-10 11:04:46 -04:00
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-04-08 10:26:43 -04:00
# Send notification
2023-08-20 05:46:46 -04:00
# -----------------------------------------------------
2023-09-20 07:56:57 -04:00
notify-send "Colors and Wallpaper updated" "with image $newwall"
2023-03-06 11:55:42 -05:00
echo "Done."