2003-04-27 15:33:26 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Set wallpaper for fluxbox.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2003 Han Boetes <han@mijncomputer.nl>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
#
|
2003-08-17 13:30:35 +00:00
|
|
|
# $Id: fbsetbg,v 1.15 2003/08/17 13:27:44 fluxgen Exp $
|
2003-04-27 15:33:26 +00:00
|
|
|
|
|
|
|
# Portability notes:
|
|
|
|
# To guarantee this script works on all platforms that support fluxbox
|
|
|
|
# please keep the following restrictions in mind:
|
|
|
|
#
|
2003-08-17 13:30:35 +00:00
|
|
|
# - don't use if ! command;, use command; if [ $? -ne 0 ];
|
|
|
|
# - don't use [ -e file ] use [ -r file ]
|
|
|
|
# - don't use $(), use ``
|
|
|
|
# - don't use ~, use ${HOME}
|
|
|
|
# - don't use id -u, use whoami
|
|
|
|
# - getopts won't work on all platforms, but the config-file can
|
|
|
|
# compensate for that.
|
|
|
|
# - various software like grep/sed/perl may be not present or not
|
|
|
|
# the version you have. for example grep '\W' only works on gnu-grep.
|
|
|
|
# Keep this in mind, use bare basic defaults.
|
|
|
|
# - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash.
|
|
|
|
# Non portable features like getopts in this script can be achieved in
|
|
|
|
# other ways.
|
|
|
|
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-06-06 02:18:34 +00:00
|
|
|
# The wallpapersetter is selected in this order
|
2003-06-29 08:22:24 +00:00
|
|
|
wpsetters='chbg Esetroot wmsetbg display qiv xv xsri xli xsetbg' # broken icewmbg'
|
2003-04-27 15:33:26 +00:00
|
|
|
lastwallpaper=${HOME}/.fluxbox/lastwallpaper
|
|
|
|
|
2003-04-29 11:26:34 +00:00
|
|
|
|
2003-04-27 15:33:26 +00:00
|
|
|
WHOAMI=`whoami`
|
2003-06-06 02:18:34 +00:00
|
|
|
[ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin
|
2003-04-27 15:33:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
display_usage() {
|
2003-07-20 11:23:51 +00:00
|
|
|
cat << EOF
|
2003-08-17 13:30:35 +00:00
|
|
|
Usage: fbsetbg [ -fFcCtTaA /path/to/wallpaper ] [ -l ] [ -h ] [ -d ] [ -p ]
|
2003-04-27 15:33:26 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
display_help() {
|
|
|
|
display_usage
|
2003-07-20 11:23:51 +00:00
|
|
|
cat << EOF
|
2003-04-27 15:33:26 +00:00
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
-f Set fullscreen wallpaper
|
|
|
|
-c Set centered wallpaper
|
|
|
|
-t Set tiled wallpaper
|
2003-04-28 14:45:13 +00:00
|
|
|
-a Set maximized wallpaper, preserving aspect.
|
|
|
|
( if your bgsetter doesn't support this
|
|
|
|
fbsetbg falls back to -f )
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
-F,-C,-T,-A same as uncapsed but without remembering.
|
|
|
|
|
2003-04-27 15:33:26 +00:00
|
|
|
-h Display this help
|
|
|
|
|
|
|
|
-l Set previous wallpaper
|
|
|
|
|
|
|
|
-d Debug fbsetbg
|
2003-08-17 13:30:35 +00:00
|
|
|
-p Tips
|
2003-04-27 15:33:26 +00:00
|
|
|
|
|
|
|
Files:
|
2003-08-17 13:30:35 +00:00
|
|
|
In this file the wallpaper you set will be stored, for the -l option:
|
2003-04-27 15:33:26 +00:00
|
|
|
~/.fluxbox/lastwallpaper
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
display_tips() {
|
|
|
|
cat << EOF
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
1) To replace all occurrences of bsetbg in a file use this command:
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
perl -pi -e 's,([^f]|^)bsetbg,fbsetbg,' filename
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
2) If you want the style to set the wallpaper and you want fbsetbg to
|
|
|
|
remember the previous wallpaper put this in your ~/.fluxbox/init
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
session.screen0.rootCommand: fbsetbg -l
|
2003-04-27 15:33:26 +00:00
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
3) Use fbsetbg -d to find out what wallpapersetter fbsetbg will use and
|
|
|
|
what he thinks about it.
|
2003-04-27 15:33:26 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# ugly code for solaris compat.
|
2003-08-17 13:30:35 +00:00
|
|
|
case `uname` in
|
|
|
|
Linux|*BSD)
|
|
|
|
find_it() {
|
|
|
|
which $1 > /dev/null 2>&1 && shift && $*
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
find_it() {
|
|
|
|
file=`which $1 2> /dev/null`
|
|
|
|
if [ -x "$file" ]; then
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
shift
|
|
|
|
$*
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2003-04-27 15:33:26 +00:00
|
|
|
|
|
|
|
message() {
|
|
|
|
xmessage -center "$@"
|
|
|
|
}
|
|
|
|
|
2003-04-28 14:45:13 +00:00
|
|
|
remembercommand() {
|
2003-07-20 10:58:27 +00:00
|
|
|
grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
|
2003-07-10 11:10:51 +00:00
|
|
|
mv -f ${lastwallpaper}.tmp ${lastwallpaper}
|
|
|
|
# Make dir/../../path/file.jpg work
|
2003-04-29 11:26:34 +00:00
|
|
|
case $wallpaper in
|
2003-07-10 11:10:51 +00:00
|
|
|
# no spaces allowed between the varname and '|'
|
|
|
|
/*) echo $option'|'$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
|
|
|
|
*) echo $option'|'$PWD/$wallpaper'|'$DISPLAY >> $lastwallpaper ;;
|
2003-04-29 11:26:34 +00:00
|
|
|
esac
|
2003-04-28 14:45:13 +00:00
|
|
|
}
|
|
|
|
|
2003-08-17 13:30:35 +00:00
|
|
|
debugfbsetbg() {
|
2003-04-29 11:26:34 +00:00
|
|
|
echo
|
|
|
|
echo $debugstory
|
|
|
|
echo
|
2003-04-27 15:33:26 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find the default wallpapersetter
|
|
|
|
for wpsetter in $wpsetters; do
|
|
|
|
if find_it $wpsetter; then
|
|
|
|
WPSETTER=$wpsetter
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2003-08-04 16:49:25 +00:00
|
|
|
standardrant=\
|
|
|
|
"$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and apps like aterm
|
|
|
|
and xchat won't work right with it. Consider using chbg, wmsetbg (from windowmaker)
|
2003-04-29 11:26:34 +00:00
|
|
|
or Esetroot (from Eterm)"
|
|
|
|
|
2003-08-04 16:49:25 +00:00
|
|
|
standardok=\
|
|
|
|
"$WPSETTER is a nice wallpapersetter. You won't have any problems."
|
|
|
|
|
2003-04-27 15:33:26 +00:00
|
|
|
case $WPSETTER in
|
2003-06-29 08:22:24 +00:00
|
|
|
chbg)
|
|
|
|
full='-once -mode maximize'
|
|
|
|
tile='-once -mode tile'
|
|
|
|
center='-once -mode center'
|
|
|
|
aspect='-once -mode smart -max_grow 100 -max_size 100'
|
2003-08-04 16:49:25 +00:00
|
|
|
debugstory=$standardok
|
2003-07-02 05:42:47 +00:00
|
|
|
;;
|
2003-04-27 15:33:26 +00:00
|
|
|
xsri)
|
2003-07-29 09:29:45 +00:00
|
|
|
full='--center-x --center-y --scale-width=100 --scale-width=100'
|
|
|
|
tile='--tile'
|
|
|
|
center='--center-x --center-y'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect=$full
|
2003-04-29 11:26:34 +00:00
|
|
|
debugstory="This is a RedHat specific app. I can't find docs about it."
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
2003-06-06 02:18:34 +00:00
|
|
|
display)
|
2003-05-12 19:58:47 +00:00
|
|
|
full="`xwininfo -root|grep geom` -window root"
|
2003-04-27 15:33:26 +00:00
|
|
|
tile='-window root'
|
|
|
|
center='-backdrop -window root'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect=$full
|
2003-04-29 11:26:34 +00:00
|
|
|
debugstory=$standardrant
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
|
|
|
Esetroot)
|
|
|
|
full='-scale'
|
|
|
|
tile=''
|
|
|
|
center='-c'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect='-fit'
|
2003-08-04 16:49:25 +00:00
|
|
|
debugstory=$standardok
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
|
|
|
wmsetbg)
|
|
|
|
full='-s -S'
|
|
|
|
tile='-t'
|
|
|
|
center='-b black -e'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect='-b black -a'
|
2003-08-04 16:49:25 +00:00
|
|
|
debugstory=$standardok
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
|
|
|
xsetbg)
|
2003-07-29 09:29:45 +00:00
|
|
|
tile='-border black'
|
|
|
|
center='-center -border black'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect='-fullscreen -border black'
|
2003-07-29 09:29:45 +00:00
|
|
|
full=$aspect #broken
|
2003-04-29 11:26:34 +00:00
|
|
|
debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
|
2003-07-29 09:29:45 +00:00
|
|
|
;;
|
2003-04-27 15:33:26 +00:00
|
|
|
xli)
|
2003-07-29 09:29:45 +00:00
|
|
|
tile='-onroot -quiet -border black'
|
|
|
|
center='-center -onroot -quiet -border black'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect='-fullscreen -onroot -quiet -border black'
|
2003-07-29 09:29:45 +00:00
|
|
|
full=$aspect #broken
|
2003-04-29 11:26:34 +00:00
|
|
|
debugstory='The fillscreen option (-f) is broken, defaults to (-a). $standardrant'
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
|
|
|
qiv)
|
|
|
|
full='--root_s'
|
|
|
|
tile='--root_t'
|
|
|
|
center='--root'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect='-m --root'
|
2003-04-29 11:26:34 +00:00
|
|
|
debugstory=$standardrant
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
|
|
|
xv)
|
|
|
|
full='-max -smooth -root -quit'
|
|
|
|
tile='-root -quit'
|
|
|
|
center='-rmode 5 -root -quit'
|
2003-04-28 14:45:13 +00:00
|
|
|
aspect='-maxpect -smooth -root -quit'
|
2003-04-29 11:26:34 +00:00
|
|
|
debugstory=$standardrant
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
2003-06-06 02:18:34 +00:00
|
|
|
icewmbg)
|
|
|
|
tile='-s'
|
|
|
|
full=$tile
|
|
|
|
center=$tile
|
|
|
|
aspect=$tile
|
|
|
|
debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
|
|
|
|
errormessages with aterm. Don't use it unless you have to."
|
|
|
|
;;
|
2003-04-27 15:33:26 +00:00
|
|
|
'')
|
2003-08-04 16:49:25 +00:00
|
|
|
message \
|
|
|
|
"I can't find an app to set the wallpaper with. You can install one in
|
2003-04-29 11:26:34 +00:00
|
|
|
many many ways but I will give you some simple advice: install Eterm and
|
|
|
|
you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
|
|
|
|
recommend you install the package provided by your distro."
|
|
|
|
exit 1
|
|
|
|
;;
|
2003-04-27 15:33:26 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
#Get options.
|
2003-08-17 13:30:35 +00:00
|
|
|
getopts ":a:f:c:t:A:F:C:T:pdlh-" COMMAND_LINE_ARGUMENT
|
2003-04-27 15:33:26 +00:00
|
|
|
case "${COMMAND_LINE_ARGUMENT}" in
|
2003-04-29 11:26:34 +00:00
|
|
|
d) debugfbsetbg
|
|
|
|
exit 0
|
|
|
|
;;
|
2003-04-28 14:45:13 +00:00
|
|
|
a) option=$aspect
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
;;
|
2003-04-27 15:33:26 +00:00
|
|
|
f) option=$full
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
;;
|
|
|
|
c) option=$center
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
;;
|
|
|
|
t) option=$tile
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
;;
|
2003-08-17 13:30:35 +00:00
|
|
|
A) option=$aspect
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
remember=false
|
|
|
|
;;
|
|
|
|
F) option=$full
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
remember=false
|
|
|
|
;;
|
|
|
|
C) option=$center
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
remember=false
|
|
|
|
;;
|
|
|
|
T) option=$tile
|
|
|
|
wallpaper=$OPTARG
|
|
|
|
remember=false
|
|
|
|
;;
|
|
|
|
|
2003-04-27 15:33:26 +00:00
|
|
|
l)
|
2003-07-20 11:23:51 +00:00
|
|
|
if [ -r $lastwallpaper ]; then
|
|
|
|
option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1`
|
|
|
|
wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
|
2003-04-27 15:33:26 +00:00
|
|
|
else
|
2003-06-06 02:18:34 +00:00
|
|
|
message 'No previous wallpaper recorded. You have never used fbsetbg before.'
|
2003-07-10 11:10:51 +00:00
|
|
|
exit 1
|
2003-04-27 15:33:26 +00:00
|
|
|
fi
|
2003-07-10 11:10:51 +00:00
|
|
|
remember=false
|
2003-04-27 15:33:26 +00:00
|
|
|
;;
|
|
|
|
h) display_help ; exit 0 ;;
|
2003-08-17 13:30:35 +00:00
|
|
|
p) display_tips ; exit 0 ;;
|
2003-04-27 15:33:26 +00:00
|
|
|
-) echo "fbsetbg doesn't recognize -- gnu-longopts."
|
2003-04-29 13:50:05 +00:00
|
|
|
echo 'Use fbsetbg -h for a long help message.'
|
2003-04-27 15:33:26 +00:00
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
2003-04-29 13:50:05 +00:00
|
|
|
*) if [ ! -r "$1" ]; then
|
|
|
|
echo "$1 isn't an existing wallpaper or a valid option." >&2
|
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2003-07-20 11:23:51 +00:00
|
|
|
if [ -z "$1" ]; then
|
2003-04-29 13:50:05 +00:00
|
|
|
message 'No wallpaper to set' >&2
|
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2003-04-27 15:33:26 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
option=${option:=$full}
|
|
|
|
wallpaper=${wallpaper:=$1}
|
|
|
|
|
|
|
|
|
2003-07-20 11:23:51 +00:00
|
|
|
if [ ! -r "$wallpaper" ]; then
|
2003-04-27 15:33:26 +00:00
|
|
|
message "Can't find wallpaper $wallpaper"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
$WPSETTER $option "$wallpaper" || message "Something went wrong while setting the wallpaper
|
|
|
|
Run '$WPSETTER $option "$wallpaper"' from an xterm to find out what."
|
|
|
|
#remember previous wallpaper
|
2003-07-10 11:10:51 +00:00
|
|
|
[ ! "$remember" = false ] && remembercommand
|
2003-08-17 13:30:35 +00:00
|
|
|
# Off course this returns 1 most of the time.
|
|
|
|
exit 0
|