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