irongit
hygoland/UserScripts/WallpaperEffects.sh
140 lines4.9 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ #
3# Wallpaper Effects using ImageMagick (SUPER SHIFT W)
4
5# Variables
6terminal=foot
7wallpaper_current="$HOME/.config/hypr/wallpaper_effects/.wallpaper_current"
8wallpaper_output="$HOME/.config/hypr/wallpaper_effects/.wallpaper_modified"
9SCRIPTSDIR="$HOME/.config/hypr/scripts"
10focused_monitor=$(hyprctl monitors -j | jq -r '.[] | select(.focused) | .name')
11rofi_theme="$HOME/.config/rofi/config-wallpaper-effect.rasi"
12
13# Directory for swaync
14iDIR="$HOME/.config/swaync/images"
15iDIRi="$HOME/.config/swaync/icons"
16
17# swww transition config
18FPS=60
19TYPE="wipe"
20DURATION=2
21BEZIER=".43,1.19,1,.4"
22SWWW_PARAMS="--transition-fps $FPS --transition-type $TYPE --transition-duration $DURATION --transition-bezier $BEZIER"
23
24# Define ImageMagick effects
25declare -A effects=(
26 ["No Effects"]="no-effects"
27 ["Black & White"]="magick $wallpaper_current -colorspace gray -sigmoidal-contrast 10,40% $wallpaper_output"
28 ["Blurred"]="magick $wallpaper_current -blur 0x10 $wallpaper_output"
29 ["Charcoal"]="magick $wallpaper_current -charcoal 0x5 $wallpaper_output"
30 ["Edge Detect"]="magick $wallpaper_current -edge 1 $wallpaper_output"
31 ["Emboss"]="magick $wallpaper_current -emboss 0x5 $wallpaper_output"
32 ["Frame Raised"]="magick $wallpaper_current +raise 150 $wallpaper_output"
33 ["Frame Sunk"]="magick $wallpaper_current -raise 150 $wallpaper_output"
34 ["Negate"]="magick $wallpaper_current -negate $wallpaper_output"
35 ["Oil Paint"]="magick $wallpaper_current -paint 4 $wallpaper_output"
36 ["Posterize"]="magick $wallpaper_current -posterize 4 $wallpaper_output"
37 ["Polaroid"]="magick $wallpaper_current -polaroid 0 $wallpaper_output"
38 ["Sepia Tone"]="magick $wallpaper_current -sepia-tone 65% $wallpaper_output"
39 ["Solarize"]="magick $wallpaper_current -solarize 80% $wallpaper_output"
40 ["Sharpen"]="magick $wallpaper_current -sharpen 0x5 $wallpaper_output"
41 ["Vignette"]="magick $wallpaper_current -vignette 0x3 $wallpaper_output"
42 ["Vignette-black"]="magick $wallpaper_current -background black -vignette 0x3 $wallpaper_output"
43 ["Zoomed"]="magick $wallpaper_current -gravity Center -extent 1:1 $wallpaper_output"
44)
45
46# Function to apply no effects
47no-effects() {
48 swww img -o "$focused_monitor" "$wallpaper_current" $SWWW_PARAMS &&
49 wait $!
50 wallust run "$wallpaper_current" -s &&
51 wait $!
52 # Refresh rofi, waybar, wallust palettes
53 sleep 2
54 "$SCRIPTSDIR/Refresh.sh"
55
56 notify-send -u low -i "$iDIR/ja.png" "No wallpaper" "effects applied"
57 # copying wallpaper for rofi menu
58 cp "$wallpaper_current" "$wallpaper_output"
59}
60
61# Function to run rofi menu
62main() {
63 # Populate rofi menu options
64 options=("No Effects")
65 for effect in "${!effects[@]}"; do
66 [[ "$effect" != "No Effects" ]] && options+=("$effect")
67 done
68
69 choice=$(printf "%s\n" "${options[@]}" | LC_COLLATE=C sort | rofi -dmenu -i -config $rofi_theme)
70
71 # Process user choice
72 if [[ -n "$choice" ]]; then
73 if [[ "$choice" == "No Effects" ]]; then
74 no-effects
75 elif [[ "${effects[$choice]+exists}" ]]; then
76 # Apply selected effect
77 notify-send -u normal -i "$iDIR/ja.png" "Applying:" "$choice effects"
78 eval "${effects[$choice]}"
79
80 # intial kill process
81 for pid in swaybg mpvpaper; do
82 killall -SIGUSR1 "$pid"
83 done
84
85 sleep 1
86 swww img -o "$focused_monitor" "$wallpaper_output" $SWWW_PARAMS &
87
88 sleep 2
89
90 wallust run "$wallpaper_output" -s &
91 sleep 1
92 # Refresh rofi, waybar, wallust palettes
93 "${SCRIPTSDIR}/Refresh.sh"
94 notify-send -u low -i "$iDIR/ja.png" "$choice" "effects applied"
95 else
96 echo "Effect '$choice' not recognized."
97 fi
98 fi
99}
100
101# Check if rofi is already running and kill it
102if pidof rofi > /dev/null; then
103 pkill rofi
104fi
105
106main
107
108sleep 1
109
110if [[ -n "$choice" ]]; then
111 sddm_sequoia="/usr/share/sddm/themes/sequoia_2"
112 if [ -d "$sddm_sequoia" ]; then
113
114 # Check if yad is running to avoid multiple yad notification
115 if pidof yad > /dev/null; then
116 killall yad
117 fi
118
119 if yad --info --text="Set current wallpaper as SDDM background?\n\nNOTE: This only applies to SEQUOIA SDDM Theme" \
120 --text-align=left \
121 --title="SDDM Background" \
122 --timeout=5 \
123 --timeout-indicator=right \
124 --button="yad-yes:0" \
125 --button="yad-no:1" \
126 ; then
127
128 # Check if terminal exists
129 if ! command -v "$terminal" &>/dev/null; then
130 notify-send -i "$iDIR/ja.png" "Missing $terminal" "Install $terminal to enable setting of wallpaper background"
131 exit 1
132 fi
133
134 # Open terminal and set the wallpaper
135 $terminal -e bash -c "echo 'Enter your password to set wallpaper as SDDM Background'; \
136 sudo cp -r $wallpaper_output '$sddm_sequoia/backgrounds/default' && \
137 notify-send -i '$iDIR/ja.png' 'SDDM' 'Background SET'"
138 fi
139 fi
140fi