forked from mut-ex/wallblur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallblur.sh
executable file
·142 lines (110 loc) · 3.31 KB
/
wallblur.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# <Constants>
cache_dir="$HOME/.cache/wallblur"
display_resolution="$(xdpyinfo | awk '/dimensions:/ {printf $2}')"
blur_delay=0
# </Constants>
# <Functions>
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
# Prevent multiple instances
if pidof -x "$(basename "$0")" -o $$ >/dev/null; then
err 'Another instance of wallblur is already running.'
exit 1
fi
gen_blurred_image () {
notify-send "Building wallblur cache for "$base_filename""
clean_cache
wallpaper_resolution=$(identify -format "%wx%h" $wallpaper)
err " Display resolution is: ""$display_resolution"""
err " Wallpaper resolution is: $wallpaper_resolution"
if [ "$wallpaper_resolution" != "$display_resolution" ]; then
err "Scaling wallpaper to match resolution"
convert $wallpaper -resize $display_resolution "$cache_dir"/"$filename"0."$extension"
wallpaper="$cache_dir"/"$filename"0."$extension"
fi
blurred_wallaper=""$cache_dir"/"$filename""5"."$extension""
convert -blur 0x8 $wallpaper $blurred_wallaper
err " > Generating $(basename $blurred_wallaper)"
notify-send "Finished building cache for "$base_filename""
}
do_blur () {
blurred_wallaper=""$cache_dir"/"$filename""5"."$extension""
feh --bg-fill "$blurred_wallaper"
}
do_unblur () {
feh --bg-fill "$wallpaper"
}
check_wallpaper_changed() {
pywallpaper="$(grep wallpaper ~/.cache/wal/colors.sh | awk -F "=" '{print $2}')"
temp_pre=${pywallpaper%\'}
temp_post="${temp_pre#\'}"
pywallpaper=${temp_post##*/}
if [ "$pywallpaper" != "$base_filename" ]
then
err " Wallpaper changed. Going to update cache"
wallpaper="$temp_post"
base_filename=${wallpaper##*/}
extension="${base_filename##*.}"
filename="${base_filename%.*}"
gen_blurred_image
prev_state="reset"
fi
}
clean_cache() {
if [ "$(ls -A "$cache_dir")" ]; then
err " * Cleaning existing cache"
rm -r "$cache_dir"/*
fi
}
# </Functions>
# Get the current wallpaper location from pywal cache
wallpaper="$(grep wallpaper ~/.cache/wal/colors.sh | awk -F "=" '{print $2}')"
temp_pre=${wallpaper%\'}
wallpaper="${temp_pre#\'}"
err "Current wallpaper: $wallpaper"
base_filename=${wallpaper##*/}
extension="${base_filename##*.}"
filename="${base_filename%.*}"
err "Blur delay : $blur_delay"
err "Filename : $base_filename"
err "Extension : $extension"
#err $filename
err "Cache directory : $cache_dir"
# Create a cache directory if it doesn't exist
if [ ! -d "$cache_dir" ]; then
err "* Creating cache directory"
mkdir -p "$cache_dir"
fi
blur_cache=""$cache_dir"/"$filename"0."$extension""
# Generate cached images if no cached images are found
if [ ! -f "$blur_cache" ]
then
gen_blurred_image
fi
prev_state="reset"
while :; do
check_wallpaper_changed
current_workspace="$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}')"
#err $current_workspace
if [[ -n "$current_workspace" ]]; then
num_windows="$(echo "$(wmctrl -l)" | awk -F" " '{print $2}' | grep ^$current_workspace)"
# err $num_windows
# If there are active windows
if [ -n "$num_windows" ]; then
if [ "$prev_state" != "blurred" ]; then
err " ! Blurring"
do_blur
fi
prev_state="blurred"
else #If there are no active windows
if [ "$prev_state" != "unblurred" ]; then
err " ! Un-blurring"
do_unblur
fi
prev_state="unblurred"
fi
fi
sleep "$blur_delay"
done