3 # Set wallpaper for awesome.
4 # Copyright (c) 2008 Julien Danjou <julien@danjou.info>
6 # Derived from fbsetbg:
7 # Copyright (c) 2003-2004 Han Boetes <han@mijncomputer.nl>
9 # Permission is hereby granted, free of charge, to any person obtaining
10 # a copy of this software and associated documentation files (the
11 # "Software"), to deal in the Software without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Software, and to
14 # permit persons to whom the Software is furnished to do so, subject to
15 # the following conditions:
17 # The above copyright notice and this permission notice shall be
18 # included in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 # To guarantee this script works on all platforms that support awesome
30 # please keep the following restrictions in mind:
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 or $UID, use whoami
38 # - getopts won't work on all platforms, but the config-file can
39 # compensate for that.
40 # - various software like grep/sed/perl may be not present or not
41 # the version you have. for example grep '\W' only works on gnu-grep.
42 # Keep this in mind, use bare basic defaults.
43 # - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash.
45 # TODO purheps: xprop -root _WIN_WORKSPACE
46 # _NET_CURRENT_DESKTOP
48 if [ -z "$XDG_CACHE_HOME" ]
50 CONFIG_DIR
="${HOME}/.cache/awesome"
52 CONFIG_DIR
="${XDG_CACHE_HOME}/awesome"
55 # The wallpapersetter is selected in this order
56 wpsetters
="${wpsetters:=Esetroot habak feh hsetroot chbg fvwm-root display qiv xv xsri xli xsetbg wmsetbg xsetroot}" # broken icewmbg'
57 lastwallpaper
="${CONFIG_DIR}/lastwallpaper"
61 [ "$WHOAMI" = root
] && PATH
=/bin
:/usr
/bin
/:/usr
/local
/bin
:/usr
/X11R
6/bin
63 command="`basename \"$0\"`"
69 Usage: $command [-u/-U [wallpapersetter]] [-fFcCtTaA] [-m #] /path/to/wallpaper
70 $command [-u/-U [wallpapersetter]] [-fFcCtTaA] [-m #] -r/-R /path/to/wallpaperdirectory
72 Use \`\`$command -h'' for a complete help message.
83 -f Set fullscreen wallpaper (default).
84 -c Set centered wallpaper.
85 -t Set tiled wallpaper.
86 -a Set maximized wallpaper, preserving aspect.
87 ( if your bgsetter doesn't support this
89 -u Use specified wallpapersetter, use no argument to forget.
90 -r set random wallpaper from a directory
92 -F,-C,-T,-A,-U,-R same as lowercase but without remembering.
96 -l Set previous wallpaper.
98 -i Information about selected wallpaper command.
100 -m # Use montage to create a big image (image should
101 fit screen size). Requires montage(1).
102 # is the number of screen (columns in montage)
105 \$XDG_CACHE_HOME/awesome/lastwallpaper In this file the wallpaper you set
106 will be stored, for the -l option.
107 Environment variables:
108 wpsetters Wallpapersetters to use.
110 wpsetters=feh awsetbg wallpaper.jpg
112 DISPLAY The display you want to set the wallpaper on.
114 DISPLAY=:0.0 awsetbg -l
120 [ -n "$1" ] && which $1 1>/dev
/null
2>&1
124 extra_args
="-default okay"
125 if find_it gxmessage
; then
126 gxmessage
$extra_args -center "$command: $@" &
128 xmessage
$extra_args -center "$command: $@" &
133 grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
134 mv -f ${lastwallpaper}.tmp ${lastwallpaper}
135 # Make dir/../../path/file.jpg work
137 # no spaces allowed between the varname and '|'
138 /*) echo $option $option2"|
$wallpaper|
$style|
"$DISPLAY >> $lastwallpaper ;;
139 *) echo $option $option2"|
$PWD/$wallpaper|
$style|
"$DISPLAY >> $lastwallpaper ;;
146 echo $sad_esetroot_story
147 echo $sad_display_story
151 if [ $# -eq 0 ]; then
152 message "no options given
"
157 # create directory and last wallpaper file
158 if [ ! -d "${CONFIG_DIR}" ]; then
159 mkdir -p "${CONFIG_DIR}"
160 touch ${lastwallpaper}
163 unset debug setterfromcommandline
164 # Parse command-line options
165 while [ $# -gt 0 ]; do
168 if find_it "$2"; then
169 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
170 echo "wpsetters
$2" >> ${lastwallpaper}.tmp
171 mv ${lastwallpaper}.tmp $lastwallpaper
173 setterfromcommandline=true
174 elif [ -z "$2" ]; then
175 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
176 mv ${lastwallpaper}.tmp $lastwallpaper
177 message "wpsetter removed from historyfile
"
180 message "Couldn
't find \"$2\" for wallpapersetter"
186 if find_it "$2"; then
188 setterfromcommandline=true
190 message "Couldn't
find \"$2\" for wallpapersetter
"
218 montage=`which montage`
219 if test ! -z "$montage"; then
223 for i in `seq $cols`; do
227 $montage $fns -geometry +0+0 -tile ${cols}x $CONFIG_DIR/montage.png
228 wallpaper=$CONFIG_DIR/montage.png
231 echo "montage not found. Falling back to single image
"
236 wallpaper=$2 # in this case it's a dir
240 wallpaper=$2 # in this case it's a dir
244 if [ -r "$lastwallpaper" ]; then
245 option=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f1`
246 option2=`echo $option|cut -d' ' -f2`
247 option=`echo $option|cut -d' ' -f1`
248 wallpaper=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f2`
249 if [ -z "$wallpaper" ]; then
250 option=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f1`
251 option2=`echo $option|cut -d' ' -f2`
252 option=`echo $option|cut -d' ' -f1`
253 wallpaper=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f2`
255 if [ -z "$wallpaper" ]; then
256 message "No previous wallpaper recorded
for display
${DISPLAY}"
260 message "No previous wallpaper recorded
for display
${DISPLAY}"
266 if [ -r "$lastwallpaper" ]; then
267 option=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f1`
268 option2=`echo $option|cut -d' ' -f2`
269 option=`echo $option|cut -d' ' -f1`
270 style=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f3`
271 wallpaper=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f2`
272 if [ -z "$wallpaper" ]; then
273 option=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f1`
274 option2=`echo $option|cut -d' ' -f2`
275 option=`echo $option|cut -d' ' -f1`
276 style=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f3`
277 wallpaper=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f2`
280 if [ "$style" != "style
" -a -n "$wallpaper" ]; then
289 -h) display_help ; exit 0 ;;
291 message "$command doesn
't recognize -- gnu-longopts."
292 message 'Use
$command -h for a
help message.
'
296 message "unrecognized option "\`"$1'"
300 if [ "$option" = random ]; then
302 elif [ ! -r "$1" ]; then
303 message "$1 isn
't an existing wallpaper or a valid option."
306 elif [ -z "$1" ]; then
307 message 'No wallpaper to
set'
317 # Find the default wallpapersetter
318 if [ "$setterfromcommandline" != true ]; then
319 if [ -r "$lastwallpaper" ]; then
320 wpsetters="`awk '/wpsetters
/ {print
$2}' $lastwallpaper` $wpsetters"
322 for wpsetter in $wpsetters; do
323 if find_it $wpsetter; then
326 if ldd `which Esetroot`|grep libImlib 2>&1 > /dev/null; then
330 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.
"
334 if find_it xwininfo; then
338 sad_display_story="I also found display
, but I need xwininfo
for querying the root window geometry.
"
349 "$WPSETTER doesn
't set the wallpaper properly. Transparency for
350 awesome and apps like aterm and xchat won't work right with
351 it. Consider installing feh
, Esetroot
352 (from Eterm
) or fvwm-root
(from FVWM
) and I
'll use them instead."
355 "$WPSETTER is a nice wallpapersetter. You won't have any problems.
"
359 full='-once -mode maximize'
360 tile='-once -mode tile'
361 center='-once -mode center'
362 aspect='-once -mode smart -max_grow 100 -max_size 100'
363 debugstory="chbg supports all features but it doesn
't report errors. I reported this bug to the chbg developers."
366 full='--center-x --center-y --scale-width=100 --scale-height=100'
368 center='--center-x --center-y --color=black
'
369 aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black
'
370 debugstory=$standardok
373 full="-sample `xwininfo -root 2> /dev/null|awk '/geom
/{print
$2}'` -window root"
375 center='-backdrop -window root
'
376 aspect="`xwininfo -root 2> /dev/null|grep geom` -window root"
377 debugstory=$standardrant
384 debugstory=$standardok
390 aspect='-b black
-a -S'
391 debugstory=$standardok
395 center='-center -border black
'
396 aspect='-fullscreen -border black
'
398 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
401 tile='-onroot -quiet -border black
'
402 center='-center -onroot -quiet -border black
'
403 aspect='-fullscreen -onroot -quiet -border black
'
405 debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
412 debugstory=$standardrant
415 full='-max -smooth -root -quit'
417 center='-rmode 5 -root -quit'
418 aspect='-maxpect -smooth -root -quit'
419 debugstory=$standardrant
426 debugstory=$standardok
433 debugstory=$standardok
440 debugstory=$standardok
447 debugstory="fvwm-root can retain and publish the Pixmap, thus
448 supports transparency. But only these image formats are supported:
449 XBM, XPM, PNG, SVG and it is rather limited with options."
456 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
457 errormessages with aterm. Don't use it unless you have to.
"
464 debugstory="I can
't find an app to set the wallpaper with. Using xsetroot to set
465 a solid background. If you want to have a background image you should install Esetroot or feh."
470 "I can't find an app to set the wallpaper with. You can install one in
471 many many ways but I will give you some simple advice: install Eterm and
472 you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
473 recommend you install the package provided by your distro."
478 if [ "$debug" = true
]; then
483 option
=${option:='$full'}
484 option2
=${option2:='$full'}
487 if [ -z "$DISPLAY" ]; then
488 message
"You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?"
493 # random wallpaper code
494 if [ "$option" = random
]; then
495 # Lets make one thing clear...
496 wallpaperdir
="$wallpaper"
497 if [ -z "$wallpaperdir" ]; then
498 message
"No random wallpaper directory specified."
501 if [ -d "$wallpaperdir" ]; then
502 number_of_wallpapers
=`ls "$wallpaperdir"|wc -l`
503 if find_it random_number
; then
504 randomnumber
=`random_number`
505 # some shells don't support $RANDOM
506 elif [ -z "$RANDOM" ]; then
507 randomnumber
=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '`
509 randomnumber
="$RANDOM"
511 wallpapernumber
=`expr $randomnumber % $number_of_wallpapers + 1`
512 #remember previous wallpaper
513 if [ ! "$remember" = false
]; then
518 wallpaper
="$wallpaperdir/`ls \"$wallpaperdir\"|sed -n ${wallpapernumber}p`"
519 option
=$option2 # have to choose something...
521 message
"Invalid random wallpaper directory specified."
527 if [ ! -r "$wallpaper" ] && [ $WPSETTER != "xsetroot" ]; then
528 message
"Can't find wallpaper $wallpaper"
533 $WPSETTER `eval echo $option` "$wallpaper"
534 if [ $?
-ne 0 -a "$WPSETTER" != "display" ] ||
535 [ $?
-ne 1 -a "$WPSETTER" = "display" ]; then
536 message
"Something went wrong while setting the wallpaper.
537 Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
542 #remember previous wallpaper
543 if [ ! "$remember" = false
]; then