#!/usr/bin/perl 
# Philip Shuman  philip at shuman dot org  c2000 v1.1
# usage: "warpto.pl programname"

@possible_wins = grep /$ARGV[0]/, `eesh -ewait window_list`; 

foreach(@possible_wins) { 
   chomp; 
   @stuff = split /\:/; 
   $stuff[0] =~ s/\s+//g; 
   push @win_ids, $stuff[0]; 
} 
$last = $#win_ids; 

($tmp,$destdesk) = split(/\:/, `eesh -ewait \"win_op $win_ids[$last] desk ?\"`); 
$destdesk =~ s/\s+//g; 

($tmp,$destarea) = split(/\:/, `eesh -ewait \"win_op $win_ids[$last] area ?\"`); 
chomp($destarea); 
$destarea =~ s/^\s+//g; 

($tmp,$iconify) = split(/\:/, `eesh -ewait \"win_op $win_ids[$last] iconify ?\"`); 
chomp($iconify); 
$iconify =~ s/\s+//g; 

open IPCPIPE,"| eesh"; 
print IPCPIPE "goto_desktop $destdesk\n"; 
print IPCPIPE "goto_area $destarea\n"; 
if ($iconify eq 'yes') { print IPCPIPE "win_op $win_ids[$last] iconify\n"; } 
print IPCPIPE "win_op $win_ids[$last] raise\n"; 
print IPCPIPE "set_focus $win_ids[$last]\n"; 
close IPCPIPE;
