diff options
Diffstat (limited to 'util/fbsetbg')
-rw-r--r-- | util/fbsetbg | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/util/fbsetbg b/util/fbsetbg new file mode 100644 index 0000000..09bcc77 --- /dev/null +++ b/util/fbsetbg | |||
@@ -0,0 +1,270 @@ | |||
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.4 2003/04/29 13:50:05 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 | wpsetters='Esetroot wmsetbg display qiv xv xsri xli xsetbg' | ||
42 | lastwallpaper=${HOME}/.fluxbox/lastwallpaper | ||
43 | |||
44 | |||
45 | WHOAMI=`whoami` | ||
46 | [ "$WHOAMI" = "root" ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin | ||
47 | |||
48 | |||
49 | # Functions | ||
50 | display_usage() { | ||
51 | cat <<EOF | ||
52 | Usage: fbsetbg [ -fcta /path/to/wallpaper ] [ -l ] [ -h ] [ -d ] | ||
53 | EOF | ||
54 | } | ||
55 | |||
56 | display_help() { | ||
57 | display_usage | ||
58 | cat <<EOF | ||
59 | |||
60 | Options: | ||
61 | |||
62 | -f Set fullscreen wallpaper | ||
63 | -c Set centered wallpaper | ||
64 | -t Set tiled wallpaper | ||
65 | -a Set maximized wallpaper, preserving aspect. | ||
66 | ( if your bgsetter doesn't support this | ||
67 | fbsetbg falls back to -f ) | ||
68 | |||
69 | -h Display this help | ||
70 | |||
71 | -l Set previous wallpaper | ||
72 | |||
73 | -d Debug fbsetbg | ||
74 | -T Tips | ||
75 | |||
76 | Files: | ||
77 | |||
78 | ~/.fluxbox/lastwallpaper | ||
79 | |||
80 | EOF | ||
81 | } | ||
82 | |||
83 | display_tips(){ | ||
84 | cat<<EOF | ||
85 | |||
86 | To replace all occurrences of bsetbg in a file use this command: | ||
87 | |||
88 | perl -pi -e 's,([^f]|^)bsetbg,fbsetbg,' | ||
89 | |||
90 | If you want the style to set the wallpaper and you want fbsetbg to | ||
91 | remember the previous wallpaper put this in your ~/.fluxbox/init | ||
92 | |||
93 | session.screen0.rootCommand: fbsetbg -l | ||
94 | |||
95 | |||
96 | EOF | ||
97 | } | ||
98 | |||
99 | # ugly code for solaris compat. | ||
100 | find_it() { | ||
101 | file=`which $1 2> /dev/null` | ||
102 | if [ -x "$file" ]; then | ||
103 | if [ $# -gt 1 ]; then | ||
104 | shift | ||
105 | $* | ||
106 | fi | ||
107 | return 0 | ||
108 | else | ||
109 | return 1 | ||
110 | fi | ||
111 | } | ||
112 | |||
113 | message() { | ||
114 | xmessage -center "$@" | ||
115 | } | ||
116 | |||
117 | remembercommand() { | ||
118 | #if the $wallpaper path is absolute | ||
119 | echo $option > $lastwallpaper | ||
120 | case $wallpaper in | ||
121 | /*) echo $wallpaper >> $lastwallpaper ;; | ||
122 | *) echo $PWD/$wallpaper >> $lastwallpaper ;; | ||
123 | esac | ||
124 | } | ||
125 | |||
126 | debugfbsetbg (){ | ||
127 | echo | ||
128 | echo $debugstory | ||
129 | echo | ||
130 | exit 0 | ||
131 | } | ||
132 | |||
133 | # Find the default wallpapersetter | ||
134 | # The precise order is up for debate. | ||
135 | for wpsetter in $wpsetters; do | ||
136 | if find_it $wpsetter; then | ||
137 | WPSETTER=$wpsetter | ||
138 | break | ||
139 | fi | ||
140 | done | ||
141 | |||
142 | standardrant="$WPSETTER sets the 'wrong' wallpaper. Transparant apps like aterm and | ||
143 | xchat won't work right with it. Consider using wmsetbg (from windowmaker) | ||
144 | or Esetroot (from Eterm)" | ||
145 | |||
146 | case $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 | '') | ||
204 | message "I can't find an app to set the wallpaper with. You can install one in | ||
205 | many many ways but I will give you some simple advice: install Eterm and | ||
206 | you're set. Eterm provides Esetroot and thats a great wallpaper setter. I | ||
207 | recommend you install the package provided by your distro." | ||
208 | exit 1 | ||
209 | ;; | ||
210 | esac | ||
211 | |||
212 | #Get options. | ||
213 | getopts ":a:f:c:t:Tdlh-" COMMAND_LINE_ARGUMENT | ||
214 | case "${COMMAND_LINE_ARGUMENT}" in | ||
215 | d) debugfbsetbg | ||
216 | exit 0 | ||
217 | ;; | ||
218 | a) option=$aspect | ||
219 | wallpaper=$OPTARG | ||
220 | ;; | ||
221 | f) option=$full | ||
222 | wallpaper=$OPTARG | ||
223 | ;; | ||
224 | c) option=$center | ||
225 | wallpaper=$OPTARG | ||
226 | ;; | ||
227 | t) option=$tile | ||
228 | wallpaper=$OPTARG | ||
229 | ;; | ||
230 | l) | ||
231 | if [ -r $lastwallpaper ];then | ||
232 | option=`head -n1 $lastwallpaper` | ||
233 | wallpaper=`tail -n1 $lastwallpaper` | ||
234 | else | ||
235 | message 'No previous wallpaper recorded.' | ||
236 | fi | ||
237 | ;; | ||
238 | h) display_help ; exit 0 ;; | ||
239 | T) display_tips ; exit 0 ;; | ||
240 | -) echo "fbsetbg doesn't recognize -- gnu-longopts." | ||
241 | echo 'Use fbsetbg -h for a long help message.' | ||
242 | display_usage | ||
243 | exit 1 | ||
244 | ;; | ||
245 | *) if [ ! -r "$1" ]; then | ||
246 | echo "$1 isn't an existing wallpaper or a valid option." >&2 | ||
247 | display_usage | ||
248 | exit 1 | ||
249 | fi | ||
250 | if [ -z "$1" ];then | ||
251 | message 'No wallpaper to set' >&2 | ||
252 | display_usage | ||
253 | exit 1 | ||
254 | fi | ||
255 | ;; | ||
256 | esac | ||
257 | |||
258 | option=${option:=$full} | ||
259 | wallpaper=${wallpaper:=$1} | ||
260 | |||
261 | |||
262 | if [ ! -r "$wallpaper" ];then | ||
263 | message "Can't find wallpaper $wallpaper" | ||
264 | exit 1 | ||
265 | fi | ||
266 | |||
267 | $WPSETTER $option "$wallpaper" || message "Something went wrong while setting the wallpaper | ||
268 | Run '$WPSETTER $option "$wallpaper"' from an xterm to find out what." | ||
269 | #remember previous wallpaper | ||
270 | remembercommand | ||