├── README.md
└── blurme
/README.md:
--------------------------------------------------------------------------------
1 | # blurme
2 |
3 |
blurme v1.0 Codename MEH (My Eyes Hurt) is a small script which will blur your feh set background if any window, or rofi is open. Furthermore there are some options, which allow you to change the default behaviour a bit. Read more about the options down below.
4 | Please feel free to fork it, make pull requests and use it in your own projects.
5 | This is my first project i publish. Please be gentle on me :)
6 | How to start
7 | Requirements
8 |
9 | - wmctrl: This script makes use of wmctrl to get the current workspace number and to clarify, whether any window is open. It's essential!
10 | - feh: Furthermore you'll need feh to set your background image(s).
11 | - imagemagick: And last but not least imagemagick is mandatory to blur the images
12 |
13 | Download and ...
14 |
15 | - Place it anywhere you like (e.g. ~/.scripts)
16 | - Make it executable (chmod +x ~/.scripts/blurme)
17 |
18 | How to run it
19 | Manual start
20 | Run it once in a terminal of your choice with ~/.scripts/blurme
21 | Autostart
22 | i3
23 | Add the line "exec --no-startup-id ~/.scripts/blurme &" to your i3 config.
24 | bspwm
25 | Add the line "sh ~/.scripts/blurme &" to ~/.xinitrc
26 | openbox
27 | Add the line "sh ~/.scripts/blurme &" to ~/.config/openbox/autostart
28 | Options
29 | There are several optional arguments provided that may be used. These include:
30 |
31 | - -a: Add another program (process name), which will start the blur effect
32 | - -c: set custom directory for transition images (default: ~/.cache/blurme)
33 | - -d: Set custom directory (default: ~/.local/share/blurme)
34 | - -t: Set custom transition time in sec (default: 0.01)
35 | - -v: Show additional output (verbose)
36 | - -h: Show all these parameters
37 |
38 |
--------------------------------------------------------------------------------
/blurme:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Error Prevention: Multiple Instances ----------------------------------
4 |
5 | if [[ $(pgrep -cl blurme) > 1 ]]; then
6 | echo 'BLURME: Another instance of blurme me is already running.'
7 | echo ' Please kill it with fire (pkill blurme) first, then try running me again.'
8 | exit
9 | fi
10 |
11 |
12 |
13 | # Options ---------------------------------------------------------------
14 |
15 | while getopts :a:c:d:t:vh option; do
16 | case "${option}" in
17 | a) ADDBLUR=${OPTARG};;
18 | c) CACHEDIR=${OPTARG};;
19 | d) WORKINGDIR=${OPTARG};;
20 | t) TIME=${OPTARG};;
21 | v) VERBOSE=true;;
22 | h)
23 | echo '---------------------------------------'
24 | echo 'BLURME v1.0 Codename MEH (My Eyes Hurt)'
25 | echo '---------------------------------------'
26 | echo "Options: '-a' adds one additional program, which will start the blur effect (must be process name!)" 1>&2
27 | echo " '-c' set custom directory for transition images (default: ~/.cache/blurme)" 1>&2
28 | echo " '-d' set custom directory (default: ~/.cache/blurme)" 1>&2
29 | echo " '-t' set custom transition time in sec (default: 0.01)" 1>&2
30 | echo " '-v' set verbose true" 1>&2
31 | exit
32 | ;;
33 | \?)
34 | echo 'BLURME: Invalid option! Please use as shown below:' 1>&2
35 | echo " '-a' adds one additional program, which will start the blur effect (must be process name!)" 1>&2
36 | echo " '-c' set custom directory for transition images (default: ~/.cache/blurme)" 1>&2
37 | echo " '-d' set custom directory (default: ~/.cache/blurme)" 1>&2
38 | echo " '-t' set custom transition time in sec (default: 0.01)" 1>&2
39 | echo " '-v' set verbose true" 1>&2
40 | exit
41 | ;;
42 | :) echo "BLURME: '-$OPTARG' requires an argument" 1>&2; exit;;
43 | esac
44 | done
45 | shift $((OPTIND-1))
46 |
47 | if [ "$VERBOSE" = true ]; then
48 | echo '---------------------------------------'
49 | echo 'BLURME v1.0 Codename MEH (My Eyes Hurt)'
50 | echo '---------------------------------------'
51 | fi
52 |
53 |
54 |
55 | # Variables -------------------------------------------------------------
56 |
57 | # Working directory contains a copy of the original unblured image,
58 | # and its path.
59 | if [ -z "$WORKINGDIR" ]; then WORKINGDIR=/home/$USER/.local/share/blurme; fi
60 | if ! [ -d $WORKINGDIR ]; then mkdir $WORKINGDIR; fi
61 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Workingdir is set to '$WORKINGDIR; fi
62 |
63 | # Cache directory contains all blurry rendered transition images.
64 | if [ -z "$CACHEDIR" ]; then CACHEDIR=/home/$USER/.cache/blurme; fi
65 | if ! [ -d $CACHEDIR ]; then mkdir $CACHEDIR; fi
66 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Cache (contains transition images) is set to '$CACHEDIR; fi
67 |
68 |
69 | # Error Prevention: Blurry startup
70 | #
71 | # Check if background is set to not blurred on start.
72 | # If for some reason the script wasn't terminated correctly,
73 | # the background might be still blurry, and the logic will go crazy.
74 | # This only fix only works when the workingdir and its containing
75 | # copy of the original not blurred background still exist
76 | # after reboot (no temp directory!).
77 | if [[ $(tail -n1 ~/.fehbg | cut -d "'" -f2) = "$CACHEDIR/trans-9" ]]; then
78 | # Reset wallpaper to original one
79 | feh --bg-fill $(cat "$WORKINGDIR/original-bg")
80 | fi
81 |
82 |
83 | if [ -z "$TIME" ]; then TIME=0.01; fi
84 | #echo "Transition time is set to: "$TIME
85 |
86 | CURRWORKSPACE=$(wmctrl -d | grep '*' | cut -d ' ' -f1)
87 | #echo "Current workspace: $CURRWORKSPACE"
88 |
89 | OPENWINDOWS=$(wmctrl -l | cut -d ' ' -f3 | grep $CURRWORKSPACE | wc -l)
90 | #echo "Open windows on workspace$CURRWORKSPACE: $WINDOWS"
91 |
92 | CURRWALLPAPER=$(tail -n1 ~/.fehbg | cut -d "'" -f2)
93 | #echo "Wallpaper path: $CURRWALLPAPER"
94 |
95 | ORIGINAL=$WORKINGDIR/original-bg
96 | echo $CURRWALLPAPER > $ORIGINAL
97 |
98 | COPYBG=$WORKINGDIR/copied-bg
99 | cp $(cat $ORIGINAL) $COPYBG
100 |
101 |
102 |
103 |
104 |
105 |
106 | # Functions -------------------------------------------------------------
107 |
108 | function create_images {
109 |
110 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Create transition images ...'; fi
111 |
112 | local i="0"
113 |
114 | while [ $i -lt "10" ]; do
115 | A=$(echo "($i + 1) * 2.4" | bc -l)
116 | B=$(echo "($i + 1) * 1.2" | bc -l)
117 | convert $COPYBG -blur $A,$B $CACHEDIR/trans-$i
118 | local PERC=$(echo "($i+1) * 10" | bc -l)
119 | if [ "$VERBOSE" = true ]; then echo 'BLURME: '$PERC'%'; fi
120 | i=$[$i+1]
121 | done
122 |
123 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Done!'; fi
124 | }
125 |
126 | function transinit {
127 |
128 | local REF=$CACHEDIR/trans-0
129 | local CMP=/tmp/blurme-trans-0.tmp
130 |
131 | if [ "$VERBOSE" = true ]; then
132 | echo "BLURME: Huh?! Background is not blurred, let's fix that!"
133 | echo 'BLURME: Unblurred original wallpaper is '$(cat $ORIGINAL)
134 | fi
135 |
136 | # is it really necessary to render again
137 | if [ -f $REF ]; then
138 | convert $(cat $ORIGINAL) -blur 2.4,1.2 $CMP
139 | # create new transition images if newly created trans-0 and old trans-0 are not the same
140 | if ! cmp -s $CMP $REF; then
141 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Seems like we have a new wallpaper which needs to be rendered.'; fi
142 | rm $CMP
143 | create_images
144 | else
145 | if [ "$VERBOSE" = true ]; then echo 'BLURME: This background seems familiar. No need to render it again! :)'; fi
146 | rm $CMP
147 | fi
148 | else
149 | # reference file not found inside existing working dir ... better render them, to get things working
150 | if [ "$VERBOSE" = true ]; then echo "BLURME: Could'nt find transition images in cachedir. Will create them on the fly."; fi
151 | create_images
152 | fi
153 | }
154 |
155 | function transition {
156 |
157 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Blur wallpaper ...'; fi
158 |
159 | local j="0"
160 |
161 | while [ $j -lt "10" ]; do
162 | feh --bg-fill $CACHEDIR/trans-$j
163 | local PERC=$(echo "($j+1) * 10" | bc -l)
164 | if [ "$VERBOSE" = true ]; then echo 'BLURME: '$PERC'%'; fi
165 | j=$[$j+1]
166 | sleep $TIME
167 | done
168 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Done!'; fi
169 | }
170 |
171 | function transition_rev {
172 |
173 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Unblur wallpaper ...'; fi
174 |
175 | local j="9"
176 |
177 | while [ $j -ge "0" ]; do
178 | feh --bg-fill $CACHEDIR/trans-$j
179 | local PERC=$(echo "($j+1) * 10" | bc -l)
180 | if [ "$VERBOSE" = true ]; then echo 'BLURME: '$PERC'%'; fi
181 | j=$[$j-1]
182 | sleep $TIME
183 | done
184 |
185 | feh --bg-fill $(cat $ORIGINAL)
186 | if [ "$VERBOSE" = true ]; then echo 'BLURME: Done!'; fi
187 | }
188 |
189 | function finish {
190 | feh --bg-fill $(cat $ORIGINAL)
191 | exit
192 | }
193 |
194 |
195 | # Logic ------------------------------------------------------------------
196 |
197 | trap finish EXIT
198 | trap finish SIGHUP
199 | trap finish SIGINT
200 | trap finish SIGKILL
201 | trap finish SIGTERM
202 |
203 | transinit
204 |
205 | while true; do
206 |
207 | CURRWORKSPACE=$(wmctrl -d | grep '*' | cut -d ' ' -f1)
208 | OPENWINDOWS=$(wmctrl -l | cut -d ' ' -f3 | grep $CURRWORKSPACE | wc -l)
209 | CURRWALLPAPER=$(tail -n1 ~/.fehbg | cut -d "'" -f2)
210 |
211 | # is any window or rofi open on current workspace
212 | if [[ $OPENWINDOWS > 0 ]] || [[ $(pgrep -cl rofi) > 0 ]] || [[ $(pidof $ADDBLUR) > 0 ]]; then
213 | # is wallpaper not blurred
214 | if [ "$CURRWALLPAPER" != "$CACHEDIR/trans-9" ]; then
215 | # has wallpaper been changed
216 | if [ "$CURRWALLPAPER" != "$(cat $ORIGINAL)" ]; then
217 | # save current wallpapers path
218 | echo $CURRWALLPAPER > $ORIGINAL
219 | # copy current wallpaper as reference
220 | cp $(cat $ORIGINAL) $COPYBG
221 | # create transition images
222 | transinit
223 | fi
224 | # set wallpapers to blur
225 | transition
226 | fi
227 | else
228 | # no windows or rofi open and wallpaper is not the unblurred original
229 | if [ "$CURRWALLPAPER" != "$(cat $ORIGINAL)" ]; then
230 | # unblur and set to original wallpaper
231 | transition_rev
232 | fi
233 | fi
234 |
235 | sleep 0.5
236 | done
237 |
--------------------------------------------------------------------------------