3
# Set wallpaper for fluxbox.
5
# Copyright (c) 2003-2004 Han Boetes <han@mijncomputer.nl>
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:
15
# The above copyright notice and this permission notice shall be
16
# included in all copies or substantial portions of the Software.
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.
27
# To guarantee this script works on all platforms that support fluxbox
28
# please keep the following restrictions in mind:
30
# - don't use if ! command;, use command; if [ $? -ne 0 ];
31
# - don't use [ -e file ] use [ -r file ]
32
# - don't use $(), use ``
33
# - don't use ~, use ${HOME}
34
# - don't use id -u or $UID, use whoami
36
# - getopts won't work on all platforms, but the config-file can
37
# compensate for that.
38
# - various software like grep/sed/perl may be not present or not
39
# the version you have. for example grep '\W' only works on gnu-grep.
40
# Keep this in mind, use bare basic defaults.
41
# - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash.
43
# TODO purheps: xprop -root _WIN_WORKSPACE
44
# _NET_CURRENT_DESKTOP
46
# The wallpapersetter is selected in this order
47
wpsetters="${wpsetters:=Esetroot wmsetbg feh hsetroot chbg display qiv xv xsri xli xsetbg}" # broken icewmbg'
48
lastwallpaper="${HOME}/.fluxbox/lastwallpaper"
52
[ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin
54
command="`basename \"$0\"`"
60
Usage: $command [-u/-U [wallpapersetter]] [-fFcCtTaA] /path/to/wallpaper
61
$command [-u/-U [wallpapersetter]] [-fFcCtTaA] -r/-R /path/to/wallpaperdirectory
62
$command [-b/-B fbsetrootoptions]
64
Use \`\`$command -h'' for a complete help message.
75
-f Set fullscreen wallpaper (default).
76
-c Set centered wallpaper.
77
-t Set tiled wallpaper.
78
-a Set maximized wallpaper, preserving aspect.
79
( if your bgsetter doesn't support this
81
-u Use specified wallpapersetter, use no argument to forget.
82
-b Forward the options to fbsetroot.
83
-r set random wallpaper from a directory
85
-F,-C,-T,-A,-U,-B,-R same as uncapsed but without remembering.
89
-l Set previous wallpaper.
91
-i Information about selected wallpaper command.
92
-d (deprecated, use -i) Debug info.
98
~/.fluxbox/lastwallpaper In this file the wallpaper you set
99
will be stored, for the -l option:
100
Environment variables:
101
wpsetters Wallpapersetters to use.
103
wpsetters=feh fbsetbg wallpaper.jpg
105
DISPLAY The display you want to set the wallpaper on.
107
DISPLAY=:0.0 fbsetbg -l
114
Common tips to use with $command:
116
1) To replace all occurrences of bsetbg with $command in a file use this
119
perl -pi -e 's,([^f]|^)bsetbg,$command,' filename
121
2) If you want the style to set the wallpaper and you want $command to
122
remember the previous wallpaper put this in your ~/.fluxbox/init
124
session.screen0.rootCommand: $command -l
126
3) Use $command -i to find out what wallpapersetter $command will be
127
used and what $command thinks about it.
133
[ -n "$1" ] && hash $1 2> /dev/null
138
# This Terminal detection method is inaccurate. Looking for a
141
# echo if we have terminal output, otherwise pop up a window
143
# echo "$command: $@"
145
extra_args="-default okay"
146
if find_it gxmessage; then
147
gxmessage $extra_args -center "$command: $@" &
149
xmessage $extra_args -center "$command: $@" &
155
grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
156
mv -f ${lastwallpaper}.tmp ${lastwallpaper}
157
if [ "$option" = fbsetroot ]; then
158
echo $option"|$wallpaper|$style|"$DISPLAY >> $lastwallpaper
161
# Make dir/../../path/file.jpg work
163
# no spaces allowed between the varname and '|'
164
/*) echo $option $option2"|$wallpaper|$style|"$DISPLAY >> $lastwallpaper ;;
165
*) echo $option $option2"|$PWD/$wallpaper|$style|"$DISPLAY >> $lastwallpaper ;;
172
echo $sad_esetroot_story
179
if [ ! "$remember" = false ]; then
186
if [ $# -eq 0 ]; then
187
message "no options given"
192
# create directory and last wallpaper file
193
if [ ! -d "$HOME/.fluxbox" ]; then
194
mkdir "$HOME/.fluxbox"
195
touch ${lastwallpaper}
198
unset debug setterfromcommandline
199
# Parse command-line options
200
while [ $# -gt 0 ]; do
203
if find_it "$2"; then
204
grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
205
echo "wpsetters $2" >> ${lastwallpaper}.tmp
206
mv ${lastwallpaper}.tmp $lastwallpaper
208
setterfromcommandline=true
209
elif [ -z "$2" ]; then
210
grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
211
mv ${lastwallpaper}.tmp $lastwallpaper
212
message "wpsetter removed from historyfile"
215
message "Couldn't find \"$2\" for wallpapersetter"
221
if find_it "$2"; then
223
setterfromcommandline=true
225
message "Couldn't find \"$2\" for wallpapersetter"
263
wallpaper=$2 # in this case it's a dir
267
wallpaper=$2 # in this case it's a dir
271
if [ -r "$lastwallpaper" ]; then
272
option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1`
273
option2=`echo $option|cut -d' ' -f2`
274
option=`echo $option|cut -d' ' -f1`
275
wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
276
if [ -z "$wallpaper" ]; then
277
option=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f1`
278
option2=`echo $option|cut -d' ' -f2`
279
option=`echo $option|cut -d' ' -f1`
280
wallpaper=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f2`
282
if [ -z "$wallpaper" ]; then
283
message "No previous wallpaper recorded for display ${DISPLAY}"
287
message "No previous wallpaper recorded for display ${DISPLAY}"
293
if [ -r "$lastwallpaper" ]; then
294
option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1`
295
option2=`echo $option|cut -d' ' -f2`
296
option=`echo $option|cut -d' ' -f1`
297
style=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f3`
298
wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
299
if [ -z "$wallpaper" ]; then
300
option=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f1`
301
option2=`echo $option|cut -d' ' -f2`
302
option=`echo $option|cut -d' ' -f1`
303
style=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f3`
304
wallpaper=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f2`
307
if [ "$style" != "style" -a -n "$wallpaper" ]; then
316
-p) display_tips ; exit 0 ;;
317
-h) display_help ; exit 0 ;;
319
message "$command doesn't recognize -- gnu-longopts."
320
message 'Use $command -h for a help message.'
324
message "unrecognized option "\`"$1'"
328
if [ "$option" = random ]; then
330
elif [ ! -r "$1" ]; then
331
message "$1 isn't an existing wallpaper or a valid option."
334
elif [ -z "$1" ]; then
335
message 'No wallpaper to set'
345
if [ "$option" = "fbsetroot" ]; then
349
# Find the default wallpapersetter
350
if [ "$setterfromcommandline" != true ]; then
351
if [ -r "$lastwallpaper" ]; then
352
wpsetters="`awk '/wpsetters/ {print $2}' $lastwallpaper` $wpsetters"
354
for wpsetter in $wpsetters; do
355
if find_it $wpsetter; then
356
if [ ! "$wpsetter" = Esetroot ]; then
359
elif ldd `which Esetroot`|grep libImlib 2>&1 > /dev/null; then
363
sad_esetroot_story="I also found Esetroot, but it doesn't have support for setting wallpapers. You need to install libimlib2 and rebuild Eterm to get it working."
370
"$WPSETTER doesn't set the wallpaper properly. Transparency for fluxbox and
371
apps like aterm and xchat won't work right with it. Consider installing
372
feh, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use
376
"$WPSETTER is a nice wallpapersetter. You won't have any problems."
380
full='-once -mode maximize'
381
tile='-once -mode tile'
382
center='-once -mode center'
383
aspect='-once -mode smart -max_grow 100 -max_size 100'
384
debugstory="chbg supports all features but it doesn't report errors. I reported this bug to the chbg developers."
387
full='--center-x --center-y --scale-width=100 --scale-height=100'
389
center='--center-x --center-y --color=black'
390
aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black'
391
debugstory=$standardok
394
full="`xwininfo -root 2> /dev/null|grep geom` -window root"
396
center='-backdrop -window root'
398
debugstory=$standardrant
405
debugstory=$standardok
411
aspect='-b black -a -S'
412
debugstory=$standardok
416
center='-center -border black'
417
aspect='-fullscreen -border black'
419
debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
422
tile='-onroot -quiet -border black'
423
center='-center -onroot -quiet -border black'
424
aspect='-fullscreen -onroot -quiet -border black'
426
debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
433
debugstory=$standardrant
436
full='-max -smooth -root -quit'
438
center='-rmode 5 -root -quit'
439
aspect='-maxpect -smooth -root -quit'
440
debugstory=$standardrant
447
debugstory=$standardok
454
debugstory=$standardok
461
debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
462
errormessages with aterm. Don't use it unless you have to."
466
"I can't find an app to set the wallpaper with. You can install one in
467
many many ways but I will give you some simple advice: install Eterm and
468
you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
469
recommend you install the package provided by your distro."
474
if [ "$debug" = true ]; then
479
option=${option:='$full'}
480
option2=${option2:='$full'}
483
if [ -z "$DISPLAY" ]; then
484
message "You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?"
489
# random wallpaper code
490
if [ "$option" = random ]; then
491
# Lets make one thing clear...
492
wallpaperdir="$wallpaper"
493
if [ -z "$wallpaperdir" ]; then
494
message "No random wallpaper directory specified."
497
if [ -d "$wallpaperdir" ]; then
498
number_of_wallpapers=`ls "$wallpaperdir"|wc -l`
499
if find_it random_number; then
500
randomnumber=`random_number`
501
# check if the program 'time' is available
502
elif [ "$(command -v time)" ]; then
503
randomnumber=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '`
505
randomnumber="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
507
wallpapernumber=`expr $randomnumber % $number_of_wallpapers + 1`
508
#remember previous wallpaper
509
if [ ! "$remember" = false ]; then
514
wallpaper="$wallpaperdir/`ls \"$wallpaperdir\"|sed -n ${wallpapernumber}p`"
515
option=$option2 # have to choose something...
517
message "Invalid random wallpaper directory specified."
523
if [ ! -r "$wallpaper" ]; then
524
message "Can't find wallpaper $wallpaper"
529
$WPSETTER `eval echo $option` "$wallpaper"
530
if [ $? -ne 0 ]; then
531
message "Something went wrong while setting the wallpaper.
532
Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
537
#remember previous wallpaper
538
if [ ! "$remember" = false ]; then