aboutsummaryrefslogtreecommitdiff
path: root/util/fbsetbg
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbsetbg')
-rw-r--r--util/fbsetbg497
1 files changed, 497 insertions, 0 deletions
diff --git a/util/fbsetbg b/util/fbsetbg
new file mode 100644
index 0000000..b3f62f2
--- /dev/null
+++ b/util/fbsetbg
@@ -0,0 +1,497 @@
1#!/bin/sh
2#
3# Set wallpaper for fluxbox.
4#
5# Copyright (c) 2003 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.27 2004/01/03 01:23:59 fluxgen 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, 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
49wpsetters=${wpsetters:=Esetroot wmsetbg feh chbg display qiv xv xsri xli xsetbg} # broken icewmbg'
50lastwallpaper=${HOME}/.fluxbox/lastwallpaper
51
52
53WHOAMI=`whoami`
54[ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin
55
56command="`basename \"$0\"`"
57
58
59# Functions
60display_usage() {
61 cat << EOF
62Usage: $command [-u/-U [wallpapersetter]] [-fFcCtTaA /path/to/wallpaper]
63 [-r/-R /path/to/wallpaperdirectory]
64 [-b/-B bsetrootoptions] [-l] [-h] [-i] [-p]
65Use \`\`$command -h'' for a complete help message.
66
67EOF
68}
69
70display_help() {
71 display_usage
72 cat << EOF
73
74Options:
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
97Files:
98
99 ~/.fluxbox/lastwallpaper In this file the wallpaper you set
100 will be stored, for the -l option:
101Environment 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
110EOF
111}
112
113display_tips() {
114 cat << EOF
115Common tips to use with $command:
116
1171) 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
1222) 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
1273) Use $command -i to find out what wallpapersetter $command will be
128 used and what $command thinks about it.
129
130EOF
131}
132
133# ugly code for solaris compat.
134case `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 ;;
154esac
155
156message() {
157 # echo if we have terminal output, otherwise
158 # pop up a window
159 if [ -t 1 ]; then
160 echo "$command: $@"
161 else
162 xmessage -center "$command: $@"
163 fi
164}
165
166remembercommand() {
167 grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
168 mv -f ${lastwallpaper}.tmp ${lastwallpaper}
169 if [ "$option" = bsetroot ]; then
170 echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper
171 return
172 fi
173 # Make dir/../../path/file.jpg work
174 case $wallpaper in
175 # no spaces allowed between the varname and '|'
176 /*) echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
177 *) echo $option'|'$PWD/$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
178 esac
179}
180
181debugfbsetbg() {
182 echo
183 echo $debugstory
184 echo
185 exit 0
186}
187
188if [ $# -eq 0 ]; then
189 message "no options given"
190 display_usage
191 exit 1
192fi
193
194
195unset debug setterfromcommandline
196# Parse command-line options
197while [ $# -gt 0 ]; do
198 case "$1" in
199 -u)
200 if find_it "$2"; then
201 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
202 echo "wpsetters $2" >> ${lastwallpaper}.tmp
203 mv ${lastwallpaper}.tmp $lastwallpaper
204 WPSETTER=$2
205 setterfromcommandline=true
206 elif [ -z "$2" ]; then
207 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
208 mv ${lastwallpaper}.tmp $lastwallpaper
209 message "wpsetter removed from historyfile"
210 exit 0
211 else
212 message "Couldn't find \"$2\" for wallpapersetter"
213 display_usage
214 exit 1
215 fi
216 shift 2 ;;
217 -U)
218 if find_it "$2"; then
219 WPSETTER=$2
220 setterfromcommandline=true
221 else
222 message "Couldn't find \"$2\" for wallpapersetter"
223 display_usage
224 exit 1
225 fi
226 shift 2 ;;
227 -d|-i) debug=true
228 break ;;
229 -a) option='$aspect'
230 wallpaper=$2
231 break ;;
232 -f) option='$full'
233 wallpaper=$2
234 break ;;
235 -c) option='$center'
236 wallpaper=$2
237 break ;;
238 -t) option='$tile'
239 wallpaper=$2
240 break ;;
241 -A) option='$aspect'
242 wallpaper=$2
243 remember=false
244 break ;;
245 -F) option='$full'
246 wallpaper=$2
247 remember=false
248 break ;;
249 -C) option='$center'
250 wallpaper=$2
251 remember=false
252 break ;;
253 -T) option='$tile'
254 wallpaper=$2
255 remember=false
256 break ;;
257 -b) option=bsetroot
258 shift
259 wallpaper=$*
260 break ;;
261 -B) option=bsetroot
262 shift
263 wallpaper=$*
264 remember=false
265 break ;;
266 -r) option=random
267 wallpaper=$2 # in this case it's a dir
268 break ;;
269 -R) option=random
270 wallpaper=$2 # in this case it's a dir
271 remember=false
272 break ;;
273 -l)
274 if [ -r "$lastwallpaper" ]; then
275 option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1`
276 wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
277 if [ -z "$wallpaper" ]; then
278 message "No previous wallpaper recorded for display ${DISPLAY}"
279 exit 1
280 fi
281 fi
282 remember=false
283 break ;;
284 -p) display_tips ; exit 0 ;;
285 -h) display_help ; exit 0 ;;
286 --)
287 message "$command doesn't recognize -- gnu-longopts."
288 message 'Use $command -h for a help message.'
289 display_usage
290 exit 1 ;;
291 -*)
292 message "unrecognized option "\`"$1'"
293 display_usage
294 exit 1 ;;
295 *)
296 if [ "$option" = random ]; then
297 option='$aspect'
298 elif [ ! -r "$1" ]; then
299 message "$1 isn't an existing wallpaper or a valid option."
300 display_usage
301 exit 1
302 elif [ -z "$1" ]; then
303 message 'No wallpaper to set'
304 display_usage
305 exit 1
306 else
307 wallpaper=$1
308 break
309 fi ;;
310 esac
311done
312
313# Find the default wallpapersetter
314if [ "$setterfromcommandline" != true ]; then
315 wpsetters="`awk '/wpsetters/ {print $2}' $lastwallpaper` $wpsetters"
316 for wpsetter in $wpsetters; do
317 if find_it $wpsetter; then
318 WPSETTER=$wpsetter
319 break
320 fi
321 done
322fi
323
324standardrant=\
325"$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and
326apps like aterm and xchat won't work right with it. Consider installing
327feh, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use
328them instead."
329
330standardok=\
331"$WPSETTER is a nice wallpapersetter. You won't have any problems."
332
333case $WPSETTER in
334 chbg)
335 full='-once -mode maximize'
336 tile='-once -mode tile'
337 center='-once -mode center'
338 aspect='-once -mode smart -max_grow 100 -max_size 100'
339 debugstory="chbg supports all features but it doesn't report errors. I reported this bug to the chbg developers."
340 ;;
341 xsri)
342 full='--center-x --center-y --scale-width=100 --scale-height=100'
343 tile='--tile'
344 center='--center-x --center-y --color=black'
345 aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black'
346 debugstory=$standardok
347 ;;
348 display)
349 full="`xwininfo -root 2> /dev/null|grep geom` -window root"
350 tile='-window root'
351 center='-backdrop -window root'
352 aspect=$full
353 debugstory=$standardrant
354 ;;
355 Esetroot)
356 full='-scale'
357 tile=''
358 center='-c'
359 aspect='-fit'
360 debugstory=$standardok
361 ;;
362 wmsetbg)
363 full='-s -S'
364 tile='-t'
365 center='-b black -e'
366 aspect='-b black -a'
367 debugstory=$standardok
368 ;;
369 xsetbg)
370 tile='-border black'
371 center='-center -border black'
372 aspect='-fullscreen -border black'
373 full=$aspect #broken
374 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
375 ;;
376 xli)
377 tile='-onroot -quiet -border black'
378 center='-center -onroot -quiet -border black'
379 aspect='-fullscreen -onroot -quiet -border black'
380 full=$aspect #broken
381 debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
382 ;;
383 qiv)
384 full='--root_s'
385 tile='--root_t'
386 center='--root'
387 aspect='-m --root'
388 debugstory=$standardrant
389 ;;
390 xv)
391 full='-max -smooth -root -quit'
392 tile='-root -quit'
393 center='-rmode 5 -root -quit'
394 aspect='-maxpect -smooth -root -quit'
395 debugstory=$standardrant
396 ;;
397 feh)
398 full='--bg-scale'
399 tile='--bg-tile'
400 center='--bg-center'
401 aspect=$full
402 debugstory=$standardok
403 ;;
404 icewmbg)
405 tile='-s'
406 full=$tile
407 center=$tile
408 aspect=$tile
409 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
410errormessages with aterm. Don't use it unless you have to."
411 ;;
412 '')
413 message \
414"I can't find an app to set the wallpaper with. You can install one in
415many many ways but I will give you some simple advice: install Eterm and
416you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
417recommend you install the package provided by your distro."
418 exit 1
419 ;;
420esac
421
422if [ "$debug" = true ]; then
423 debugfbsetbg
424 exit 0
425fi
426
427option=${option:='$full'}
428
429
430
431if [ -z "$DISPLAY" ]; then
432 message "You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?"
433 exit 1
434fi
435
436
437if [ "$option" = bsetroot ]; then
438 bsetroot $wallpaper
439 if [ ! "$remember" = false ]; then
440 remembercommand
441 fi
442 exit 0
443fi
444
445
446# random wallpaper code
447if [ "$option" = random ]; then
448 # Lets make one thing clear...
449 wallpaperdir=$wallpaper
450 if [ -z "$wallpaperdir" ]; then
451 message "No random wallpaper directory specified."
452 exit 1
453 fi
454 if [ -d "$wallpaperdir" ]; then
455 number_of_wallpapers=`ls $wallpaperdir|wc -l`
456 if find_it random_number; then
457 randomnumber=$(random_number)
458 # some shells don't support $RANDOM
459 elif [ -z $RANDOM ]; then
460 randomnumber=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '`
461 else
462 randomnumber=$RANDOM
463 fi
464 wallpapernumber=`expr $randomnumber % $number_of_wallpapers + 1`
465 #remember previous wallpaper
466 if [ ! "$remember" = false ]; then
467 remembercommand
468 fi
469 remember=false
470 #set -x
471 wallpaper="$wallpaperdir/`ls $wallpaperdir|sed -n ${wallpapernumber}p`"
472 option='$aspect' # have to choose something...
473 else
474 message "Invalid random wallpaper directory specified."
475 exit 1
476 fi
477fi
478
479
480if [ ! -r "$wallpaper" ]; then
481 message "Can't find wallpaper $wallpaper"
482 exit 1
483fi
484
485
486$WPSETTER `eval echo $option` "$wallpaper"
487if [ $? -ne 0 ]; then
488 message "Something went wrong while setting the wallpaper.
489Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
490 exit 1
491fi
492
493
494#remember previous wallpaper
495if [ ! "$remember" = false ]; then
496 remembercommand
497fi