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 wmsetbg feh hsetroot chbg display qiv xv xsri xli xsetbg 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 uncapsed 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
150 if [ $# -eq 0 ]; then
151 message "no options given
"
156 # create directory and last wallpaper file
157 if [ ! -d "${CONFIG_DIR}" ]; then
158 mkdir -p "${CONFIG_DIR}"
159 touch ${lastwallpaper}
162 unset debug setterfromcommandline
163 # Parse command-line options
164 while [ $# -gt 0 ]; do
167 if find_it "$2"; then
168 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
169 echo "wpsetters
$2" >> ${lastwallpaper}.tmp
170 mv ${lastwallpaper}.tmp $lastwallpaper
172 setterfromcommandline=true
173 elif [ -z "$2" ]; then
174 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
175 mv ${lastwallpaper}.tmp $lastwallpaper
176 message "wpsetter removed from historyfile
"
179 message "Couldn
't find \"$2\" for wallpapersetter"
185 if find_it "$2"; then
187 setterfromcommandline=true
189 message "Couldn't
find \"$2\" for wallpapersetter
"
217 montage=`which montage`
218 if test ! -z "$montage"; then
222 for i in `seq $cols`; do
226 $montage $fns -geometry +0+0 -tile ${cols}x $CONFIG_DIR/montage.png
227 wallpaper=$CONFIG_DIR/montage.png
230 echo "montage not found. Falling back to single image
"
235 wallpaper=$2 # in this case it's a dir
239 wallpaper=$2 # in this case it's a dir
243 if [ -r "$lastwallpaper" ]; then
244 option=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f1`
245 option2=`echo $option|cut -d' ' -f2`
246 option=`echo $option|cut -d' ' -f1`
247 wallpaper=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f2`
248 if [ -z "$wallpaper" ]; then
249 option=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f1`
250 option2=`echo $option|cut -d' ' -f2`
251 option=`echo $option|cut -d' ' -f1`
252 wallpaper=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f2`
254 if [ -z "$wallpaper" ]; then
255 message "No previous wallpaper recorded
for display
${DISPLAY}"
259 message "No previous wallpaper recorded
for display
${DISPLAY}"
265 if [ -r "$lastwallpaper" ]; then
266 option=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f1`
267 option2=`echo $option|cut -d' ' -f2`
268 option=`echo $option|cut -d' ' -f1`
269 style=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f3`
270 wallpaper=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f2`
271 if [ -z "$wallpaper" ]; then
272 option=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f1`
273 option2=`echo $option|cut -d' ' -f2`
274 option=`echo $option|cut -d' ' -f1`
275 style=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f3`
276 wallpaper=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f2`
279 if [ "$style" != "style
" -a -n "$wallpaper" ]; then
288 -h) display_help ; exit 0 ;;
290 message "$command doesn
't recognize -- gnu-longopts."
291 message 'Use
$command -h for a
help message.
'
295 message "unrecognized option "\`"$1'"
299 if [ "$option" = random ]; then
301 elif [ ! -r "$1" ]; then
302 message "$1 isn
't an existing wallpaper or a valid option."
305 elif [ -z "$1" ]; then
306 message 'No wallpaper to
set'
316 # Find the default wallpapersetter
317 if [ "$setterfromcommandline" != true ]; then
318 if [ -r "$lastwallpaper" ]; then
319 wpsetters="`awk '/wpsetters
/ {print
$2}' $lastwallpaper` $wpsetters"
321 for wpsetter in $wpsetters; do
322 if find_it $wpsetter; then
323 if [ ! "$wpsetter" = Esetroot ]; then
326 elif 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.
"
337 "$WPSETTER doesn
't set the wallpaper properly. Transparency for awesome and
338 apps like aterm and xchat won't work right with it. Consider installing
339 feh
, wmsetbg
(from windowmaker
) or Esetroot
(from Eterm
) and I
'll use
343 "$WPSETTER is a nice wallpapersetter. You won't have any problems.
"
347 full='-once -mode maximize'
348 tile='-once -mode tile'
349 center='-once -mode center'
350 aspect='-once -mode smart -max_grow 100 -max_size 100'
351 debugstory="chbg supports all features but it doesn
't report errors. I reported this bug to the chbg developers."
354 full='--center-x --center-y --scale-width=100 --scale-height=100'
356 center='--center-x --center-y --color=black
'
357 aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black
'
358 debugstory=$standardok
361 full="-sample `xwininfo -root 2> /dev/null|awk '/geom
/{print
$2}'` -window root"
363 center='-backdrop -window root
'
364 aspect="`xwininfo -root 2> /dev/null|grep geom` -window root"
365 debugstory=$standardrant
372 debugstory=$standardok
378 aspect='-b black
-a -S'
379 debugstory=$standardok
383 center='-center -border black
'
384 aspect='-fullscreen -border black
'
386 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
389 tile='-onroot -quiet -border black
'
390 center='-center -onroot -quiet -border black
'
391 aspect='-fullscreen -onroot -quiet -border black
'
393 debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
400 debugstory=$standardrant
403 full='-max -smooth -root -quit'
405 center='-rmode 5 -root -quit'
406 aspect='-maxpect -smooth -root -quit'
407 debugstory=$standardrant
414 debugstory=$standardok
421 debugstory=$standardok
428 debugstory=$standardok
435 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
436 errormessages with aterm. Don't use it unless you have to.
"
443 debugstory="I can
't find an app to set the wallpaper with. Using xsetroot to set
444 a solid background. If you want to have a background image you should install Esetroot or feh."
449 "I can't find an app to set the wallpaper with. You can install one in
450 many many ways but I will give you some simple advice: install Eterm and
451 you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
452 recommend you install the package provided by your distro."
457 if [ "$debug" = true
]; then
462 option
=${option:='$full'}
463 option2
=${option2:='$full'}
466 if [ -z "$DISPLAY" ]; then
467 message
"You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?"
472 # random wallpaper code
473 if [ "$option" = random
]; then
474 # Lets make one thing clear...
475 wallpaperdir
="$wallpaper"
476 if [ -z "$wallpaperdir" ]; then
477 message
"No random wallpaper directory specified."
480 if [ -d "$wallpaperdir" ]; then
481 number_of_wallpapers
=`ls "$wallpaperdir"|wc -l`
482 if find_it random_number
; then
483 randomnumber
=`random_number`
484 # some shells don't support $RANDOM
485 elif [ -z "$RANDOM" ]; then
486 randomnumber
=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '`
488 randomnumber
="$RANDOM"
490 wallpapernumber
=`expr $randomnumber % $number_of_wallpapers + 1`
491 #remember previous wallpaper
492 if [ ! "$remember" = false
]; then
497 wallpaper
="$wallpaperdir/`ls \"$wallpaperdir\"|sed -n ${wallpapernumber}p`"
498 option
=$option2 # have to choose something...
500 message
"Invalid random wallpaper directory specified."
506 if [ ! -r "$wallpaper" ] && [ $WPSETTER != "xsetroot" ]; then
507 message
"Can't find wallpaper $wallpaper"
512 $WPSETTER `eval echo $option` "$wallpaper"
513 if [ $?
-ne 0 ]; then
514 message
"Something went wrong while setting the wallpaper.
515 Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
520 #remember previous wallpaper
521 if [ ! "$remember" = false
]; then