aboutsummaryrefslogtreecommitdiff
path: root/util/fbsetbg
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbsetbg')
-rw-r--r--util/fbsetbg278
1 files changed, 278 insertions, 0 deletions
diff --git a/util/fbsetbg b/util/fbsetbg
new file mode 100644
index 0000000..045e172
--- /dev/null
+++ b/util/fbsetbg
@@ -0,0 +1,278 @@
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.7 2003/06/06 02:18:34 rathnor 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='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 #if the $wallpaper path is absolute
120 echo $option > $lastwallpaper
121 case $wallpaper in
122 /*) echo $wallpaper >> $lastwallpaper ;;
123 *) echo $PWD/$wallpaper >> $lastwallpaper ;;
124 esac
125}
126
127debugfbsetbg (){
128 echo
129 echo $debugstory
130 echo
131 exit 0
132}
133
134# Find the default wallpapersetter
135for wpsetter in $wpsetters; do
136 if find_it $wpsetter; then
137 WPSETTER=$wpsetter
138 break
139 fi
140done
141
142standardrant="$WPSETTER sets the 'wrong' wallpaper. Transparant apps like aterm and
143xchat won't work right with it. Consider using wmsetbg (from windowmaker)
144or Esetroot (from Eterm)"
145
146case $WPSETTER in
147 xsri)
148 full='--center-x --center-y --scale-width=100 --scale-width=100'
149 tile='--tile'
150 center='--center-x --center-y'
151 aspect=$full
152 debugstory="This is a RedHat specific app. I can't find docs about it."
153 ;;
154 display)
155 full="`xwininfo -root|grep geom` -window root"
156 tile='-window root'
157 center='-backdrop -window root'
158 aspect=$full
159 debugstory=$standardrant
160 ;;
161 Esetroot)
162 full='-scale'
163 tile=''
164 center='-c'
165 aspect='-fit'
166 debugstory="Esetroot is a nice app. You won't have any problems."
167 ;;
168 wmsetbg)
169 full='-s -S'
170 tile='-t'
171 center='-b black -e'
172 aspect='-b black -a'
173 debugstory="wmsetbg is a nice app. You won't have any problems."
174 ;;
175 xsetbg)
176 tile='-border black'
177 center='-center -border black'
178 aspect='-fullscreen -border black'
179 full=$aspect #broken
180 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
181 ;;
182 xli)
183 tile='-onroot -quiet -border black'
184 center='-center -onroot -quiet -border black'
185 aspect='-fullscreen -onroot -quiet -border black'
186 full=$aspect #broken
187 debugstory='The fillscreen option (-f) is broken, defaults to (-a). $standardrant'
188 ;;
189 qiv)
190 full='--root_s'
191 tile='--root_t'
192 center='--root'
193 aspect='-m --root'
194 debugstory=$standardrant
195 ;;
196 xv)
197 full='-max -smooth -root -quit'
198 tile='-root -quit'
199 center='-rmode 5 -root -quit'
200 aspect='-maxpect -smooth -root -quit'
201 debugstory=$standardrant
202 ;;
203 icewmbg)
204 tile='-s'
205 full=$tile
206 center=$tile
207 aspect=$tile
208 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
209errormessages with aterm. Don't use it unless you have to."
210 ;;
211 '')
212 message "I can't find an app to set the wallpaper with. You can install one in
213many many ways but I will give you some simple advice: install Eterm and
214you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
215recommend you install the package provided by your distro."
216 exit 1
217 ;;
218esac
219
220#Get options.
221getopts ":a:f:c:t:Tdlh-" COMMAND_LINE_ARGUMENT
222case "${COMMAND_LINE_ARGUMENT}" in
223 d) debugfbsetbg
224 exit 0
225 ;;
226 a) option=$aspect
227 wallpaper=$OPTARG
228 ;;
229 f) option=$full
230 wallpaper=$OPTARG
231 ;;
232 c) option=$center
233 wallpaper=$OPTARG
234 ;;
235 t) option=$tile
236 wallpaper=$OPTARG
237 ;;
238 l)
239 if [ -r $lastwallpaper ];then
240 option=`head -n1 $lastwallpaper`
241 wallpaper=`tail -n1 $lastwallpaper`
242 else
243 message 'No previous wallpaper recorded. You have never used fbsetbg before.'
244 fi
245 ;;
246 h) display_help ; exit 0 ;;
247 T) display_tips ; exit 0 ;;
248 -) echo "fbsetbg doesn't recognize -- gnu-longopts."
249 echo 'Use fbsetbg -h for a long help message.'
250 display_usage
251 exit 1
252 ;;
253 *) if [ ! -r "$1" ]; then
254 echo "$1 isn't an existing wallpaper or a valid option." >&2
255 display_usage
256 exit 1
257 fi
258 if [ -z "$1" ];then
259 message 'No wallpaper to set' >&2
260 display_usage
261 exit 1
262 fi
263 ;;
264esac
265
266option=${option:=$full}
267wallpaper=${wallpaper:=$1}
268
269
270if [ ! -r "$wallpaper" ];then
271 message "Can't find wallpaper $wallpaper"
272 exit 1
273fi
274
275$WPSETTER $option "$wallpaper" || message "Something went wrong while setting the wallpaper
276Run '$WPSETTER $option "$wallpaper"' from an xterm to find out what."
277#remember previous wallpaper
278remembercommand