2008-02-07 21:48:21 +00:00
#!/usr/bin/env perl
2008-01-10 01:59:16 +00:00
#A placeholder wcons, a fuller port from 1.3 is needed
2008-02-07 21:48:21 +00:00
use Getopt::Long qw(:config getopt_compat);
use File::Basename;
use Data::Dumper;
2008-02-08 15:45:13 +00:00
use strict;
2008-02-07 21:48:21 +00:00
unless ($ENV{DISPLAY}) {
print '$DISPLAY not set';
exit 1;
}
my $mydir = dirname($0);
my $sb;
my $tilefact;
my $font;
GetOptions(
'sb' => \$sb,
'tile|t:i' => \$tilefact,
'font|f=s' => \$font
);
my $nodes=`nodels $ARGV[0]`;
my @nodes = split /\n/,$nodes;
my $firstnode = shift @nodes;
2008-02-08 15:45:13 +00:00
my $currx;
my $curry;
my $wmxo;
my $wmyo;
my $currx;
my $screenwidth;
my $screenheight;
my $window_width;
my $window_height;
2008-02-08 19:13:10 +00:00
my $panel_pad=0;
my $top_pad;
2008-02-07 21:48:21 +00:00
if (defined($tilefact)) {
2008-02-08 15:45:13 +00:00
my $rootinf = `xwininfo -root`;
foreach (split /\n/,$rootinf) {
if (/.*Width:\s+([0-9]*).*/) {
$screenwidth=$1;
} elsif (/.*Height:\s+([0-9]*).*/) {
$screenheight=$1;
}
}
2008-02-08 19:13:10 +00:00
$rootinf = `xwininfo -name "Top Panel"`;
foreach (split /\n/,$rootinf) {
if (/-geometry\s+([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)/) {
if ($1 > 640 and $2 < 480 and $3 == 0 and $4 == 0) {
$panel_pad=$2;
}
}
}
system("xterm -fn 5x7 -name $firstnode -title $firstnode -n $firstnode -geometry +0+0 -e /bin/sh -c \"$mydir/xtcd.pl ".$ENV{DISPLAY}." $firstnode $firstnode & $mydir/rcons $firstnode\" &");
2008-02-08 15:45:13 +00:00
sleep(2); #Give time for window manager to figure out everything
my $xinfo = `xwininfo -name $firstnode`;
my @xinfl = split(/\n/,$xinfo);
my $side_pad;
my $wmxo;
my $wmyo;
foreach (@xinfl) {
if (/.*Absolute upper-left X:\s*([0-9]*).*/) {
$side_pad = $1;
} elsif (/.*Absolute upper-left Y:\s*([0-9]*).*/) {
2008-02-08 19:13:10 +00:00
$top_pad = $1-$panel_pad;
2008-02-08 15:45:13 +00:00
} elsif (/.*Width:\s*([0-9]*).*/) {
$window_width = $1;
} elsif (/.*Height:\s*([0-9]*).*/) {
$window_height = $1;
} elsif (/.*-gemotery \d+x\d+\+(\d+)(\d+)/) {
$wmxo=$1;
$wmyo=$2;
}
}
$window_width += $side_pad*2; #add the side border, assuming symmetric left and right borders
$window_height += $side_pad+$top_pad; #Add the titlebar and bottom border, which is guessed to probably be equal to the sides, doesn't hold true in all cases, i.e. window maker, but it's the currently best approximation
$screenwidth-=$wmxo; #Subtract a factor that 1.3 did, not sure why precisely
$screenheight-=$wmyo;
$currx=$window_width;
2008-02-08 19:13:10 +00:00
$curry=$panel_pad; #+$top_pad;
2008-02-08 15:45:13 +00:00
my $maxcol = int($screenwidth/$window_width);
unless ($tilefact or $tilefact > $maxcol) {
$tilefact=$maxcol;
}
if ($tilefact==1) {
$curry+=$window_height;
2008-02-08 19:13:10 +00:00
$currx=0;
2008-02-08 15:45:13 +00:00
}
2008-02-07 21:48:21 +00:00
} else {
2008-02-08 19:13:10 +00:00
system("xterm -fn 5x7 -name $firstnode -title $firstnode -n $firstnode -e /bin/sh -c \"$mydir/xtcd.pl ".$ENV{DISPLAY}." $firstnode $firstnode & $mydir/rcons $firstnode\" &");
2008-02-07 21:48:21 +00:00
}
2008-02-08 15:45:13 +00:00
my $geometry="";
2008-02-07 21:48:21 +00:00
foreach (@nodes) {
2008-02-08 15:45:13 +00:00
if ($tilefact) {
my $corrected_x=$currx+$wmxo;
my $corrected_y=$curry+$wmyo;
$geometry="-geometry +$corrected_x+$corrected_y";
$currx+=$window_width;
if ($currx >= ($tilefact * $window_width)) {
$currx=0;
$curry+=$window_height;
if ($curry > $screenheight) {
2008-02-08 19:13:10 +00:00
$curry = $panel_pad; #+$top_pad;
2008-02-08 15:45:13 +00:00
}
}
}
2008-02-08 19:13:10 +00:00
system("xterm -fn 5x7 -name $_ -title $_ -n $_ $geometry -e /bin/sh -c \"$mydir/xtcd.pl .".$ENV{DISPLAY}." $_ $_ & $mydir/rcons $_\" &");
2008-02-07 21:48:21 +00:00
}
#print Dumper(\@ARGV);
#MYDIR=`dirname $0`
#for n in $NODES
#do
2008-02-08 19:13:10 +00:00
# xterm -fn 5x7 -name wcons -T $n -n $n -e $MYDIR/rcons $n &
2008-02-07 21:48:21 +00:00
#done