aboutsummaryrefslogtreecommitdiff
path: root/util/fbsetbg
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbsetbg')
-rw-r--r--util/fbsetbg333
1 files changed, 333 insertions, 0 deletions
diff --git a/util/fbsetbg b/util/fbsetbg
new file mode 100644
index 0000000..58dfafe
--- /dev/null
+++ b/util/fbsetbg
@@ -0,0 +1,333 @@
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.16 2003/08/26 20:32:27 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# - getopts won't work on all platforms, but the config-file can
38# compensate for that.
39# - various software like grep/sed/perl may be not present or not
40# the version you have. for example grep '\W' only works on gnu-grep.
41# Keep this in mind, use bare basic defaults.
42# - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash.
43# Non portable features like getopts in this script can be achieved in
44# other ways.
45
46
47# The wallpapersetter is selected in this order
48wpsetters='chbg Esetroot wmsetbg display qiv xv xsri xli xsetbg' # broken icewmbg'
49lastwallpaper=${HOME}/.fluxbox/lastwallpaper
50
51
52WHOAMI=`whoami`
53[ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin
54
55
56# Functions
57display_usage() {
58 cat << EOF
59Usage: fbsetbg [ -fFcCtTaA /path/to/wallpaper ] [ -l ] [ -h ] [ -d ] [ -p ]
60EOF
61}
62
63display_help() {
64 display_usage
65 cat << EOF
66
67Options:
68
69 -f Set fullscreen wallpaper
70 -c Set centered wallpaper
71 -t Set tiled wallpaper
72 -a Set maximized wallpaper, preserving aspect.
73 ( if your bgsetter doesn't support this
74 fbsetbg falls back to -f )
75
76 -F,-C,-T,-A same as uncapsed but without remembering.
77
78 -h Display this help
79
80 -l Set previous wallpaper
81
82 -d Debug fbsetbg
83 -p Tips
84
85Files:
86 In this file the wallpaper you set will be stored, for the -l option:
87 ~/.fluxbox/lastwallpaper
88
89EOF
90}
91
92display_tips() {
93 cat << EOF
94
951) To replace all occurrences of bsetbg in a file use this command:
96
97 perl -pi -e 's,([^f]|^)bsetbg,fbsetbg,' filename
98
992) If you want the style to set the wallpaper and you want fbsetbg to
100 remember the previous wallpaper put this in your ~/.fluxbox/init
101
102 session.screen0.rootCommand: fbsetbg -l
103
1043) Use fbsetbg -d to find out what wallpapersetter fbsetbg will use and
105 what he thinks about it.
106
107EOF
108}
109
110# ugly code for solaris compat.
111case `uname` in
112 Linux|*BSD)
113 find_it() {
114 which $1 > /dev/null 2>&1 && shift && $*
115 }
116 ;;
117 *)
118 find_it() {
119 file=`which $1 2> /dev/null`
120 if [ -x "$file" ]; then
121 if [ $# -gt 1 ]; then
122 shift
123 $*
124 fi
125 return 0
126 else
127 return 1
128 fi
129 }
130 ;;
131esac
132
133
134message() {
135 xmessage -center "$@"
136}
137
138remembercommand() {
139 grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
140 mv -f ${lastwallpaper}.tmp ${lastwallpaper}
141 # Make dir/../../path/file.jpg work
142 case $wallpaper in
143 # no spaces allowed between the varname and '|'
144 /*) echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
145 *) echo $option'|'$PWD/$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
146 esac
147}
148
149debugfbsetbg() {
150 echo
151 echo $debugstory
152 echo
153 exit 0
154}
155
156# Find the default wallpapersetter
157for wpsetter in $wpsetters; do
158 if find_it $wpsetter; then
159 WPSETTER=$wpsetter
160 break
161 fi
162done
163
164standardrant=\
165"$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and apps like aterm
166and xchat won't work right with it. Consider using chbg, wmsetbg (from windowmaker)
167or Esetroot (from Eterm)"
168
169standardok=\
170"$WPSETTER is a nice wallpapersetter. You won't have any problems."
171
172case $WPSETTER in
173 chbg)
174 full='-once -mode maximize'
175 tile='-once -mode tile'
176 center='-once -mode center'
177 aspect='-once -mode smart -max_grow 100 -max_size 100'
178 debugstory=$standardok
179 ;;
180 xsri)
181 full='--center-x --center-y --scale-width=100 --scale-height=100'
182 tile='--tile'
183 center='--center-x --center-y'
184 aspect=$full
185 debugstory="This is a RedHat specific app. I can't find docs about it."
186 ;;
187 display)
188 full="`xwininfo -root|grep geom` -window root"
189 tile='-window root'
190 center='-backdrop -window root'
191 aspect=$full
192 debugstory=$standardrant
193 ;;
194 Esetroot)
195 full='-scale'
196 tile=''
197 center='-c'
198 aspect='-fit'
199 debugstory=$standardok
200 ;;
201 wmsetbg)
202 full='-s -S'
203 tile='-t'
204 center='-b black -e'
205 aspect='-b black -a'
206 debugstory=$standardok
207 ;;
208 xsetbg)
209 tile='-border black'
210 center='-center -border black'
211 aspect='-fullscreen -border black'
212 full=$aspect #broken
213 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
214 ;;
215 xli)
216 tile='-onroot -quiet -border black'
217 center='-center -onroot -quiet -border black'
218 aspect='-fullscreen -onroot -quiet -border black'
219 full=$aspect #broken
220 debugstory='The fillscreen option (-f) is broken, defaults to (-a). $standardrant'
221 ;;
222 qiv)
223 full='--root_s'
224 tile='--root_t'
225 center='--root'
226 aspect='-m --root'
227 debugstory=$standardrant
228 ;;
229 xv)
230 full='-max -smooth -root -quit'
231 tile='-root -quit'
232 center='-rmode 5 -root -quit'
233 aspect='-maxpect -smooth -root -quit'
234 debugstory=$standardrant
235 ;;
236 icewmbg)
237 tile='-s'
238 full=$tile
239 center=$tile
240 aspect=$tile
241 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
242errormessages with aterm. Don't use it unless you have to."
243 ;;
244 '')
245 message \
246"I can't find an app to set the wallpaper with. You can install one in
247many many ways but I will give you some simple advice: install Eterm and
248you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
249recommend you install the package provided by your distro."
250 exit 1
251 ;;
252esac
253
254#Get options.
255getopts ":a:f:c:t:A:F:C:T:pdlh-" COMMAND_LINE_ARGUMENT
256case "${COMMAND_LINE_ARGUMENT}" in
257 d) debugfbsetbg
258 exit 0
259 ;;
260 a) option=$aspect
261 wallpaper=$OPTARG
262 ;;
263 f) option=$full
264 wallpaper=$OPTARG
265 ;;
266 c) option=$center
267 wallpaper=$OPTARG
268 ;;
269 t) option=$tile
270 wallpaper=$OPTARG
271 ;;
272 A) option=$aspect
273 wallpaper=$OPTARG
274 remember=false
275 ;;
276 F) option=$full
277 wallpaper=$OPTARG
278 remember=false
279 ;;
280 C) option=$center
281 wallpaper=$OPTARG
282 remember=false
283 ;;
284 T) option=$tile
285 wallpaper=$OPTARG
286 remember=false
287 ;;
288
289 l)
290 if [ -r $lastwallpaper ]; then
291 option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1`
292 wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
293 else
294 message 'No previous wallpaper recorded. You have never used fbsetbg before.'
295 exit 1
296 fi
297 remember=false
298 ;;
299 h) display_help ; exit 0 ;;
300 p) display_tips ; exit 0 ;;
301 -) echo "fbsetbg doesn't recognize -- gnu-longopts."
302 echo 'Use fbsetbg -h for a long help message.'
303 display_usage
304 exit 1
305 ;;
306 *) if [ ! -r "$1" ]; then
307 echo "$1 isn't an existing wallpaper or a valid option." >&2
308 display_usage
309 exit 1
310 fi
311 if [ -z "$1" ]; then
312 message 'No wallpaper to set' >&2
313 display_usage
314 exit 1
315 fi
316 ;;
317esac
318
319option=${option:=$full}
320wallpaper=${wallpaper:=$1}
321
322
323if [ ! -r "$wallpaper" ]; then
324 message "Can't find wallpaper $wallpaper"
325 exit 1
326fi
327
328$WPSETTER $option "$wallpaper" || message "Something went wrong while setting the wallpaper
329Run '$WPSETTER $option "$wallpaper"' from an xterm to find out what."
330#remember previous wallpaper
331[ ! "$remember" = false ] && remembercommand
332# Off course this returns 1 most of the time.
333exit 0