#!/bin/bash
##
# Copyright : (C) 2007 cyberorg
# E-mail    : cyberorg (at) cyberorg.info 
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#This is a script to run xscreensaver as animated background in Xgl
#Get xwinwrap before using this script
#
#-g = parse geometry
#-ni = no input
#-argb = argb visual
#-fs = full screen
#-s = sticky
#-st = skip taskbar
#-sp = skip pager
#-a = above
#-b = below
#-nf = no focus
#-o OPACITY
#
##
ARCH=`arch`
if [ $ARCH == "i686" ]; then
SAVERPATH=/usr/lib/xscreensaver
elif [ $ARCH == "x86_64" ]; then
SAVERPATH=/usr/lib64/xscreensaver
fi
need_help() {
	## See if any parameters was supplied. If not, or to many, show help
	if [ x"$1" = x"" -o x"$2" != x"" ]; then
		echo ""
		echo "Please run coolbg again with one of the following parameters;"
		echo "You have to provide the full path where the movie file is"
		echo "   -x    - Use xscreensaver as a cool background"
		echo "   -m    - Play movie as a background, cd to folder containing movie files(requires mplayer)"
		exit 1
	fi
	RUNPARAM=$1
}
need_help $1
if [ x"$RUNPARAM" = x"-x" ]; then
while true; do
ls $SAVERPATH
echo "Select your cool background:"
read background
bg=$background
echo -n "Want to run in foreground? (y/n) "
read yn
case $yn in
y* | Y* ) xwinwrap -ni -argb -fs -s -st -sp -nf -- $SAVERPATH/$bg -root -window-id WID; break ;;
[nN]* ) xwinwrap -ni -argb -fs -s -st -sp -b -nf -- $SAVERPATH/$bg -root -window-id WID; break ;;
q* ) exit ;;
* ) echo "unknown response. Asking again" ;;
esac
done
fi
if [ x"$RUNPARAM" = x"-m" ]; then
while true; do
ls
echo "Select the movie to play on the background:"
read background
bg=$background
xwinwrap -ni -fs -s -st -sp -b -nf -- mplayer -wid WID -quiet $bg
done
fi

