2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests resizing tiling containers
20 my $tmp = fresh_workspace;
24 my $top = open_window;
25 my $bottom = open_window;
27 diag("top = " . $top->id . ", bottom = " . $bottom->id);
29 is($x->input_focus, $bottom->id, 'Bottom window focused');
31 ############################################################
33 ############################################################
35 cmd 'resize grow up 10 px or 25 ppt';
37 my ($nodes, $focus) = get_ws_content($tmp);
39 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
40 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
43 ############################################################
44 # split and check if the 'percent' factor is still correct
45 ############################################################
49 ($nodes, $focus) = get_ws_content($tmp);
51 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
52 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
54 ############################################################
55 # checks that resizing within stacked/tabbed cons works
56 ############################################################
58 $tmp = fresh_workspace;
63 $bottom = open_window;
68 ($nodes, $focus) = get_ws_content($tmp);
69 cmp_float($nodes->[0]->{percent}, 0.5, 'top window got 50%');
70 cmp_float($nodes->[1]->{percent}, 0.5, 'bottom window got 50%');
72 cmd 'resize grow up 10 px or 25 ppt';
74 ($nodes, $focus) = get_ws_content($tmp);
75 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got 25%');
76 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
78 ############################################################
79 # Checks that resizing in the parent's parent's orientation works.
80 # Take for example a horizontal workspace with one window on the left side and
81 # a v-split container with two windows on the right side. Focus is on the
82 # bottom right window, use 'resize left'.
83 ############################################################
85 $tmp = fresh_workspace;
87 my $left = open_window;
88 my $right = open_window;
93 $bottom = open_window;
95 ($nodes, $focus) = get_ws_content($tmp);
96 cmp_float($nodes->[0]->{percent}, 0.5, 'left window got 50%');
97 cmp_float($nodes->[1]->{percent}, 0.5, 'right window got 50%');
99 cmd 'resize grow left 10 px or 25 ppt';
101 ($nodes, $focus) = get_ws_content($tmp);
102 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
103 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
105 ################################################################################
106 # Check that the resize grow/shrink width/height syntax works.
107 ################################################################################
110 $tmp = fresh_workspace;
113 $right = open_window;
115 cmd 'resize grow width 10 px or 25 ppt';
117 ($nodes, $focus) = get_ws_content($tmp);
118 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
119 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
121 # Now test it with four windows
122 $tmp = fresh_workspace;
124 open_window for (1..4);
126 cmd 'resize grow width 10 px or 25 ppt';
128 ($nodes, $focus) = get_ws_content($tmp);
129 cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
130 cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
131 cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
132 cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');
134 # height should be a no-op in this situation
135 cmd 'resize grow height 10 px or 25 ppt';
137 ($nodes, $focus) = get_ws_content($tmp);
138 cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
139 cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
140 cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
141 cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');
144 ############################################################
145 # checks that resizing floating windows works
146 ############################################################
148 $tmp = fresh_workspace;
152 cmd 'floating enable';
154 my @content = @{get_ws($tmp)->{floating_nodes}};
155 cmp_ok(@content, '==', 1, 'one floating node on this ws');
158 my $oldrect = $content[0]->{rect};
160 cmd 'resize grow up 10 px or 25 ppt';
162 @content = @{get_ws($tmp)->{floating_nodes}};
163 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
164 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
165 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
166 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
167 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
168 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
170 # up, but with a different amount of px
171 $oldrect = $content[0]->{rect};
173 cmd 'resize grow up 12 px or 25 ppt';
175 @content = @{get_ws($tmp)->{floating_nodes}};
176 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
177 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
178 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
179 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
180 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
181 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
184 $oldrect = $content[0]->{rect};
186 cmd 'resize grow left 10 px or 25 ppt';
188 @content = @{get_ws($tmp)->{floating_nodes}};
189 cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
190 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
193 $oldrect = $content[0]->{rect};
195 cmd 'resize grow right 10 px or 25 ppt';
197 @content = @{get_ws($tmp)->{floating_nodes}};
198 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
199 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
200 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
201 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
204 $oldrect = $content[0]->{rect};
206 cmd 'resize grow down 10 px or 25 ppt';
208 @content = @{get_ws($tmp)->{floating_nodes}};
209 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
210 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
211 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
212 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
215 $oldrect = $content[0]->{rect};
217 cmd 'resize grow width 10px or 10ppt';
219 @content = @{get_ws($tmp)->{floating_nodes}};
220 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
221 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
222 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
223 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
226 $oldrect = $content[0]->{rect};
228 cmd 'resize shrink width 10px or 10ppt';
230 @content = @{get_ws($tmp)->{floating_nodes}};
231 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
232 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
233 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
234 cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');
237 $oldrect = $content[0]->{rect};
239 cmd 'resize grow height 10px or 10ppt';
241 @content = @{get_ws($tmp)->{floating_nodes}};
242 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
243 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
244 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
245 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
248 $oldrect = $content[0]->{rect};
250 cmd 'resize shrink height 10px or 10ppt';
252 @content = @{get_ws($tmp)->{floating_nodes}};
253 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
254 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
255 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
256 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
258 ################################################################################
259 # Check that resizing with criteria works
260 ################################################################################
262 $tmp = fresh_workspace;
264 my $left = open_floating_window;
265 my $right = open_floating_window;
267 sub get_floating_rect {
268 my ($window_id) = @_;
270 my $floating_nodes = get_ws($tmp)->{floating_nodes};
271 for my $floating_node (@$floating_nodes) {
272 # Get all the windows within that floating container
273 my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
274 if ($window_id ~~ @window_ids) {
275 return $floating_node->{rect};
282 # focus is on the right window, so we resize the left one using criteria
283 my $leftold = get_floating_rect($left->id);
284 my $rightold = get_floating_rect($right->id);
285 cmd '[id="' . $left->id . '"] resize shrink height 10px or 10ppt';
287 my $leftnew = get_floating_rect($left->id);
288 my $rightnew = get_floating_rect($right->id);
289 is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
290 is($leftnew->{height}, $leftold->{height} - 10, 'height of left container changed');