FvwmPiazza

 view release on metacpan or  search on metacpan

lib/FvwmPiazza/Layouts/Grid.pm  view on Meta::CPAN

use FVWM::Module;
use FvwmPiazza::Tiler;
use FvwmPiazza::Page;
use FvwmPiazza::Group;
use FvwmPiazza::GroupWindow;

use base qw( FvwmPiazza::Layouts );

our $ERROR;
our $DEBUG = 0 unless defined $DEBUG;

=head1 METHODS

=head2 init

=cut

sub init {
    my ($self, $config) = @_;

    return $self;
} # init


=head2 apply_layout

Apply the requested tiling layout.

=cut
sub apply_layout {
    my $self = shift;
    my %args = (
		area=>undef,
		options=>[],
		left_offset=>0,
		right_offset=>0,
		top_offset=>0,
		bottom_offset=>0,
		vp_width=>0,
		vp_heigt=>0,
		max_win=>2,
		tiler=>undef,
		@_
	       );
    my $err = $self->check_args(%args);
    if ($err)
    {
        return $self->error($err);
    }
    my $area = $args{area};

    # parse the options, if any
    my @options = @{$args{options}};
    my $num_cols;
    my @rat_args = ();
    my $width_ratio;
    my $height_ratio;

    # new-style
    {
        local @ARGV = @options;
        my $parser = new Getopt::Long::Parser();
        if (!$parser->getoptions("cols=n" => \$num_cols,
                                 'ratios=s@' => \@rat_args,
                                 "width_ratio=s" => \$width_ratio,
                                 "height_ratio=s" => \$height_ratio))
        {
            $args{tiler}->debug("Grid failed to parse options: " . join(':', @ARGV));
        }
        @options = @ARGV;
    }
    if (@rat_args)
    {
        # width first, then height
        if (@rat_args = 1)
        {
            my @rat = split(',', $args{ratios});
            $width_ratio = $rat[0];
            $height_ratio = $rat[1];
        }
        else # more than one, take first two
        {
            $width_ratio = $rat_args[0];
            $height_ratio = $rat_args[1];
        }
    }
    # old-style
    if (!defined $num_cols)
    {
        $num_cols = (@options ? shift @options : 2);
    }
    if (!defined $width_ratio)
    {
        $width_ratio = (@options ? shift @options : '');
    }
    if (!defined $height_ratio)
    {
        $height_ratio = (@options ? shift @options : '');
    }

    my $working_width = $args{vp_width} -
	($args{left_offset} + $args{right_offset});
    my $working_height = $args{vp_height} -
	($args{top_offset} + $args{bottom_offset});

    my $num_win = $area->num_windows();
    my $max_win = $args{max_win};

    $num_cols = 1 if $num_win == 1;

    # adjust the max-win if we have few windows
    if ($num_win < $max_win)
    {
	$max_win = $num_win + ($num_win % $num_cols);
	$area->redistribute_windows(n_groups=>$max_win);
    }
    elsif ($area->num_groups() != $max_win)
    {
	$area->redistribute_windows(n_groups=>$max_win);
    }



( run in 1.539 second using v1.01-cache-2.11-cpan-364913b4093 )