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 wmsetbg feh hsetroot chbg display qiv xv xsri xli xsetbg}" # 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] /path/to/wallpaper
70 $command [-u/-U [wallpapersetter]] [-fFcCtTaA] -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,-B,-R same as uncapsed but without remembering.
96 -l Set previous wallpaper.
98 -i Information about selected wallpaper command.
102 \$XDG_CACHE_HOME/awesome/lastwallpaper In this file the wallpaper you set
103 will be stored, for the -l option.
104 Environment variables:
105 wpsetters Wallpapersetters to use.
107 wpsetters=feh awsetbg wallpaper.jpg
109 DISPLAY The display you want to set the wallpaper on.
111 DISPLAY=:0.0 awsetbg -l
117 [ -n "$1" ] && hash $1 2> /dev
/null
121 extra_args
="-default okay"
122 if find_it gxmessage
; then
123 gxmessage
$extra_args -center "$command: $@" &
125 xmessage
$extra_args -center "$command: $@" &
130 grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
131 mv -f ${lastwallpaper}.tmp ${lastwallpaper}
132 # Make dir/../../path/file.jpg work
134 # no spaces allowed between the varname and '|'
135 /*) echo $option $option2"|
$wallpaper|
$style|
"$DISPLAY >> $lastwallpaper ;;
136 *) echo $option $option2"|
$PWD/$wallpaper|
$style|
"$DISPLAY >> $lastwallpaper ;;
143 echo $sad_esetroot_story
147 if [ $# -eq 0 ]; then
148 message "no options given
"
153 # create directory and last wallpaper file
154 if [ ! -d "${CONFIG_DIR}" ]; then
155 mkdir -p "${CONFIG_DIR}"
156 touch ${lastwallpaper}
159 unset debug setterfromcommandline
160 # Parse command-line options
161 while [ $# -gt 0 ]; do
164 if find_it "$2"; then
165 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
166 echo "wpsetters
$2" >> ${lastwallpaper}.tmp
167 mv ${lastwallpaper}.tmp $lastwallpaper
169 setterfromcommandline=true
170 elif [ -z "$2" ]; then
171 grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
172 mv ${lastwallpaper}.tmp $lastwallpaper
173 message "wpsetter removed from historyfile
"
176 message "Couldn
't find \"$2\" for wallpapersetter"
182 if find_it "$2"; then
184 setterfromcommandline=true
186 message "Couldn't
find \"$2\" for wallpapersetter
"
215 wallpaper=$2 # in this case it's a dir
219 wallpaper=$2 # in this case it's a dir
223 if [ -r "$lastwallpaper" ]; then
224 option=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f1`
225 option2=`echo $option|cut -d' ' -f2`
226 option=`echo $option|cut -d' ' -f1`
227 wallpaper=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f2`
228 if [ -z "$wallpaper" ]; then
229 option=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f1`
230 option2=`echo $option|cut -d' ' -f2`
231 option=`echo $option|cut -d' ' -f1`
232 wallpaper=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f2`
234 if [ -z "$wallpaper" ]; then
235 message "No previous wallpaper recorded
for display
${DISPLAY}"
239 message "No previous wallpaper recorded
for display
${DISPLAY}"
245 if [ -r "$lastwallpaper" ]; then
246 option=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f1`
247 option2=`echo $option|cut -d' ' -f2`
248 option=`echo $option|cut -d' ' -f1`
249 style=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f3`
250 wallpaper=`grep "|
${DISPLAY}$
" $lastwallpaper|cut -d'|' -f2`
251 if [ -z "$wallpaper" ]; then
252 option=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f1`
253 option2=`echo $option|cut -d' ' -f2`
254 option=`echo $option|cut -d' ' -f1`
255 style=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f3`
256 wallpaper=`grep "|
${DISPLAY}.0$
" $lastwallpaper|cut -d'|' -f2`
259 if [ "$style" != "style
" -a -n "$wallpaper" ]; then
268 -h) display_help ; exit 0 ;;
270 message "$command doesn
't recognize -- gnu-longopts."
271 message 'Use
$command -h for a
help message.
'
275 message "unrecognized option "\`"$1'"
279 if [ "$option" = random ]; then
281 elif [ ! -r "$1" ]; then
282 message "$1 isn
't an existing wallpaper or a valid option."
285 elif [ -z "$1" ]; then
286 message 'No wallpaper to
set'
296 # Find the default wallpapersetter
297 if [ "$setterfromcommandline" != true ]; then
298 if [ -r "$lastwallpaper" ]; then
299 wpsetters="`awk '/wpsetters
/ {print
$2}' $lastwallpaper` $wpsetters"
301 for wpsetter in $wpsetters; do
302 if find_it $wpsetter; then
303 if [ ! "$wpsetter" = Esetroot ]; then
306 elif ldd `which Esetroot`|grep libImlib 2>&1 > /dev/null; then
310 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.
"
317 "$WPSETTER doesn
't set the wallpaper properly. Transparency for awesome and
318 apps like aterm and xchat won't work right with it. Consider installing
319 feh
, wmsetbg
(from windowmaker
) or Esetroot
(from Eterm
) and I
'll use
323 "$WPSETTER is a nice wallpapersetter. You won't have any problems.
"
327 full='-once -mode maximize'
328 tile='-once -mode tile'
329 center='-once -mode center'
330 aspect='-once -mode smart -max_grow 100 -max_size 100'
331 debugstory="chbg supports all features but it doesn
't report errors. I reported this bug to the chbg developers."
334 full='--center-x --center-y --scale-width=100 --scale-height=100'
336 center='--center-x --center-y --color=black
'
337 aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black
'
338 debugstory=$standardok
341 full="-sample `xwininfo -root 2> /dev/null|awk '/geom
/{print
$2}'` -window root"
343 center='-backdrop -window root
'
344 aspect="`xwininfo -root 2> /dev/null|grep geom` -window root"
345 debugstory=$standardrant
352 debugstory=$standardok
358 aspect='-b black
-a -S'
359 debugstory=$standardok
363 center='-center -border black
'
364 aspect='-fullscreen -border black
'
366 debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
369 tile='-onroot -quiet -border black
'
370 center='-center -onroot -quiet -border black
'
371 aspect='-fullscreen -onroot -quiet -border black
'
373 debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
380 debugstory=$standardrant
383 full='-max -smooth -root -quit'
385 center='-rmode 5 -root -quit'
386 aspect='-maxpect -smooth -root -quit'
387 debugstory=$standardrant
394 debugstory=$standardok
401 debugstory=$standardok
408 debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
409 errormessages with aterm. Don't use it unless you have to.
"
413 "I can
't find an app to set the wallpaper with. You can install one in
414 many many ways but I will give you some simple advice: install Eterm and
415 you're
set. Eterm provides Esetroot and thats a great wallpaper setter. I
416 recommend you
install the package provided by your distro.
"
421 if [ "$debug" = true ]; then
426 option=${option:='$full'}
427 option2=${option2:='$full'}
430 if [ -z "$DISPLAY" ]; then
431 message "You are not connected to an X session
\nPerhaps you should
set the DISPLAY environment variable?
"
436 # random wallpaper code
437 if [ "$option" = random ]; then
438 # Lets make one thing clear...
439 wallpaperdir="$wallpaper"
440 if [ -z "$wallpaperdir" ]; then
441 message "No random wallpaper directory specified.
"
444 if [ -d "$wallpaperdir" ]; then
445 number_of_wallpapers=`ls "$wallpaperdir"|wc -l`
446 if find_it random_number; then
447 randomnumber=`random_number`
448 # some shells don't support $RANDOM
449 elif [ -z "$RANDOM" ]; then
450 randomnumber=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '`
452 randomnumber="$RANDOM"
454 wallpapernumber=`expr $randomnumber % $number_of_wallpapers + 1`
455 #remember previous wallpaper
456 if [ ! "$remember" = false ]; then
461 wallpaper="$wallpaperdir/`ls \"$wallpaperdir\"|sed -n ${wallpapernumber}p`"
462 option=$option2 # have to choose something...
464 message "Invalid random wallpaper directory specified.
"
470 if [ ! -r "$wallpaper" ]; then
471 message "Can
't find wallpaper $wallpaper"
476 $WPSETTER `eval echo $option` "$wallpaper"
477 if [ $? -ne 0 ]; then
478 message "Something went wrong while setting the wallpaper.
479 Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
484 #remember previous wallpaper
485 if [ ! "$remember" = false ]; then