##########################################################################
# Title      :  xsetbg - set X11 background image using "xv"
# Author     :  Heiner Steven (heiner.steven@odn.de)
#               after a script by muftix@asbach.de
# Date       :  1994-04-21
# Requires   :	cfcat, dcop, xv
# Category   :  Desktop, KDE
# SCCS-Id.   :	@(#) xsetbg	1.5 04/12/20
##########################################################################
# Note
##########################################################################

PN=`basename "$0"`			# Program name
VER='1.5'

: ${PICDEF:=`cfcat $HOME/.picdefault`}	# 

Usage () {
    echo "$PN - set X11 background image, $VER
usage: $PN [imagefile]

If no image file was specified, the name of the file is taken
from the file \$PICDEF=$PICDEF." >&2
    exit 1
}

[ $# -gt 1 -o \( $# -eq 1 -a "$1" = "-h" \) ] && Usage

Img=${1:-$PICDEF}
[ -z "$Img" ] && Usage

if (dcop kdesktop) >/dev/null 2>&1
then
    # KDE desktop is running, use the KDE way of setting the
    # background image: invoke method "setWallpaper()" of object
    # "KBackgroundIface" from application "kdesktop"

    # We need an absolute path name; a relative one is not
    # sufficient.

    case "$1" in
    	/*)	;;	# Absolute path name
	*)	set -- "`pwd`/$1";;
    esac

    dcop kdesktop KBackgroundIface setWallpaper "$1" 5
else
    # Display image in the root window, centered, maximum size.
    # Terminate program automatically

    xv -24 -root -rmode 0 -quit "$@" &
fi
