aboutsummaryrefslogtreecommitdiff
path: root/util/fbsetbg
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbsetbg')
-rw-r--r--util/fbsetbg405
1 files changed, 405 insertions, 0 deletions
diff --git a/util/fbsetbg b/util/fbsetbg
new file mode 100644
index 0000000..b31cb6f
--- /dev/null
+++ b/util/fbsetbg
@@ -0,0 +1,405 @@
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.23 2003/11/23 01:19:01 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, 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 wallpapersetter] [-fFcCtTaA /path/to/wallpaper] [-l] [-h] [-i] [-p]
63Use $command -h for a complete help message.
64
65EOF
66}
67
68display_help() {
69 display_usage
70 cat << EOF
71
72Options:
73
74 -f Set fullscreen wallpaper
75 -c Set centered wallpaper
76 -t Set tiled wallpaper
77 -a Set maximized wallpaper, preserving aspect.
78 ( if your bgsetter doesn't support this
79 we fall back to -f )
80
81 -F,-C,-T,-A same as uncapsed but without remembering.
82
83 -h Display this help
84
85 -l Set previous wallpaper
86
87 -i Information about selected wallpaper command
88 -d (deprecated, use -i) Debug info
89 -p Tips
90 -u Use specified wallpapersetter
91
92Files:
93
94 ~/.fluxbox/lastwallpaper In this file the wallpaper you set
95 will be stored, for the -l option:
96Environment variables:
97 wpsetters Wallpapersetters to use.
98 example:
99 wpsetters=feh fbsetbg wallpaper.jpg
100
101 DISPLAY The display you want to set the wallpaper on.
102 example:
103 DISPLAY=:0.0 fbsetbg -l
104
105EOF
106}
107
108display_tips() {
109 cat << EOF
110Common tips to use with $command:
111
1121) To replace all occurrences of bsetbg with $command in a file use this
113 command:
114
115 perl -pi -e 's,([^f]|^)bsetbg,$command,' filename
116
1172) If you want the style to set the wallpaper and you want $command to
118 remember the previous wallpaper put this in your ~/.fluxbox/init
119
120 session.screen0.rootCommand: $command -l
121
1223) Use $command -i to find out what wallpapersetter $command will be
123 used and what I think about it.
124
125EOF
126}
127
128# ugly code for solaris compat.
129case `uname` in
130 Linux|*BSD)
131 find_it() {
132 which $1 > /dev/null 2>&1 && shift && $*
133 }
134 ;;
135 *)
136 find_it() {
137 file=`which $1 2> /dev/null`
138 if [ -x "$file" ]; then
139 if [ $# -gt 1 ]; then
140 shift
141 $*
142 fi
143 return 0
144 else
145 return 1
146 fi
147 }
148 ;;
149esac
150
151message() {
152 # echo if we have terminal output, otherwise
153 # pop up a window
154 if [ -t 1 ]; then
155 echo "$command: $@"
156 else
157 xmessage -center "$command: $@"
158 fi
159}
160
161remembercommand() {
162 grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
163 mv -f ${lastwallpaper}.tmp ${lastwallpaper}
164 # Make dir/../../path/file.jpg work
165 case $wallpaper in
166 # no spaces allowed between the varname and '|'
167 /*) echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
168 *) echo $option'|'$PWD/$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
169 esac
170}
171
172debugfbsetbg() {
173 echo
174 echo $debugstory
175 echo
176 exit 0
177}
178
179if [ $# -eq 0 ]; then
180 message "no options given"
181 display_help
182 exit 1
183fi
184
185
186unset debug
187
188# Parse command-line options
189while [ $# -gt 0 ]; do
190 case "$1" in
191 -u)
192 if find_it "$2"; then
193 wpsetters=$2
194 else
195 message "Couldn't find \"$2\" for wallpapersetter"
196 display_usage
197 exit 1
198 fi
199 shift 2 ;;
200 -d|-i) debug=true
201 break ;;
202 -a) option='$aspect'
203 wallpaper=$2
204 break ;;
205 -f) option='$full'
206 wallpaper=$2
207 break ;;
208 -c) option='$center'
209 wallpaper=$2
210 break ;;
211 -t) option='$tile'
212 wallpaper=$2
213 break ;;
214 -A) option='$aspect'
215 wallpaper=$2
216 remember=false
217 break ;;
218 -F) option='$full'
219 wallpaper=$2
220 remember=false
221 break ;;
222 -C) option='$center'
223 wallpaper=$2
224 remember=false
225 break ;;
226 -T) option='$tile'
227 wallpaper=$2
228 remember=false
229 break ;;
230 -l)
231 if [ -r "$lastwallpaper" ]; then
232 option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1`
233 wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
234 if [ -z "$wallpaper" ]; then
235 message "No previous wallpaper recorded for display ${DISPLAY}"
236 exit 1
237 fi
238 fi
239 remember=false
240 break
241 ;;
242 -p) display_tips ; exit 0 ;;
243 -h) display_help ; exit 0 ;;
244 --)
245 echo "$command doesn't recognize -- gnu-longopts."
246 echo 'Use $command -h for a help message.'
247 display_usage
248 exit 1 ;;
249 -*)
250 echo 1>&2 "$command: unrecognized option "\`"$1'"
251 display_usage
252 exit 1
253 ;;
254 *)
255 if [ ! -r "$1" ]; then
256 echo "$1 isn't an existing wallpaper or a valid option." >&2
257 display_usage
258 exit 1
259 elif [ -z "$1" ]; then
260 message 'No wallpaper to set' >&2
261 display_usage
262 exit 1
263 else
264 wallpaper=$1
265 break
266 fi
267 ;;
268 esac
269done
270
271# Find the default wallpapersetter
272for wpsetter in $wpsetters; do
273 if find_it $wpsetter; then
274 WPSETTER=$wpsetter
275 break
276 fi
277done
278
279standardrant=\
280"$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and
281apps like aterm and xchat won't work right with it. Consider installing
282feh, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use
283them instead."
284
285standardok=\
286"$WPSETTER is a nice wallpapersetter. You won't have any problems."
287
288case $WPSETTER in
289 chbg)
290 full='-once -mode maximize'
291 tile='-once -mode tile'
292 center='-once -mode center'
293 aspect='-once -mode smart -max_grow 100 -max_size 100'
294 debugstory="chbg supports all features but it doesn't report errors. I reported this bug to the chbg developers."
295 ;;
296 xsri)
297 full='--center-x --center-y --scale-width=100 --scale-height=100'
298 tile='--tile'
299 center='--center-x --center-y --color=black'
300 aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black'
301 debugstory=$standardok
302 ;;
303 display)
304 full="`xwininfo -root 2> /dev/null|grep geom` -window root"
305 tile='-window root'
306 center='-backdrop -window root'
307 aspect=$full
308 debugstory=$standardrant
309 ;;
310 Esetroot)
311 full='-scale'
312 tile=''
313 center='-c'
314 aspect='-fit'
315 debugstory=$standardok
316 ;;
317 wmsetbg)
318 full='-s -S'
319 tile='-t'
320 center='-b black -e'
321 aspect='-b black -a'
322 debugstory=$standardok
323 ;;
324 xsetbg)
325 tile='-border black'
326 center='-center -border black'
327 aspect='-fullscreen -border black'
328 full=$aspect #broken
329 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
330 ;;
331 xli)
332 tile='-onroot -quiet -border black'
333 center='-center -onroot -quiet -border black'
334 aspect='-fullscreen -onroot -quiet -border black'
335 full=$aspect #broken
336 debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
337 ;;
338 qiv)
339 full='--root_s'
340 tile='--root_t'
341 center='--root'
342 aspect='-m --root'
343 debugstory=$standardrant
344 ;;
345 xv)
346 full='-max -smooth -root -quit'
347 tile='-root -quit'
348 center='-rmode 5 -root -quit'
349 aspect='-maxpect -smooth -root -quit'
350 debugstory=$standardrant
351 ;;
352 feh)
353 full='--bg-scale'
354 tile='--bg-tile'
355 center='--bg-center'
356 aspect=$full
357 debugstory=$standardok
358 ;;
359 icewmbg)
360 tile='-s'
361 full=$tile
362 center=$tile
363 aspect=$tile
364 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
365errormessages with aterm. Don't use it unless you have to."
366 ;;
367 '')
368 message \
369"I can't find an app to set the wallpaper with. You can install one in
370many many ways but I will give you some simple advice: install Eterm and
371you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
372recommend you install the package provided by your distro."
373 exit 1
374 ;;
375esac
376
377if [ "$debug" = true ];then
378 debugfbsetbg
379 exit 0
380fi
381
382option=${option:='$full'}
383
384if [ ! -r "$wallpaper" ]; then
385 message "Can't find wallpaper $wallpaper"
386 exit 1
387fi
388
389if [ -z "$DISPLAY" ];then
390 message "You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?"
391 exit 1
392fi
393
394
395$WPSETTER `eval echo $option` "$wallpaper"
396if [ $? -ne 0 ]; then
397 message "Something went wrong while setting the wallpaper.
398Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
399 exit 1
400fi
401
402#remember previous wallpaper
403if [ ! "$remember" = false ]; then
404 remembercommand
405fi