#!/bin/sh

# Copyright (C) 1990 by Digital Equipment Corporation.
# 
# Author: Michael P. Altenhofen, CEC Karlsruhe e-mail:
# Altenhofen@kampus.enet.dec.com
# 
# This file ist part of Shared X
# 
# Permission to use, copy, modify, and distribute this software and its
# documentation without fee is hereby granted, but only for non-profit  use
# and distribution,  and provided  that the copyright notice and this notice
# is preserved on all copies.
# 
# DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
# DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.

# Tell helper, where your shXchange is
# CHANGE=/usr/local/bin/shXchange
CHANGE=shXchange

# Tell helper, where your selwin is
# SELWIN=/usr/local/bin/selwin
SELWIN=selwin

######  DON'T CHANGE ANYTHING BELOW THIS LINE!
#
progname=$0

if [ $# = 0 ]
then
   echo "Usage:"
   echo "   $progname + <display> <display> ..."
   echo "   $progname - <display> <display> ..."
   echo "   $progname c[halk]"
   exit 1
fi

case $1 in
     c*)
	echo "Select the application you want to pass"
	n=`${SELWIN}`
	echo "Now choose the display"
	xprop -id $n XMUX_HOSTS |
	   awk '{n=split($3,a,"\""); n=split(a[2],b,",");
	       for (i=1; i<=n; i++)
	       print "for " b[i] ",\t type " i-1}'
	echo -n "Your choice: "
	read d
	${CHANGE} c $n $d
     	;;
     +)
	echo "Select the window to share"
	shift
	${CHANGE} p `${SELWIN}` "+$*"
        ;;
     -)
	echo "Select the shared window"
	shift
	${CHANGE} p `${SELWIN}` "-$*"
        ;;
     *)
	echo "Usage:"
	echo "   $progname + <display> <display> ..."
	echo "   $progname - <display> <display> ..."
	echo "   $progname c[halk]"
	exit 1
     	;;
esac
