init
This commit is contained in:
Executable
+211
@@ -0,0 +1,211 @@
|
||||
#!/bin/bash
|
||||
# _ _
|
||||
# __ ____ _| | |_ __ __ _ _ __ ___ _ __
|
||||
# \ \ /\ / / _` | | | '_ \ / _` | '_ \ / _ \ '__|
|
||||
# \ V V / (_| | | | |_) | (_| | |_) | __/ |
|
||||
# \_/\_/ \__,_|_|_| .__/ \__,_| .__/ \___|_|
|
||||
# |_| |_|
|
||||
#
|
||||
# by Stephan Raabe (2024)
|
||||
# -----------------------------------------------------
|
||||
|
||||
# Cache file for holding the current wallpaper
|
||||
wallpaper_folder="$HOME/wallpaper"
|
||||
if [ -f ~/dotfiles/.settings/wallpaper-folder.sh ] ;then
|
||||
source ~/dotfiles/.settings/wallpaper-folder.sh
|
||||
fi
|
||||
used_wallpaper="$HOME/.cache/used_wallpaper"
|
||||
cache_file="$HOME/.cache/current_wallpaper"
|
||||
square="$HOME/.cache/square_wallpaper.png"
|
||||
rasi_file="$HOME/.cache/current_wallpaper.rasi"
|
||||
blur_file="$HOME/dotfiles/.settings/blur.sh"
|
||||
|
||||
square_dir="$HOME/.cache/square_wallpaper/"
|
||||
|
||||
mkdir -pv "${square_dir}"
|
||||
|
||||
blur="50x30"
|
||||
blur=$(cat $blur_file)
|
||||
|
||||
# Create cache file if not exists
|
||||
#if [ ! -f $cache_file ] ;then
|
||||
# touch $cache_file
|
||||
# echo "$wallpaper_folder/default.jpg" > "$cache_file"
|
||||
#fi
|
||||
|
||||
## Create rasi file if not exists
|
||||
#if [ ! -f $rasi_file ] ;then
|
||||
# touch $rasi_file
|
||||
# echo "* { current-image: url(\"$wallpaper_folder/default.jpg\", height); }" > "$rasi_file"
|
||||
#fi
|
||||
|
||||
#current_wallpaper=$(cat "$cache_file")
|
||||
|
||||
case $1 in
|
||||
|
||||
# Load wallpaper from .cache of last session
|
||||
"init")
|
||||
sleep 1
|
||||
if [ -f $cache_file ]; then
|
||||
pass #wal -q -i $current_wallpaper
|
||||
else
|
||||
pass #wal -q -i $wallpaper_folder/
|
||||
fi
|
||||
;;
|
||||
|
||||
# Select wallpaper with rofi
|
||||
"select")
|
||||
sleep 0.2
|
||||
entries=""
|
||||
for wp in "${wallpaper_folder}"/*.{jpg,jpeg,png}; do
|
||||
[[ -f "$wp" ]] || continue
|
||||
name=$(basename "$wp")
|
||||
#name="${name%.*}"
|
||||
sq="${square_dir}/${name%.*}.png"
|
||||
|
||||
if [[ ! -f "${sq}" ]]; then
|
||||
magick "${wp}" -gravity Center -extent 512:512 "$sq"
|
||||
fi
|
||||
entries+="${name}\x00icon\x1f${sq}\n"
|
||||
done
|
||||
|
||||
selected=$( printf "$entries" | sort -R | rofi -dmenu -i -replace -config ~/dotfiles/rofi/config-wallpaper.rasi)
|
||||
if [ ! "$selected" ]; then
|
||||
echo "No wallpaper selected"
|
||||
exit
|
||||
fi
|
||||
#wal -q -i $wallpaper_folder/$selected
|
||||
export wallpaper=$wallpaper_folder/$selected
|
||||
echo $wallpaper
|
||||
;;
|
||||
|
||||
# Randomly select wallpaper
|
||||
*)
|
||||
pass
|
||||
#wal -q -i $wallpaper_folder/
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Load current pywal color scheme
|
||||
# -----------------------------------------------------
|
||||
#source "$HOME/.cache/wal/colors.sh"
|
||||
|
||||
# -----------------------------------------------------
|
||||
# get wallpaper image name
|
||||
# -----------------------------------------------------
|
||||
newwall=$(echo $wallpaper | sed "s|$wallpaper_folder/||g")
|
||||
echo $newwall
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Reload waybar with new colors
|
||||
# -----------------------------------------------------
|
||||
~/dotfiles/waybar/launch.sh
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Set the new wallpaper
|
||||
# -----------------------------------------------------
|
||||
transition_type="wipe"
|
||||
# transition_type="outer"
|
||||
# transition_type="random"
|
||||
|
||||
ln -svfr $wallpaper $used_wallpaper
|
||||
|
||||
# Load Wallpaper Effect
|
||||
if [ -f $HOME/dotfiles/.settings/wallpaper-effect.sh ] ;then
|
||||
effect=$(cat $HOME/dotfiles/.settings/wallpaper-effect.sh)
|
||||
if [ ! "$effect" == "off" ] ;then
|
||||
if [ "$1" == "init" ] ;then
|
||||
echo ":: Init"
|
||||
else
|
||||
notify-send -e "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
|
||||
fi
|
||||
fi
|
||||
|
||||
wallpaper_engine=$(cat $HOME/dotfiles/.settings/wallpaper-engine.sh)
|
||||
if [ "$wallpaper_engine" == "awww" ] ;then
|
||||
# awww
|
||||
echo ":: Using awww"
|
||||
awww img $used_wallpaper \
|
||||
--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
|
||||
wal_tpl=$(cat $HOME/dotfiles/.settings/hyprpaper.tpl)
|
||||
output=${wal_tpl//WALLPAPER/$used_wallpaper}
|
||||
echo "$output" > $HOME/dotfiles/hypr/hyprpaper.conf
|
||||
hyprpaper &
|
||||
else
|
||||
echo ":: Wallpaper Engine disabled"
|
||||
fi
|
||||
|
||||
if [ "$1" == "init" ] ;then
|
||||
echo ":: Init"
|
||||
else
|
||||
sleep 1
|
||||
notifyid=$(notify-send -e "Changing wallpaper ..." "with image $newwall" -h int:value:25 -p)
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Created blurred wallpaper
|
||||
# -----------------------------------------------------
|
||||
if [ "$1" == "init" ] ;then
|
||||
echo ":: Init"
|
||||
else
|
||||
notify-send -e "Creating blurred version ..." "with image $newwall" -h int:value:50 -r $notifyid
|
||||
fi
|
||||
|
||||
#magick $used_wallpaper -resize 75% $blurred
|
||||
#echo ":: Resized to 75%"
|
||||
#if [ ! "$blur" == "0x0" ] ;then
|
||||
# magick $blurred -blur $blur $blurred
|
||||
# echo ":: Blurred"
|
||||
#fi
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Created quare wallpaper
|
||||
# -----------------------------------------------------
|
||||
if [ "$1" == "init" ] ;then
|
||||
echo ":: Init"
|
||||
else
|
||||
notify-send -e "Creating square version ..." "with image $newwall" -h int:value:75 -r $notifyid
|
||||
fi
|
||||
#magick $wallpaper -gravity Center -extent 1:1 $square
|
||||
name=$(basename "$wallpaper")
|
||||
ln -svfr "${square_dir}/${name%.*}.png" "$square"
|
||||
echo ":: Square version created"
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Write selected wallpaper into .cache files
|
||||
# -----------------------------------------------------
|
||||
echo "$wallpaper" > "$cache_file"
|
||||
|
||||
#read bw bh < <(identify -format "%w %h" "$blurred")
|
||||
#rw=900
|
||||
#rh=522
|
||||
#if (( bw * rh >= rw * bh )); then
|
||||
# scale=height
|
||||
#else
|
||||
# scale=width
|
||||
#fi
|
||||
#echo "* { current-image: url(\"$blurred\", $scale); }" > "$rasi_file"
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Send notification
|
||||
# -----------------------------------------------------
|
||||
|
||||
if [ "$1" == "init" ] ;then
|
||||
echo ":: Init"
|
||||
else
|
||||
notify-send -e "Wallpaper procedure complete!" "with image $newwall" -h int:value:100 -r $notifyid -t 1000
|
||||
fi
|
||||
|
||||
echo "DONE!"
|
||||
Reference in New Issue
Block a user