i3/testcases/t/122-split.t
Michael Stapelberg de94f6da1a Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.

The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").

To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.

The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.

As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).

AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).

Fixes #464
2012-08-04 03:13:24 +02:00

123 lines
3.6 KiB
Perl
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!perl
# vim:ts=4:sw=4:expandtab
#
# Tests splitting
#
use i3test;
my $tmp;
my $ws;
################################################################################
# Open two containers, split, open another container. Then verify
# the layout is like we expect it to be
################################################################################
sub verify_split_layout {
my (%args) = @_;
$tmp = fresh_workspace;
$ws = get_ws($tmp);
is($ws->{layout}, 'splith', 'orientation horizontal by default');
cmd 'split v';
$ws = get_ws($tmp);
is($ws->{layout}, 'splitv', 'split v changes workspace orientation');
cmd 'open';
cmd 'open';
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};
cmd $args{split_command};
cmd 'open';
$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');
is($second->{layout}, 'splith', 'orientation is horizontal');
is(@{$second->{nodes}}, 2, 'second container has 2 children');
is($second->{nodes}->[0]->{name}, $old_name, 'found old second container');
}
verify_split_layout(split_command => 'split h');
verify_split_layout(split_command => 'split horizontal');
# TODO: extend this test-case (test next/prev)
# - wrapping (no horizontal switch possible, goes level-up)
# - going level-up "manually"
######################################################################
# Test splitting multiple times without actually creating windows
######################################################################
$tmp = fresh_workspace;
$ws = get_ws($tmp);
is($ws->{layout}, 'splith', 'orientation horizontal by default');
cmd 'split v';
$ws = get_ws($tmp);
is($ws->{layout}, 'splitv', 'split v changes workspace orientation');
cmd 'open';
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},
map { @{$_->{'floating_nodes'}} } @{$nodes});
return @{$nodes} + sum_nodes(\@children);
}
my $old_count = sum_nodes(\@content);
cmd 'split v';
@content = @{get_ws_content($tmp)};
$old_count = sum_nodes(\@content);
cmd 'split v';
@content = @{get_ws_content($tmp)};
my $count = sum_nodes(\@content);
is($count, $old_count, 'not more windows after splitting again');
######################################################################
# In the special case of being inside a stacked or tabbed container, we dont
# 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');
done_testing;