#!/usr/athena/bin/perl
$WafeLib = $ENV{'WAFELIB'} || "/mit/sipb/lib/wafe";
require "$WafeLib/perl/wafe.pl";

&UI( <<"End of TCL");
### BEGIN wafedesign TCL ###
form form1 topLevel  \\
	sensitive true \\
	background #749
command command1 form1  \\
	horizDistance 136 \\
	label {Instance LMF} \\
	vertDistance 25 \\
	background blue \\
	callback {echo lmf}
command command2 form1  \\
	horizDistance 136 \\
	label {Instance W-M} \\
	vertDistance 49 \\
	callback {echo wm} \\
	background red
command command3 form1  \\
	callback {echo sigh1} \\
	background green \\
	label *sigh* \\
	vertDistance 49 \\
	horizDistance 3 \\
	foreground black
command command4 form1  \\
	foreground black \\
	vertDistance 49 \\
	background orange \\
	callback {echo sigh2} \\
	horizDistance 64 \\
	label **sigh**
command command5 form1  \\
	vertDistance 75 \\
	horizDistance 4 \\
	foreground black \\
	callback {echo sigh4} \\
	background pink \\
	label *hgis*
command command6 form1  \\
	foreground black \\
	horizDistance 65 \\
	label sigh... \\
	background yellow \\
	vertDistance 74 \\
	callback {echo sigh3}
command command7 form1  \\
	background white \\
	label {Instance M-B} \\
	callback {echo mb} \\
	foreground black \\
	vertDistance 73 \\
	horizDistance 137
command command8 form1  \\
	horizDistance 31 \\
	callback {echo goodbye} \\
	label {Say goodbye and logout} \\
	font -*-*-*-*-*-*-16-*-*-*-*-*-*-* \\
	vertDistance 98
label label1 form1  \\
	foreground black \\
	label *sigh* \\
	font -*-*-*-*-*-*-34-*-*-*-*-*-*-* \\
	background gray90 \\
	horizDistance 2 \\
	vertDistance 4
label label2 form1  \\
	label {Send to...} \\
	vertDistance 4 \\
	horizDistance 136 \\
	width 90 \\
	background #749 \\
	foreground black \\
	borderColor #749 
realize
### END wafedesign TCL ###
End of TCL
    $sigh = '*sigh*';
while(<STDIN>) {
    chop;
    if(/sigh/){
	if(/1/){$sigh='*sigh*';
	&dlabel(34);}
	elsif(/2/){$sigh='**sigh**';
	&dlabel(24);}
	elsif(/3/){$sigh='sigh...';
	&dlabel(26);}
	elsif(/4/){$sigh='*hgis*';
	&dlabel(34);}
    }
    if(/lmf/){
	&zs('lmf', $sigh);
    }
    if(/wm/){
	&zs('white-magic', $sigh);
    }
    if(/mb/){
	&zs('magie-blanche', $sigh);
    }
    if(/goodbye/){
	&zs('white-magic', "Good bye...");
	sleep(5);
	&zs('lmf', "Au revior, tout le monde...");
	sleep(20);
	`kill -HUP $ENV{'XSESSION'}`;
    }
}
&wafe'cleanup; 


sub zs {
    local($instance, $sigh) = @_;
    open(ZPH, "|zwrite -n -q -d -i $instance");
    print(ZPH "$sigh\n");
    close(ZPH);
}

sub dlabel {
	local($pt) = @_;
	&Xui("label label1 form1 foreground black label $sigh font -*-*-*-*-*-*-$pt-*-*-*-*-*-*-* background gray90 horizDistance 2 vertDistance 4 height 40 width 130\n");
}
