2010-05-10 03:33:10 -04:00
|
|
|
|
#!perl
|
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
|
#
|
|
|
|
|
# Tests splitting
|
|
|
|
|
#
|
2011-03-09 14:25:17 -05:00
|
|
|
|
use i3test;
|
2010-05-10 03:33:10 -04:00
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
|
my $tmp = fresh_workspace;
|
2010-05-10 03:33:10 -04:00
|
|
|
|
|
|
|
|
|
my $ws = get_ws($tmp);
|
2011-01-07 14:48:01 -05:00
|
|
|
|
is($ws->{orientation}, 'horizontal', 'orientation horizontal by default');
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'split v';
|
2010-05-10 03:33:10 -04:00
|
|
|
|
$ws = get_ws($tmp);
|
2011-01-07 14:48:01 -05:00
|
|
|
|
is($ws->{orientation}, 'vertical', 'split v changes workspace orientation');
|
2010-05-10 03:33:10 -04:00
|
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
# Open two containers, split, open another container. Then verify
|
|
|
|
|
# the layout is like we expect it to be
|
|
|
|
|
######################################################################
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'open';
|
|
|
|
|
cmd 'open';
|
2010-05-10 03:33:10 -04:00
|
|
|
|
my $content = get_ws_content($tmp);
|
|
|
|
|
|
|
|
|
|
is(@{$content}, 2, 'two containers on workspace level');
|
|
|
|
|
my $first = $content->[0];
|
|
|
|
|
my $second = $content->[1];
|
|
|
|
|
|
|
|
|
|
is(@{$first->{nodes}}, 0, 'first container has no children');
|
|
|
|
|
is(@{$second->{nodes}}, 0, 'second container has no children (yet)');
|
|
|
|
|
my $old_name = $second->{name};
|
|
|
|
|
|
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'split h';
|
|
|
|
|
cmd 'open';
|
2010-05-10 03:33:10 -04:00
|
|
|
|
|
|
|
|
|
$content = get_ws_content($tmp);
|
|
|
|
|
|
|
|
|
|
is(@{$content}, 2, 'two containers on workspace level');
|
|
|
|
|
$first = $content->[0];
|
|
|
|
|
$second = $content->[1];
|
|
|
|
|
|
|
|
|
|
is(@{$first->{nodes}}, 0, 'first container has no children');
|
|
|
|
|
isnt($second->{name}, $old_name, 'second container was replaced');
|
2011-01-07 14:48:01 -05:00
|
|
|
|
is($second->{orientation}, 'horizontal', 'orientation is horizontal');
|
2010-05-10 03:33:10 -04:00
|
|
|
|
is(@{$second->{nodes}}, 2, 'second container has 2 children');
|
|
|
|
|
is($second->{nodes}->[0]->{name}, $old_name, 'found old second container');
|
|
|
|
|
|
|
|
|
|
# TODO: extend this test-case (test next/prev)
|
|
|
|
|
# - wrapping (no horizontal switch possible, goes level-up)
|
|
|
|
|
# - going level-up "manually"
|
|
|
|
|
|
2010-06-01 16:29:19 -04:00
|
|
|
|
######################################################################
|
|
|
|
|
# Test splitting multiple times without actually creating windows
|
|
|
|
|
######################################################################
|
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
|
$tmp = fresh_workspace;
|
2010-06-01 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
$ws = get_ws($tmp);
|
2011-01-07 14:48:01 -05:00
|
|
|
|
is($ws->{orientation}, 'horizontal', 'orientation horizontal by default');
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'split v';
|
2010-06-01 16:29:19 -04:00
|
|
|
|
$ws = get_ws($tmp);
|
2011-01-07 14:48:01 -05:00
|
|
|
|
is($ws->{orientation}, 'vertical', 'split v changes workspace orientation');
|
2010-06-01 16:29:19 -04:00
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'open';
|
2010-06-01 16:29:19 -04:00
|
|
|
|
my @content = @{get_ws_content($tmp)};
|
|
|
|
|
|
|
|
|
|
# recursively sums up all nodes and their children
|
|
|
|
|
sub sum_nodes {
|
|
|
|
|
my ($nodes) = @_;
|
|
|
|
|
|
|
|
|
|
return 0 if !@{$nodes};
|
|
|
|
|
|
|
|
|
|
my @children = (map { @{$_->{nodes}} } @{$nodes},
|
2010-11-21 10:34:45 -05:00
|
|
|
|
map { @{$_->{'floating_nodes'}} } @{$nodes});
|
2010-06-01 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
return @{$nodes} + sum_nodes(\@children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $old_count = sum_nodes(\@content);
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'split v';
|
2010-06-01 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
@content = @{get_ws_content($tmp)};
|
2010-08-21 12:25:48 -04:00
|
|
|
|
$old_count = sum_nodes(\@content);
|
2010-06-01 16:29:19 -04:00
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
|
cmd 'split v';
|
2010-06-01 16:29:19 -04:00
|
|
|
|
|
|
|
|
|
@content = @{get_ws_content($tmp)};
|
|
|
|
|
my $count = sum_nodes(\@content);
|
|
|
|
|
is($count, $old_count, 'not more windows after splitting again');
|
2010-05-10 03:33:10 -04:00
|
|
|
|
|
2012-01-30 11:13:44 -05:00
|
|
|
|
######################################################################
|
|
|
|
|
# In the special case of being inside a stacked or tabbed container, we don’t
|
|
|
|
|
# want this to happen.
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
|
|
$tmp = fresh_workspace;
|
|
|
|
|
|
|
|
|
|
cmd 'open';
|
|
|
|
|
@content = @{get_ws_content($tmp)};
|
|
|
|
|
is(scalar @content, 1, 'Precisely one container on this ws');
|
|
|
|
|
cmd 'layout stacked';
|
|
|
|
|
@content = @{get_ws_content($tmp)};
|
|
|
|
|
is(scalar @content, 1, 'Still one container on this ws');
|
|
|
|
|
is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con has one child node');
|
|
|
|
|
|
|
|
|
|
cmd 'split h';
|
|
|
|
|
cmd 'open';
|
|
|
|
|
@content = @{get_ws_content($tmp)};
|
|
|
|
|
is(scalar @content, 1, 'Still one container on this ws');
|
|
|
|
|
is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con still has one child node');
|
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
|
done_testing;
|