First cut at "-g" - window tiling

Reapply Bren Viren's lost code for clusters in .csshrc (no idea where that went)
This commit is contained in:
duncan_ferguson 2004-04-19 13:51:20 +00:00
parent 60d80f7c36
commit ffcbd01c51

View file

@ -204,7 +204,8 @@ $user_config{'default.key_addhost'}="Control-plus";
$user_config{'default.key_clientname'}="Alt-n";
$user_config{'default.variables'}="no";
$user_config{'default.title_number'}="no";
$user_config{'default.size'}="80x10";
$user_config{'default.term_size'}="80x24";
#$user_config{'default.term_size'}="50x10";
# Now read in the system config file
Config::Simple->import_from('/etc/csshrc', \%user_config);
@ -340,6 +341,19 @@ if ( -r "/etc/clusters" )
close(CLUSTERS);
}
{
my $clstr = $user_config{'default.clusters'};
if(defined($clstr))
{
my(@clarray)=split(/\s+/,$clstr);
foreach (@clarray)
{
my $c=$user_config{'default.'.$_};
$clusters{$_} = $c if $c;
}
}
}
# loop over ARGV and expand any cluster aliases
my @cmdargs=@ARGV;
@ -384,24 +398,79 @@ foreach (reverse(@cmdargs))
# [1] process id
# [2] pipe file name
# [3] pipe file handle
# [4] window geometry if tiling
my %servers;
# handle for main window
my $mw=MainWindow->new(-title=>$control_title);
# Now get the screen height for tiling windows later
my $screen_height=$mw->screenheight;
my $screen_width=$mw->screenwidth;
# work out how many windows we are opening if setting geometry
# vars we need when we open windows
my ($term_height, $term_width, $rows, $cols);
# Get the term widht and height
my $term_height=$user_config{'default.size'};
$term_height=~ s/.*x//;
my $term_width=$user_config{'default.size'};
$term_width=~ s/x.*//;
if($options{g})
{
# Now get the screen height for tiling windows later
my $screen_height=$mw->screenheight;
my $screen_width=$mw->screenwidth;
# Work out the seen term size
my $over_height=int($screen_height/10);
my $over_width=int($screen_width/4);
#warn "screen_height=$screen_height\n";
#warn "screen_width=$screen_width\n";
RECALC:
# Get the term width and height
$term_height=$user_config{'default.term_size'};
$term_height=~ s/.*x//;
$term_height= ( $term_height * 13 ) + 5 ; # convert loosly to pixels
$term_width=$user_config{'default.term_size'};
$term_width=~ s/x.*//;
$term_width= ( $term_width * 6 ) + 20 ; # convert loosly to pixels
# Convert character size to pixels
$rows=int(( $screen_height - ($screen_height % $term_height )) / $term_height);
$cols=int(( $screen_width - ( $screen_width % $term_width )) / $term_width);
my $total=@cmdargs;
#warn "total=$total\n";
#warn "term_height=$term_height\n";
#warn "term_width=$term_width\n";
#warn "cols=$cols\n";
#warn "rows=$rows\n";
#warn "default.term_size=$user_config{'default.term_size'}\n";
# If we cannot fit them all in, decrease size of windows and rework out
if($total > ($rows * $cols ))
{
my $term_height=$user_config{'default.term_size'};
$term_height=~ s/.*x//;
my $term_width=$user_config{'default.term_size'};
$term_width=~ s/x.*//;
if($term_height>10 && $term_width > 40)
{
$term_height-=2;
$term_width-=5;
$user_config{'default.term_size'}="${term_width}x${term_height}";
warn "WARNING: too many too big terminals to fit; reducing in size to ",
$user_config{'default.term_size'}, "\n";
#warn "total=$total\n";
#warn "term_height=$term_height\n";
#warn "term_width=$term_width\n";
#warn "cols=$cols\n";
#warn "rows=$rows\n";
#warn "default.term_size=$user_config{'default.term_size'}\n";
goto RECALC;
} else {
warn "WARNING: cannot tile windows - not attempting to tile\n";
delete($options{g});
}
}
}
open_windows(@cmdargs);
@ -421,6 +490,34 @@ sub open_windows
# Only need carry on if we have been passed some args
return if($#_ == -1);
my $total=@cmdargs;
my $slots=$cols*$rows;
#warn "total:$total,slots:$slots",$/;
#warn "cols:$cols, rows:$rows\n";
my $cur_col = $total % $cols;
my $cur_row = ($total - ($total % $cols)) / $cols;
#warn "cur_col=$cur_col\n";
#warn "cur_row=$cur_row\n";
# we want the first ones to be from 0 not 1, so take 1 off
$cols-=1 if($cols > 0);
$rows-=1 if($rows > 0);
$cur_col-=1;
if($cur_col<0)
{
$cur_row-=1 ;
$cur_col=$cols;
}
#warn "start cols:$cols, rows:$rows\n";
#warn "start cur_col=$cur_col\n";
#warn "start cur_row=$cur_row\n";
foreach (@_)
{
my $serv;
@ -452,8 +549,35 @@ sub open_windows
# Now we create the fifo pipe file
mkfifo($servers{$serv_name}[2], 0600) or die("Cannot create pipe: $!");
$servers{$serv_name}[1]=fork();
my $size= $options{g} ? "-geometry $user_config{'default.term_size'}" : "";
my $place=$size;
# If tiling, start at the bottom right and work backwards to ensure the
# correct overlaps
if($options{g})
{
#warn "in cur_col=$cur_col\n";
#warn "in cur_row=$cur_row\n";
# Include extra space (+30) required on first line for title bar here
$place=$size."+".$cur_col*$term_width."+".(($cur_row*$term_height)+30);
#print "place=$place\n";
$cur_col -= 1;
if($cur_col<0)
{
#warn "cur_col reset, cur_row -1\n";
$cur_col = $cols;
$cur_row-=1;
}
#warn "out cur_col=$cur_col\n";
#warn "out cur_row=$cur_row\n";
}
$servers{$serv_name}[1]=fork();
if(!defined($servers{$serv_name}[1]))
{
@ -463,10 +587,8 @@ sub open_windows
} elsif($servers{$serv_name}[1] == 0) {
# child => fork returned 0
my $size= $options{g} ? "-geometry $user_config{'default.size'}" : "";
# Start up the terminal via ourselves so the pipes are in place
exec("$user_config{'default.terminal'} $user_config{'default.terminal_options'} $size -title '$method:$serv' -e $FindBin::Bin/$FindBin::Script -x $servers{$serv_name}[2] $path_method $serv") or warn("Could not exec session to $serv: $! ");
exec("$user_config{'default.terminal'} $user_config{'default.terminal_options'} $place -title '$method:$serv' -e $FindBin::Bin/$FindBin::Script -x $servers{$serv_name}[2] $path_method $serv") or warn("Could not exec session to $serv: $! ");
} else {
# parent => fork return process id of child
@ -1035,7 +1157,9 @@ Open the Add Host dialogue box
=item Alt-n
Paste in the correct client name to all clients, i.e.
scp /etc/hosts server:files/<Alt-n>.hosts
scp /etc/hosts server:files/<Alt-n>.hosts
would replace the <Alt-n> with the correct client name
=back
@ -1089,6 +1213,15 @@ bourne shell or c shell syntax
Show the number of open connections in control window title
=item clusters
List of defined clusters held within the file (see section on /etc/clusters
above), i.e.
clusters = list1 list2
list1 = server1 user@server2
list2 = server4 user@server5
=item key_quit = Control-q
Default key sequence to quit the program (will terminate all open windows).
@ -1233,6 +1366,10 @@ L<Config::Simple>
# Moved to sf.net cvs
#
# $Log$
# Revision 2.6 2004/04/19 13:51:20 duncan_ferguson
# First cut at "-g" - window tiling
# Reapply Bren Viren's lost code for clusters in .csshrc (no idea where that went)
#
# Revision 2.5 2004/04/15 09:35:28 duncan_ferguson
# Applied patch for missing env vars when run from window manager not cmd line
# - Tony Mancill