fluxbox/util/fbsetbg

295 lines
7.9 KiB
Text
Raw Normal View History

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-04 16:49:25 +00:00
# $Id: fbsetbg,v 1.14 2003/08/04 16:49:25 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-04-28 14:45:13 +00:00
# don't use [ -e file ], use [ -r file ]
2003-04-27 15:33:26 +00:00
# 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.
#
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-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-04-29 13:50:05 +00:00
Usage: fbsetbg [ -fcta /path/to/wallpaper ] [ -l ] [ -h ] [ -d ]
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
-h Display this help
-l Set previous wallpaper
-d Debug fbsetbg
-T Tips
Files:
~/.fluxbox/lastwallpaper
EOF
}
display_tips(){
2003-07-20 11:23:51 +00:00
cat<< EOF
2003-04-27 15:33:26 +00:00
To replace all occurrences of bsetbg in a file use this command:
2003-04-27 15:33:26 +00:00
2003-07-20 11:23:51 +00:00
perl -pi -e 's,([^f]|^)bsetbg,fbsetbg,' filename
2003-04-27 15:33:26 +00:00
2003-04-28 14:45:13 +00:00
If you want the style to set the wallpaper and you want fbsetbg to
2003-04-27 15:33:26 +00:00
remember the previous wallpaper put this in your ~/.fluxbox/init
session.screen0.rootCommand: fbsetbg -l
EOF
}
# ugly code for solaris compat.
find_it() {
file=`which $1 2> /dev/null`
if [ -x "$file" ]; then
if [ $# -gt 1 ]; then
shift
$*
fi
return 0
else
return 1
fi
}
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
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 ;;
esac
2003-04-28 14:45:13 +00:00
}
2003-04-27 15:33:26 +00:00
debugfbsetbg (){
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)
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
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
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
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
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'
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'
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
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.
getopts ":a:f:c:t:Tdlh-" COMMAND_LINE_ARGUMENT
2003-04-27 15:33:26 +00:00
case "${COMMAND_LINE_ARGUMENT}" in
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
;;
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 ;;
T) display_tips ; exit 0 ;;
-) 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