2 # vim:ts=4:sw=4:expandtab
7 use List::Util qw(first);
12 ################################################################################
13 # Open two containers, split, open another container. Then verify
14 # the layout is like we expect it to be
15 ################################################################################
17 sub verify_split_layout {
20 $tmp = fresh_workspace;
23 is($ws->{layout}, 'splith', 'orientation horizontal by default');
26 is($ws->{layout}, 'splitv', 'split v changes workspace orientation');
30 my $content = get_ws_content($tmp);
32 is(@{$content}, 2, 'two containers on workspace level');
33 my $first = $content->[0];
34 my $second = $content->[1];
36 is(@{$first->{nodes}}, 0, 'first container has no children');
37 is(@{$second->{nodes}}, 0, 'second container has no children (yet)');
38 my $old_name = $second->{name};
40 cmd $args{split_command};
43 $content = get_ws_content($tmp);
45 is(@{$content}, 2, 'two containers on workspace level');
46 $first = $content->[0];
47 $second = $content->[1];
49 is(@{$first->{nodes}}, 0, 'first container has no children');
50 isnt($second->{name}, $old_name, 'second container was replaced');
51 is($second->{layout}, 'splith', 'orientation is horizontal');
52 is(@{$second->{nodes}}, 2, 'second container has 2 children');
53 is($second->{nodes}->[0]->{name}, $old_name, 'found old second container');
56 verify_split_layout(split_command => 'split h');
57 verify_split_layout(split_command => 'split horizontal');
59 # TODO: extend this test-case (test next/prev)
60 # - wrapping (no horizontal switch possible, goes level-up)
61 # - going level-up "manually"
63 ######################################################################
64 # Test splitting multiple times without actually creating windows
65 ######################################################################
67 $tmp = fresh_workspace;
70 is($ws->{layout}, 'splith', 'orientation horizontal by default');
73 is($ws->{layout}, 'splitv', 'split v changes workspace orientation');
76 my @content = @{get_ws_content($tmp)};
78 # recursively sums up all nodes and their children
82 return 0 if !@{$nodes};
84 my @children = (map { @{$_->{nodes}} } @{$nodes},
85 map { @{$_->{'floating_nodes'}} } @{$nodes});
87 return @{$nodes} + sum_nodes(\@children);
90 my $old_count = sum_nodes(\@content);
93 @content = @{get_ws_content($tmp)};
94 $old_count = sum_nodes(\@content);
98 @content = @{get_ws_content($tmp)};
99 my $count = sum_nodes(\@content);
100 is($count, $old_count, 'not more windows after splitting again');
102 ######################################################################
103 # In the special case of being inside a stacked or tabbed container, we don’t
104 # want this to happen.
105 ######################################################################
107 $tmp = fresh_workspace;
110 @content = @{get_ws_content($tmp)};
111 is(scalar @content, 1, 'Precisely one container on this ws');
112 cmd 'layout stacked';
113 @content = @{get_ws_content($tmp)};
114 is(scalar @content, 1, 'Still one container on this ws');
115 is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con has one child node');
119 @content = @{get_ws_content($tmp)};
120 is(scalar @content, 1, 'Still one container on this ws');
121 is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con still has one child node');
123 ################################################################################
124 # When focusing the workspace, changing the layout should have an effect on the
125 # workspace, not on the parent (CT_CONTENT) container.
126 ################################################################################
128 sub get_output_content {
129 my $tree = i3(get_socket_path())->get_tree->recv;
131 my @outputs = grep { $_->{name} !~ /^__/ } @{$tree->{nodes}};
132 is(scalar @outputs, 1, 'exactly one output (testcase not multi-monitor capable)');
133 my $output = $outputs[0];
134 # get the first (and only) CT_CON
135 return first { $_->{type} == 2 } @{$output->{nodes}};
138 $tmp = fresh_workspace;
144 is(get_output_content()->{layout}, 'splith', 'content container layout ok');
145 cmd 'layout stacked';
146 is(get_output_content()->{layout}, 'splith', 'content container layout still ok');