diff options
Diffstat (limited to 'util/fbsetbg')
-rw-r--r-- | util/fbsetbg | 516 |
1 files changed, 516 insertions, 0 deletions
diff --git a/util/fbsetbg b/util/fbsetbg new file mode 100644 index 0000000..2e55ad0 --- /dev/null +++ b/util/fbsetbg | |||
@@ -0,0 +1,516 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # Set wallpaper for fluxbox. | ||
4 | # | ||
5 | # Copyright (c) 2003-2004 Han Boetes <han@mijncomputer.nl> | ||
6 | # | ||
7 | # Permission is hereby granted, free of charge, to any person obtaining | ||
8 | # a copy of this software and associated documentation files (the | ||
9 | # "Software"), to deal in the Software without restriction, including | ||
10 | # without limitation the rights to use, copy, modify, merge, publish, | ||
11 | # distribute, sublicense, and/or sell copies of the Software, and to | ||
12 | # permit persons to whom the Software is furnished to do so, subject to | ||
13 | # the following conditions: | ||
14 | # | ||
15 | # The above copyright notice and this permission notice shall be | ||
16 | # included in all copies or substantial portions of the Software. | ||
17 | # | ||
18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
21 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
22 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
23 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
24 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
25 | # | ||
26 | # $Id: fbsetbg,v 1.30 2004/03/11 00:08:34 rathnor Exp $ | ||
27 | |||
28 | # Portability notes: | ||
29 | # To guarantee this script works on all platforms that support fluxbox | ||
30 | # please keep the following restrictions in mind: | ||
31 | # | ||
32 | # - don't use if ! command;, use command; if [ $? -ne 0 ]; | ||
33 | # - don't use [ -e file ] use [ -r file ] | ||
34 | # - don't use $(), use `` | ||
35 | # - don't use ~, use ${HOME} | ||
36 | # - don't use id -u or $UID, use whoami | ||
37 | # - don't use echo -e | ||
38 | # - getopts won't work on all platforms, but the config-file can | ||
39 | # compensate for that. | ||
40 | # - various software like grep/sed/perl may be not present or not | ||
41 | # the version you have. for example grep '\W' only works on gnu-grep. | ||
42 | # Keep this in mind, use bare basic defaults. | ||
43 | # - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash. | ||
44 | |||
45 | # TODO purheps: xprop -root _WIN_WORKSPACE | ||
46 | # _NET_CURRENT_DESKTOP | ||
47 | |||
48 | # The wallpapersetter is selected in this order | ||
49 | wpsetters=${wpsetters:=Esetroot wmsetbg feh chbg display qiv xv xsri xli xsetbg} # broken icewmbg' | ||
50 | lastwallpaper=${HOME}/.fluxbox/lastwallpaper | ||
51 | |||
52 | |||
53 | WHOAMI=`whoami` | ||
54 | [ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin | ||
55 | |||
56 | command="`basename \"$0\"`" | ||
57 | |||
58 | |||
59 | # Functions | ||
60 | display_usage() { | ||
61 | cat << EOF | ||
62 | Usage: $command [-u/-U [wallpapersetter]] [-fFcCtTaA /path/to/wallpaper] | ||
63 | [-r/-R /path/to/wallpaperdirectory] | ||
64 | [-b/-B bsetrootoptions] [-l] [-h] [-i] [-p] | ||
65 | Use \`\`$command -h'' for a complete help message. | ||
66 | |||
67 | EOF | ||
68 | } | ||
69 | |||
70 | display_help() { | ||
71 | display_usage | ||
72 | cat << EOF | ||
73 | |||
74 | Options: | ||
75 | |||
76 | -f Set fullscreen wallpaper. | ||
77 | -c Set centered wallpaper. | ||
78 | -t Set tiled wallpaper. | ||
79 | -a Set maximized wallpaper, preserving aspect. | ||
80 | ( if your bgsetter doesn't support this | ||
81 | we fall back to -f ) | ||
82 | -u Use specified wallpapersetter, use no argument to forget. | ||
83 | -b Forward the options to bsetroot. | ||
84 | -r set random wallpaper from a directory | ||
85 | |||
86 | -F,-C,-T,-A,-U,-B,-R same as uncapsed but without remembering. | ||
87 | |||
88 | -h Display this help. | ||
89 | |||
90 | -l Set previous wallpaper. | ||
91 | |||
92 | -i Information about selected wallpaper command. | ||
93 | -d (deprecated, use -i) Debug info. | ||
94 | -p Tips. | ||
95 | |||
96 | |||
97 | Files: | ||
98 | |||
99 | ~/.fluxbox/lastwallpaper In this file the wallpaper you set | ||
100 | will be stored, for the -l option: | ||
101 | Environment variables: | ||
102 | wpsetters Wallpapersetters to use. | ||
103 | example: | ||
104 | wpsetters=feh fbsetbg wallpaper.jpg | ||
105 | |||
106 | DISPLAY The display you want to set the wallpaper on. | ||
107 | example: | ||
108 | DISPLAY=:0.0 fbsetbg -l | ||
109 | |||
110 | EOF | ||
111 | } | ||
112 | |||
113 | display_tips() { | ||
114 | cat << EOF | ||
115 | Common tips to use with $command: | ||
116 | |||
117 | 1) To replace all occurrences of bsetbg with $command in a file use this | ||
118 | command: | ||
119 | |||
120 | perl -pi -e 's,([^f]|^)bsetbg,$command,' filename | ||
121 | |||
122 | 2) If you want the style to set the wallpaper and you want $command to | ||
123 | remember the previous wallpaper put this in your ~/.fluxbox/init | ||
124 | |||
125 | session.screen0.rootCommand: $command -l | ||
126 | |||
127 | 3) Use $command -i to find out what wallpapersetter $command will be | ||
128 | used and what $command thinks about it. | ||
129 | |||
130 | EOF | ||
131 | } | ||
132 | |||
133 | # ugly code for solaris compat. | ||
134 | case `uname` in | ||
135 | Linux|*BSD) | ||
136 | find_it() { | ||
137 | which $1 > /dev/null 2>&1 && shift && $* | ||
138 | } | ||
139 | ;; | ||
140 | *) | ||
141 | find_it() { | ||
142 | file=`which $1 2> /dev/null` | ||
143 | if [ -x "$file" ]; then | ||
144 | if [ $# -gt 1 ]; then | ||
145 | shift | ||
146 | $* | ||
147 | fi | ||
148 | return 0 | ||
149 | else | ||
150 | return 1 | ||
151 | fi | ||
152 | } | ||
153 | ;; | ||
154 | esac | ||
155 | |||
156 | message() { | ||
157 | |||
158 | # This Terminal detection method is inaccurate. Looking for a | ||
159 | # replacement. | ||
160 | |||
161 | # echo if we have terminal output, otherwise pop up a window | ||
162 | # if [ -t 1 ]; then | ||
163 | # echo "$command: $@" | ||
164 | # else | ||
165 | if find_it gxmessage; then | ||
166 | gxmessage -center "$command: $@" | ||
167 | else | ||
168 | xmessage -center "$command: $@" | ||
169 | fi | ||
170 | # fi | ||
171 | } | ||
172 | |||
173 | remembercommand() { | ||
174 | grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp | ||
175 | mv -f ${lastwallpaper}.tmp ${lastwallpaper} | ||
176 | if [ "$option" = bsetroot ]; then | ||
177 | echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper | ||
178 | return | ||
179 | fi | ||
180 | # Make dir/../../path/file.jpg work | ||
181 | case $wallpaper in | ||
182 | # no spaces allowed between the varname and '|' | ||
183 | /*) echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper ;; | ||
184 | *) echo $option'|'$PWD/$wallpaper'|'$DISPLAY >> $lastwallpaper ;; | ||
185 | esac | ||
186 | } | ||
187 | |||
188 | debugfbsetbg() { | ||
189 | echo | ||
190 | echo $debugstory | ||
191 | echo $sad_esetroot_story | ||
192 | exit 0 | ||
193 | } | ||
194 | |||
195 | if [ $# -eq 0 ]; then | ||
196 | message "no options given" | ||
197 | display_usage | ||
198 | exit 1 | ||
199 | fi | ||
200 | |||
201 | |||
202 | unset debug setterfromcommandline | ||
203 | # Parse command-line options | ||
204 | while [ $# -gt 0 ]; do | ||
205 | case "$1" in | ||
206 | -u) | ||
207 | if find_it "$2"; then | ||
208 | grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp | ||
209 | echo "wpsetters $2" >> ${lastwallpaper}.tmp | ||
210 | mv ${lastwallpaper}.tmp $lastwallpaper | ||
211 | WPSETTER=$2 | ||
212 | setterfromcommandline=true | ||
213 | elif [ -z "$2" ]; then | ||
214 | grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp | ||
215 | mv ${lastwallpaper}.tmp $lastwallpaper | ||
216 | message "wpsetter removed from historyfile" | ||
217 | exit 0 | ||
218 | else | ||
219 | message "Couldn't find \"$2\" for wallpapersetter" | ||
220 | display_usage | ||
221 | exit 1 | ||
222 | fi | ||
223 | shift 2 ;; | ||
224 | -U) | ||
225 | if find_it "$2"; then | ||
226 | WPSETTER=$2 | ||
227 | setterfromcommandline=true | ||
228 | else | ||
229 | message "Couldn't find \"$2\" for wallpapersetter" | ||
230 | display_usage | ||
231 | exit 1 | ||
232 | fi | ||
233 | shift 2 ;; | ||
234 | -d|-i) debug=true | ||
235 | break ;; | ||
236 | -a) option='$aspect' | ||
237 | wallpaper=$2 | ||
238 | break ;; | ||
239 | -f) option='$full' | ||
240 | wallpaper=$2 | ||
241 | break ;; | ||
242 | -c) option='$center' | ||
243 | wallpaper=$2 | ||
244 | break ;; | ||
245 | -t) option='$tile' | ||
246 | wallpaper=$2 | ||
247 | break ;; | ||
248 | -A) option='$aspect' | ||
249 | wallpaper=$2 | ||
250 | remember=false | ||
251 | break ;; | ||
252 | -F) option='$full' | ||
253 | wallpaper=$2 | ||
254 | remember=false | ||
255 | break ;; | ||
256 | -C) option='$center' | ||
257 | wallpaper=$2 | ||
258 | remember=false | ||
259 | break ;; | ||
260 | -T) option='$tile' | ||
261 | wallpaper=$2 | ||
262 | remember=false | ||
263 | break ;; | ||
264 | -b) option=bsetroot | ||
265 | shift | ||
266 | wallpaper=$* | ||
267 | break ;; | ||
268 | -B) option=bsetroot | ||
269 | shift | ||
270 | wallpaper=$* | ||
271 | remember=false | ||
272 | break ;; | ||
273 | -r) option=random | ||
274 | wallpaper=$2 # in this case it's a dir | ||
275 | break ;; | ||
276 | -R) option=random | ||
277 | wallpaper=$2 # in this case it's a dir | ||
278 | remember=false | ||
279 | break ;; | ||
280 | -l) | ||
281 | if [ -r "$lastwallpaper" ]; then | ||
282 | option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1` | ||
283 | wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2` | ||
284 | if [ -z "$wallpaper" ]; then | ||
285 | message "No previous wallpaper recorded for display ${DISPLAY}" | ||
286 | exit 1 | ||
287 | fi | ||
288 | else | ||
289 | message "No previous wallpaper recorded for display ${DISPLAY}" | ||
290 | exit 1 | ||
291 | fi | ||
292 | remember=false | ||
293 | break ;; | ||
294 | -p) display_tips ; exit 0 ;; | ||
295 | -h) display_help ; exit 0 ;; | ||
296 | --) | ||
297 | message "$command doesn't recognize -- gnu-longopts." | ||
298 | message 'Use $command -h for a help message.' | ||
299 | display_usage | ||
300 | exit 1 ;; | ||
301 | -*) | ||
302 | message "unrecognized option "\`"$1'" | ||
303 | display_usage | ||
304 | exit 1 ;; | ||
305 | *) | ||
306 | if [ "$option" = random ]; then | ||
307 | option='$aspect' | ||
308 | elif [ ! -r "$1" ]; then | ||
309 | message "$1 isn't an existing wallpaper or a valid option." | ||
310 | display_usage | ||
311 | exit 1 | ||
312 | elif [ -z "$1" ]; then | ||
313 | message 'No wallpaper to set' | ||
314 | display_usage | ||
315 | exit 1 | ||
316 | else | ||
317 | wallpaper=$1 | ||
318 | break | ||
319 | fi ;; | ||
320 | esac | ||
321 | done | ||
322 | |||
323 | # Find the default wallpapersetter | ||
324 | if [ "$setterfromcommandline" != true ]; then | ||
325 | if [ -r "$lastwallpaper" ]; then | ||
326 | wpsetters="`awk '/wpsetters/ {print $2}' $lastwallpaper` $wpsetters" | ||
327 | fi | ||
328 | for wpsetter in $wpsetters; do | ||
329 | if find_it $wpsetter; then | ||
330 | if [ ! "$wpsetter" = Esetroot ]; then | ||
331 | WPSETTER=$wpsetter | ||
332 | break | ||
333 | elif ldd `which Esetroot`|grep libImlib 2>&1 > /dev/null; then | ||
334 | WPSETTER=$wpsetter | ||
335 | break | ||
336 | else | ||
337 | sad_esetroot_story="I also found Esetroot, but it doesn't have support for setting wallpapers. You need to install libimlib2 and rebuild Eterm to get it working." | ||
338 | fi | ||
339 | fi | ||
340 | done | ||
341 | fi | ||
342 | |||
343 | standardrant=\ | ||
344 | "$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and | ||
345 | apps like aterm and xchat won't work right with it. Consider installing | ||
346 | feh, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use | ||
347 | them instead." | ||
348 | |||
349 | standardok=\ | ||
350 | "$WPSETTER is a nice wallpapersetter. You won't have any problems." | ||
351 | |||
352 | case $WPSETTER in | ||
353 | chbg) | ||
354 | full='-once -mode maximize' | ||
355 | tile='-once -mode tile' | ||
356 | center='-once -mode center' | ||
357 | aspect='-once -mode smart -max_grow 100 -max_size 100' | ||
358 | debugstory="chbg supports all features but it doesn't report errors. I reported this bug to the chbg developers." | ||
359 | ;; | ||
360 | xsri) | ||
361 | full='--center-x --center-y --scale-width=100 --scale-height=100' | ||
362 | tile='--tile' | ||
363 | center='--center-x --center-y --color=black' | ||
364 | aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black' | ||
365 | debugstory=$standardok | ||
366 | ;; | ||
367 | display) | ||
368 | full="`xwininfo -root 2> /dev/null|grep geom` -window root" | ||
369 | tile='-window root' | ||
370 | center='-backdrop -window root' | ||
371 | aspect=$full | ||
372 | debugstory=$standardrant | ||
373 | ;; | ||
374 | Esetroot) | ||
375 | full='-scale' | ||
376 | tile='' | ||
377 | center='-c' | ||
378 | aspect='-fit' | ||
379 | debugstory=$standardok | ||
380 | ;; | ||
381 | wmsetbg) | ||
382 | full='-s -S' | ||
383 | tile='-t' | ||
384 | center='-b black -e' | ||
385 | aspect='-b black -a' | ||
386 | debugstory=$standardok | ||
387 | ;; | ||
388 | xsetbg) | ||
389 | tile='-border black' | ||
390 | center='-center -border black' | ||
391 | aspect='-fullscreen -border black' | ||
392 | full=$aspect #broken | ||
393 | debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant" | ||
394 | ;; | ||
395 | xli) | ||
396 | tile='-onroot -quiet -border black' | ||
397 | center='-center -onroot -quiet -border black' | ||
398 | aspect='-fullscreen -onroot -quiet -border black' | ||
399 | full=$aspect #broken | ||
400 | debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant" | ||
401 | ;; | ||
402 | qiv) | ||
403 | full='--root_s' | ||
404 | tile='--root_t' | ||
405 | center='--root' | ||
406 | aspect='-m --root' | ||
407 | debugstory=$standardrant | ||
408 | ;; | ||
409 | xv) | ||
410 | full='-max -smooth -root -quit' | ||
411 | tile='-root -quit' | ||
412 | center='-rmode 5 -root -quit' | ||
413 | aspect='-maxpect -smooth -root -quit' | ||
414 | debugstory=$standardrant | ||
415 | ;; | ||
416 | feh) | ||
417 | full='--bg-scale' | ||
418 | tile='--bg-tile' | ||
419 | center='--bg-center' | ||
420 | aspect=$full | ||
421 | debugstory=$standardok | ||
422 | ;; | ||
423 | icewmbg) | ||
424 | tile='-s' | ||
425 | full=$tile | ||
426 | center=$tile | ||
427 | aspect=$tile | ||
428 | debugstory="icewmbg does support transparency, but only tiling. And I noticed odd | ||
429 | errormessages with aterm. Don't use it unless you have to." | ||
430 | ;; | ||
431 | '') | ||
432 | message \ | ||
433 | "I can't find an app to set the wallpaper with. You can install one in | ||
434 | many many ways but I will give you some simple advice: install Eterm and | ||
435 | you're set. Eterm provides Esetroot and thats a great wallpaper setter. I | ||
436 | recommend you install the package provided by your distro." | ||
437 | exit 1 | ||
438 | ;; | ||
439 | esac | ||
440 | |||
441 | if [ "$debug" = true ]; then | ||
442 | debugfbsetbg | ||
443 | exit 0 | ||
444 | fi | ||
445 | |||
446 | option=${option:='$full'} | ||
447 | |||
448 | |||
449 | |||
450 | if [ -z "$DISPLAY" ]; then | ||
451 | message "You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?" | ||
452 | exit 1 | ||
453 | fi | ||
454 | |||
455 | |||
456 | if [ "$option" = bsetroot ]; then | ||
457 | bsetroot $wallpaper | ||
458 | if [ ! "$remember" = false ]; then | ||
459 | remembercommand | ||
460 | fi | ||
461 | exit 0 | ||
462 | fi | ||
463 | |||
464 | |||
465 | # random wallpaper code | ||
466 | if [ "$option" = random ]; then | ||
467 | # Lets make one thing clear... | ||
468 | wallpaperdir=$wallpaper | ||
469 | if [ -z "$wallpaperdir" ]; then | ||
470 | message "No random wallpaper directory specified." | ||
471 | exit 1 | ||
472 | fi | ||
473 | if [ -d "$wallpaperdir" ]; then | ||
474 | number_of_wallpapers=`ls $wallpaperdir|wc -l` | ||
475 | if find_it random_number; then | ||
476 | randomnumber=$(random_number) | ||
477 | # some shells don't support $RANDOM | ||
478 | elif [ -z $RANDOM ]; then | ||
479 | randomnumber=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '` | ||
480 | else | ||
481 | randomnumber=$RANDOM | ||
482 | fi | ||
483 | wallpapernumber=`expr $randomnumber % $number_of_wallpapers + 1` | ||
484 | #remember previous wallpaper | ||
485 | if [ ! "$remember" = false ]; then | ||
486 | remembercommand | ||
487 | fi | ||
488 | remember=false | ||
489 | #set -x | ||
490 | wallpaper="$wallpaperdir/`ls $wallpaperdir|sed -n ${wallpapernumber}p`" | ||
491 | option='$aspect' # have to choose something... | ||
492 | else | ||
493 | message "Invalid random wallpaper directory specified." | ||
494 | exit 1 | ||
495 | fi | ||
496 | fi | ||
497 | |||
498 | |||
499 | if [ ! -r "$wallpaper" ]; then | ||
500 | message "Can't find wallpaper $wallpaper" | ||
501 | exit 1 | ||
502 | fi | ||
503 | |||
504 | |||
505 | $WPSETTER `eval echo $option` "$wallpaper" | ||
506 | if [ $? -ne 0 ]; then | ||
507 | message "Something went wrong while setting the wallpaper. | ||
508 | Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what." | ||
509 | exit 1 | ||
510 | fi | ||
511 | |||
512 | |||
513 | #remember previous wallpaper | ||
514 | if [ ! "$remember" = false ]; then | ||
515 | remembercommand | ||
516 | fi | ||