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
|
|
|
#
|
2024-05-23 09:47:31 -04:00
|
|
|
# by Stephan Raabe (2024)
|
2023-08-17 11:44:09 -04:00
|
|
|
# -----------------------------------------------------
|
2023-08-17 10:59:28 -04:00
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Get wallpaper folder
|
|
|
|
# -----------------------------------------------------
|
2024-05-15 05:12:53 -04:00
|
|
|
wallpaper_folder="$HOME/wallpaper"
|
|
|
|
if [ -f ~/dotfiles/.settings/wallpaper-folder.sh ] ;then
|
|
|
|
source ~/dotfiles/.settings/wallpaper-folder.sh
|
|
|
|
fi
|
2024-06-13 09:06:45 -04:00
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# Check to use wallpaper cache
|
|
|
|
# -----------------------------------------------------
|
|
|
|
use_cache=0
|
|
|
|
if [ -f $HOME/dotfiles/.settings/wallpaper_cache ] ;then
|
|
|
|
use_cache=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$use_cache" == "1" ] ;then
|
|
|
|
echo ":: Using Wallpaper Cache"
|
|
|
|
else
|
|
|
|
echo ":: Wallpaper Cache disabled"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# File and folder names
|
|
|
|
# -----------------------------------------------------
|
|
|
|
force_generate=0
|
|
|
|
|
|
|
|
generated_versions="$HOME/.cache/ml4w-wallpaper-generated"
|
2023-12-21 05:05:20 -05:00
|
|
|
cache_file="$HOME/.cache/current_wallpaper"
|
2024-06-13 09:06:45 -04:00
|
|
|
used_wallpaper="$HOME/.cache/used_wallpaper"
|
|
|
|
blurred_wallpaper="$HOME/.cache/blurred_wallpaper.png"
|
|
|
|
square_wallpaper="$HOME/.cache/square_wallpaper.png"
|
|
|
|
|
2023-12-21 05:05:20 -05:00
|
|
|
rasi_file="$HOME/.cache/current_wallpaper.rasi"
|
2024-03-14 12:18:48 -04:00
|
|
|
blur_file="$HOME/dotfiles/.settings/blur.sh"
|
|
|
|
|
|
|
|
blur="50x30"
|
|
|
|
blur=$(cat $blur_file)
|
2023-12-21 05:05:20 -05:00
|
|
|
|
|
|
|
# Create cache file if not exists
|
|
|
|
if [ ! -f $cache_file ] ;then
|
|
|
|
touch $cache_file
|
2024-05-15 05:12:53 -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-15 05:12:53 -04:00
|
|
|
echo "* { current-image: url(\"$wallpaper_folder/default.jpg\", height); }" > "$rasi_file"
|
2023-12-21 05:05:20 -05:00
|
|
|
fi
|
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# Create folder with generated versions of wallpaper if not exists
|
|
|
|
if [ ! -d $generated_versions ] ;then
|
|
|
|
mkdir $generated_versions
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# Current wallpaper
|
|
|
|
# -----------------------------------------------------
|
2023-12-21 05:05:20 -05:00
|
|
|
current_wallpaper=$(cat "$cache_file")
|
2024-06-13 09:06:45 -04:00
|
|
|
current_wallpaper_filename=$(echo $current_wallpaper | sed "s|$wallpaper_folder/||g")
|
2023-12-21 05:05:20 -05:00
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Select Wallpaper
|
|
|
|
# -----------------------------------------------------
|
2023-11-10 16:12:15 -05:00
|
|
|
case $1 in
|
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# Remove current wallpaper cached files for regeneration
|
|
|
|
"regenerate")
|
|
|
|
sleep 1
|
|
|
|
force_generate=1
|
|
|
|
echo ":: Cached files for current wallpaper $current_wallpaper_filename will be regenerated"
|
|
|
|
notify-send "Cached files for current wallpaper $current_wallpaper_filename will be regenerated"
|
|
|
|
;;
|
|
|
|
|
|
|
|
# Empty the cache folder completely
|
|
|
|
"clearcache")
|
|
|
|
sleep 1
|
|
|
|
rm $generated_versions/*
|
|
|
|
echo ":: Wallpaper cache cleared"
|
|
|
|
notify-send "Wallpaper cache cleared"
|
|
|
|
;;
|
|
|
|
|
2023-11-10 16:12:15 -05:00
|
|
|
# Load wallpaper from .cache of last session
|
|
|
|
"init")
|
2024-03-27 08:25:38 -04:00
|
|
|
sleep 1
|
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-15 05:12:53 -04:00
|
|
|
wal -q -i $wallpaper_folder/
|
2023-11-10 16:12:15 -05:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
# Select wallpaper with rofi
|
|
|
|
"select")
|
2024-03-20 06:08:37 -04:00
|
|
|
sleep 0.2
|
2024-05-15 05:12:53 -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-06-13 09:06:45 -04:00
|
|
|
if [ -f $generated_versions/square-${rfile}.png ] ;then
|
|
|
|
echo -en "$rfile\x00icon\x1f$generated_versions/square-${rfile}.png\n"
|
|
|
|
else
|
|
|
|
echo -en "$rfile\x00icon\x1f$wallpaper_folder/${rfile}\n"
|
|
|
|
fi
|
2024-03-20 06:24:31 -04:00
|
|
|
done | rofi -dmenu -i -replace -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-15 05:12:53 -04:00
|
|
|
wal -q -i $wallpaper_folder/$selected
|
2023-11-10 16:12:15 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
# Randomly select wallpaper
|
|
|
|
*)
|
2024-05-15 05:12:53 -04:00
|
|
|
wal -q -i $wallpaper_folder/
|
2023-11-10 16:12:15 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
2023-08-17 11:44:09 -04:00
|
|
|
|
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
# Execute pywal
|
2023-08-17 11:44:09 -04:00
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
|
2023-08-17 10:59:28 -04:00
|
|
|
source "$HOME/.cache/wal/colors.sh"
|
|
|
|
|
2023-08-17 11:44:09 -04:00
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
# Selected Wallpaper
|
2023-08-17 11:44:09 -04:00
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
|
|
|
|
echo ":: Setting up wallpaper with $wallpaper"
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# Get selected wallpaper image name
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
2024-05-15 05:12:53 -04:00
|
|
|
newwall=$(echo $wallpaper | sed "s|$wallpaper_folder/||g")
|
2023-08-17 10:59:28 -04:00
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Copy selected wallpaper to .cache
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
|
|
echo ":: Copy $wallpaper to .cache"
|
|
|
|
cp $wallpaper $HOME/.cache/
|
|
|
|
mv $HOME/.cache/$newwall $used_wallpaper
|
|
|
|
|
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
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
# swww transition type
|
2023-11-10 16:12:15 -05:00
|
|
|
# -----------------------------------------------------
|
|
|
|
transition_type="wipe"
|
|
|
|
# transition_type="outer"
|
|
|
|
# transition_type="random"
|
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Wallpaper Effects
|
|
|
|
# -----------------------------------------------------
|
2024-05-28 09:36:16 -04:00
|
|
|
|
|
|
|
if [ -f $HOME/dotfiles/.settings/wallpaper-effect.sh ] ;then
|
|
|
|
effect=$(cat $HOME/dotfiles/.settings/wallpaper-effect.sh)
|
|
|
|
if [ ! "$effect" == "off" ] ;then
|
2024-06-13 09:06:45 -04:00
|
|
|
if [ -f $generated_versions/$effect-$newwall ] && [ "$force_generate" == "0" ] && [ "$use_cache" == "1" ] ;then
|
|
|
|
echo ":: Use cached wallpaper $effect_$newwall"
|
2024-05-28 09:36:16 -04:00
|
|
|
else
|
2024-06-13 09:06:45 -04:00
|
|
|
echo ":: Generate new cached wallpaper $effect-$newwall with effect $effect"
|
|
|
|
if [ "$1" == "init" ] ;then
|
|
|
|
echo ":: Init"
|
|
|
|
else
|
|
|
|
dunstify "Using wallpaper effect $effect..." "with image $newwall" -h int:value:10 -h string:x-dunst-stack-tag:wallpaper
|
|
|
|
fi
|
|
|
|
source $HOME/dotfiles/hypr/effects/wallpaper/$effect
|
|
|
|
cp $used_wallpaper $generated_versions/$effect-$newwall
|
2024-05-28 09:36:16 -04:00
|
|
|
fi
|
2024-06-13 09:06:45 -04:00
|
|
|
cp $generated_versions/$effect-$newwall $used_wallpaper
|
|
|
|
else
|
|
|
|
echo ":: Wallpaper effect is set to off"
|
2024-05-28 09:36:16 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Set new wallpaper with defined wallpaper engine
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
2024-03-28 07:23:11 -04:00
|
|
|
wallpaper_engine=$(cat $HOME/dotfiles/.settings/wallpaper-engine.sh)
|
|
|
|
if [ "$wallpaper_engine" == "swww" ] ;then
|
|
|
|
# swww
|
|
|
|
echo ":: Using swww"
|
2024-05-28 09:36:16 -04:00
|
|
|
swww img $used_wallpaper \
|
2024-03-28 07:23:11 -04:00
|
|
|
--transition-bezier .43,1.19,1,.4 \
|
|
|
|
--transition-fps=60 \
|
|
|
|
--transition-type=$transition_type \
|
|
|
|
--transition-duration=0.7 \
|
|
|
|
--transition-pos "$( hyprctl cursorpos )"
|
|
|
|
elif [ "$wallpaper_engine" == "hyprpaper" ] ;then
|
|
|
|
# hyprpaper
|
|
|
|
echo ":: Using hyprpaper"
|
|
|
|
killall hyprpaper
|
2024-03-28 10:50:38 -04:00
|
|
|
wal_tpl=$(cat $HOME/dotfiles/.settings/hyprpaper.tpl)
|
2024-05-28 09:36:16 -04:00
|
|
|
output=${wal_tpl//WALLPAPER/$used_wallpaper}
|
2024-03-28 10:50:38 -04:00
|
|
|
echo "$output" > $HOME/dotfiles/hypr/hyprpaper.conf
|
2024-06-13 09:06:45 -04:00
|
|
|
hyprpaper & > /dev/null 2>&1
|
2024-03-28 07:23:11 -04:00
|
|
|
else
|
|
|
|
echo ":: Wallpaper Engine disabled"
|
|
|
|
fi
|
2023-10-01 05:21:02 -04:00
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
# Notify that the wallpaper will changed
|
2024-03-27 08:25:38 -04:00
|
|
|
if [ "$1" == "init" ] ;then
|
|
|
|
echo ":: Init"
|
|
|
|
else
|
|
|
|
sleep 1
|
2024-04-14 07:02:29 -04:00
|
|
|
dunstify "Changing wallpaper ..." "with image $newwall" -h int:value:25 -h string:x-dunst-stack-tag:wallpaper
|
2024-05-01 07:40:33 -04:00
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# Reload Hyprctl.sh
|
|
|
|
# -----------------------------------------------------
|
2024-05-01 10:08:42 -04:00
|
|
|
$HOME/.config/ml4w-hyprland-settings/hyprctl.sh &
|
2024-03-27 08:25:38 -04:00
|
|
|
fi
|
|
|
|
|
2024-03-07 09:51:34 -05:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Created blurred wallpaper
|
2024-03-08 04:18:45 -05:00
|
|
|
# -----------------------------------------------------
|
2024-03-27 08:25:38 -04:00
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
if [ -f $generated_versions/blur-$blur-$newwall.png ] && [ "$force_generate" == "0" ] && [ "$use_cache" == "1" ] ;then
|
|
|
|
echo ":: Use cached wallpaper blur-$blur-$newwall.png"
|
|
|
|
else
|
|
|
|
echo ":: Generate new cached wallpaper blur-$blur-$newwall with blur $blur"
|
|
|
|
if [ "$1" == "init" ] ;then
|
|
|
|
echo ":: Init"
|
|
|
|
else
|
|
|
|
dunstify "Creating blurred version ..." "with image $newwall" -h int:value:50 -h string:x-dunst-stack-tag:wallpaper
|
|
|
|
fi
|
|
|
|
magick $used_wallpaper -resize 75% $blurred_wallpaper
|
|
|
|
echo ":: Resized to 75%"
|
|
|
|
if [ ! "$blur" == "0x0" ] ;then
|
|
|
|
magick $blurred_wallpaper -blur $blur $blurred_wallpaper
|
|
|
|
cp $blurred_wallpaper $generated_versions/blur-$blur-$newwall.png
|
|
|
|
echo ":: Blurred"
|
|
|
|
fi
|
|
|
|
cp $generated_versions/blur-$blur-$newwall.png $blurred_wallpaper
|
2024-03-18 05:50:51 -04:00
|
|
|
fi
|
2024-06-13 09:06:45 -04:00
|
|
|
cp $generated_versions/blur-$blur-$newwall.png $blurred_wallpaper
|
2024-03-18 05:50:51 -04:00
|
|
|
|
2024-04-14 07:02:29 -04:00
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
# Created square wallpaper
|
2024-04-14 07:02:29 -04:00
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
|
|
|
|
if [ -f $generated_versions/square-$newwall.png ] && [ "$force_generate" == "0" ] && [ "$use_cache" == "1" ] ;then
|
|
|
|
echo ":: Use cached wallpaper square-$newwall.png"
|
2024-04-14 07:02:29 -04:00
|
|
|
else
|
2024-06-13 09:06:45 -04:00
|
|
|
echo ":: Generate new cached wallpaper square-$newwall"
|
|
|
|
if [ "$1" == "init" ] ;then
|
|
|
|
echo ":: Init"
|
|
|
|
else
|
|
|
|
dunstify "Creating square version ..." "with image $newwall" -h int:value:75 -h string:x-dunst-stack-tag:wallpaper
|
|
|
|
fi
|
|
|
|
magick $wallpaper -gravity Center -extent 1:1 $square_wallpaper
|
|
|
|
cp $square_wallpaper $generated_versions/square-$newwall.png
|
2024-04-14 07:02:29 -04:00
|
|
|
fi
|
2024-06-13 09:06:45 -04:00
|
|
|
cp $generated_versions/square-$newwall.png $square_wallpaper
|
2024-04-14 07:02:29 -04:00
|
|
|
|
2024-03-07 09:51:34 -05:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Write selected wallpaper into .cache files
|
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
|
2024-03-07 09:51:34 -05:00
|
|
|
echo "$wallpaper" > "$cache_file"
|
2024-06-13 09:06:45 -04:00
|
|
|
echo "* { current-image: url(\"$blurred_wallpaper\", height); }" > "$rasi_file"
|
2024-03-07 09:51:34 -05:00
|
|
|
|
2023-08-20 05:46:46 -04:00
|
|
|
# -----------------------------------------------------
|
2024-06-13 09:06:45 -04:00
|
|
|
# Send complete notification
|
2023-08-20 05:46:46 -04:00
|
|
|
# -----------------------------------------------------
|
2024-02-27 09:57:20 -05:00
|
|
|
|
|
|
|
if [ "$1" == "init" ] ;then
|
|
|
|
echo ":: Init"
|
|
|
|
else
|
2024-03-27 08:25:38 -04:00
|
|
|
dunstify "Wallpaper procedure complete!" "with image $newwall" -h int:value:100 -h string:x-dunst-stack-tag:wallpaper
|
2024-02-27 09:57:20 -05:00
|
|
|
fi
|
2023-08-17 10:59:28 -04:00
|
|
|
|
2024-06-13 09:06:45 -04:00
|
|
|
echo "DONE!"
|