added support for specifying the desired number of columns or rows

This commit is contained in:
Lohmar ASHAR 2017-04-29 17:08:22 +02:00
parent 2b9b8990b7
commit cd355f965d
4 changed files with 58 additions and 18 deletions

View file

@ -950,6 +950,25 @@ sub retile_hosts {
$self->config->{internal_screen_width} = $xdisplay->{width_in_pixels}; $self->config->{internal_screen_width} = $xdisplay->{width_in_pixels};
# Now, work out how many columns of terminals we can fit on screen # Now, work out how many columns of terminals we can fit on screen
if ( $self->config->{rows} != -1 || $self->config->{cols} != -1 ) {
if ( $self->config->{rows} != -1 ) {
$self->config->{internal_rows} = $self->config->{rows};
$self->config->{internal_columns} = int(
( $self->config->{internal_total}
/ $self->config->{internal_rows}
) + 0.999
);
}
else {
$self->config->{internal_columns} = $self->config->{cols};
$self->config->{internal_rows} = int(
( $self->config->{internal_total}
/ $self->config->{internal_columns}
) + 0.999
);
}
}
else {
$self->config->{internal_columns} = int( $self->config->{internal_columns} = int(
( $self->config->{internal_screen_width} ( $self->config->{internal_screen_width}
- $self->config->{screen_reserve_left} - $self->config->{screen_reserve_left}
@ -967,7 +986,7 @@ sub retile_hosts {
/ $self->config->{internal_columns} / $self->config->{internal_columns}
) + 0.999 ) + 0.999
); );
}
$self->debug( 2, "Screen Columns: ", $self->config->{internal_columns} ); $self->debug( 2, "Screen Columns: ", $self->config->{internal_columns} );
$self->debug( 2, "Screen Rows: ", $self->config->{internal_rows} ); $self->debug( 2, "Screen Rows: ", $self->config->{internal_rows} );

View file

@ -108,6 +108,8 @@ my %default_config = (
# don't set username here as takes precendence over ssh config # don't set username here as takes precendence over ssh config
user => '', user => '',
rows => -1,
cols => -1,
); );
sub new { sub new {

View file

@ -240,7 +240,16 @@ sub add_common_options {
help => help =>
$self->loc('Do not output extra text when using some options'), $self->loc('Do not output extra text when using some options'),
); );
$self->add_option(
spec => 'cols|x=i',
arg_desc => 'cols',
help => $self->loc('Number of columns'),
);
$self->add_option(
spec => 'rows|y=i',
arg_desc => 'rows',
help => $self->loc('Number of rows'),
);
return $self; return $self;
} }
@ -380,6 +389,12 @@ sub getopts {
= !$self->parent->config->{window_tiling} || 0; = !$self->parent->config->{window_tiling} || 0;
} }
if ( $self->rows ) {
$self->parent->config->{rows} = $self->rows;
}
if ( $self->cols ) {
$self->parent->config->{cols} = $self->cols;
}
return $self; return $self;
} }

View file

@ -124,6 +124,8 @@ Readonly::Hash my %default_config => {
# other bits inheritted from App::ClusterSSH::Base # other bits inheritted from App::ClusterSSH::Base
lang => 'en', lang => 'en',
user => '', user => '',
rows => -1,
cols => -1,
}; };
my %expected = %default_config; my %expected = %default_config;
is_deeply( $config, \%expected, 'default config is correct' ); is_deeply( $config, \%expected, 'default config is correct' );
@ -538,6 +540,7 @@ my $expected = qq{# Configuration dump produced by "cssh -d"
auto_close=5 auto_close=5
auto_quit=yes auto_quit=yes
auto_wm_decoration_offsets=no auto_wm_decoration_offsets=no
cols=-1
console=console console=console
console_args= console_args=
console_position= console_position=
@ -568,6 +571,7 @@ max_host_menu_items=30
menu_host_autotearoff=0 menu_host_autotearoff=0
menu_send_autotearoff=0 menu_send_autotearoff=0
mouse_paste=Button-2 mouse_paste=Button-2
rows=-1
rsh=rsh rsh=rsh
rsh_args= rsh_args=
screen_reserve_bottom=60 screen_reserve_bottom=60