#!/usr/athena/bin/perl

if(fork()){
	exit;
}

$newws = shift(@ARGV);
$xwininfo = `xwininfo`;

$*=1;

$xwininfo =~ /Window id: (0x[^ ]+) /;
$id = $1;

&readstate();
`/mit/mkgray/afs/bin/workspace toggle $sws{$id}`;

sub readstate {
    open(WS, "/tmp/.workspaces.$ENV{'USER'}");
    while(<WS>){
	($wid, $ws, $state) = split;
	$sws{$wid} = $ws;
	$state{$wid} = $state;
    }
    close(WS);
}

sub writestate {
    open(WS, ">/tmp/.workspaces.$ENV{'USER'}");
    for $wid (keys %sws){
	print WS "$wid $sws{$wid} $state{$wid}\n";
    }
    close(WS);
}
