2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://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
21 my $tmp = fresh_workspace;
25 my $top = open_window;
26 my $bottom = open_window;
28 diag("top = " . $top->id . ", bottom = " . $bottom->id);
30 is($x->input_focus, $bottom->id, 'Bottom window focused');
32 ############################################################
34 ############################################################
36 cmd 'resize grow up 10 px or 25 ppt';
38 my ($nodes, $focus) = get_ws_content($tmp);
40 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
41 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
44 ############################################################
45 # split and check if the 'percent' factor is still correct
46 ############################################################
50 ($nodes, $focus) = get_ws_content($tmp);
52 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
53 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
55 ############################################################
56 # checks that resizing within stacked/tabbed cons works
57 ############################################################
59 $tmp = fresh_workspace;
64 $bottom = open_window;
69 ($nodes, $focus) = get_ws_content($tmp);
70 cmp_float($nodes->[0]->{percent}, 0.5, 'top window got 50%');
71 cmp_float($nodes->[1]->{percent}, 0.5, 'bottom window got 50%');
73 cmd 'resize grow up 10 px or 25 ppt';
75 ($nodes, $focus) = get_ws_content($tmp);
76 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got 25%');
77 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
79 ############################################################
80 # Checks that resizing in the parent's parent's orientation works.
81 # Take for example a horizontal workspace with one window on the left side and
82 # a v-split container with two windows on the right side. Focus is on the
83 # bottom right window, use 'resize left'.
84 ############################################################
86 $tmp = fresh_workspace;
94 $bottom = open_window;
96 ($nodes, $focus) = get_ws_content($tmp);
97 cmp_float($nodes->[0]->{percent}, 0.5, 'left window got 50%');
98 cmp_float($nodes->[1]->{percent}, 0.5, 'right window got 50%');
100 cmd 'resize grow left 10 px or 25 ppt';
102 ($nodes, $focus) = get_ws_content($tmp);
103 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
104 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
106 ################################################################################
107 # Check that the resize grow/shrink width/height syntax works.
108 ################################################################################
111 $tmp = fresh_workspace;
114 $right = open_window;
116 cmd 'resize grow width 10 px or 25 ppt';
118 ($nodes, $focus) = get_ws_content($tmp);
119 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
120 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
122 # Now test it with four windows
123 $tmp = fresh_workspace;
125 open_window for (1..4);
127 cmd 'resize grow width 10 px or 25 ppt';
129 ($nodes, $focus) = get_ws_content($tmp);
130 cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
131 cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
132 cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
133 cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');
135 # height should be a no-op in this situation
136 cmd 'resize grow height 10 px or 25 ppt';
138 ($nodes, $focus) = get_ws_content($tmp);
139 cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
140 cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
141 cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
142 cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');
144 ################################################################################
145 # Check that we can grow tiled windows by pixels
146 ################################################################################
148 $tmp = fresh_workspace;
151 $right = open_window;
153 ($nodes, $focus) = get_ws_content($tmp);
154 cmp_float($nodes->[0]->{rect}->{width}, 640, 'left window is 640px');
155 cmp_float($nodes->[1]->{rect}->{width}, 640, 'right window is 640px');
157 cmd 'resize grow left 10px';
158 ($nodes, $focus) = get_ws_content($tmp);
159 cmp_float($nodes->[0]->{rect}->{width}, 630, 'left window is 630px');
160 cmp_float($nodes->[1]->{rect}->{width}, 650, 'right window is 650px');
162 ################################################################################
163 # Check that we can shrink tiled windows by pixels
164 ################################################################################
166 $tmp = fresh_workspace;
169 $right = open_window;
171 ($nodes, $focus) = get_ws_content($tmp);
172 cmp_float($nodes->[0]->{rect}->{width}, 640, 'left window is 640px');
173 cmp_float($nodes->[1]->{rect}->{width}, 640, 'right window is 640px');
175 cmd 'resize shrink left 10px';
176 ($nodes, $focus) = get_ws_content($tmp);
177 cmp_float($nodes->[0]->{rect}->{width}, 650, 'left window is 650px');
178 cmp_float($nodes->[1]->{rect}->{width}, 630, 'right window is 630px');
181 ################################################################################
182 # Check that we can shrink vertical tiled windows by pixels
183 ################################################################################
185 $tmp = fresh_workspace;
190 $bottom = open_window;
192 ($nodes, $focus) = get_ws_content($tmp);
193 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
195 cmd 'resize grow up 10px';
196 ($nodes, $focus) = get_ws_content($tmp);
197 cmp_float($nodes->[0]->{rect}->{height}, $heights[0] - 10, 'top window is 10px larger');
198 cmp_float($nodes->[1]->{rect}->{height}, $heights[1] + 10, 'bottom window is 10px smaller');
200 ################################################################################
201 # Check that we can shrink vertical tiled windows by pixels
202 ################################################################################
204 $tmp = fresh_workspace;
209 $bottom = open_window;
211 ($nodes, $focus) = get_ws_content($tmp);
212 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
214 cmd 'resize shrink up 10px';
215 ($nodes, $focus) = get_ws_content($tmp);
216 cmp_float($nodes->[0]->{rect}->{height}, $heights[0] + 10, 'top window is 10px smaller');
217 cmp_float($nodes->[1]->{rect}->{height}, $heights[1] - 10, 'bottom window is 10px larger');
219 ################################################################################
220 # Check that the resize grow/shrink width/height syntax works if a nested split
221 # was set on the container, but no sibling has been opened yet. See #2015.
222 ################################################################################
224 $tmp = fresh_workspace;
226 $right = open_window;
229 cmd 'resize grow width 10px or 25 ppt';
231 ($nodes, $focus) = get_ws_content($tmp);
232 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
233 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
235 ############################################################
236 # checks that resizing floating windows works
237 ############################################################
239 $tmp = fresh_workspace;
243 cmd 'floating enable';
245 my @content = @{get_ws($tmp)->{floating_nodes}};
246 cmp_ok(@content, '==', 1, 'one floating node on this ws');
249 my $oldrect = $content[0]->{rect};
251 cmd 'resize grow up 10 px or 25 ppt';
253 @content = @{get_ws($tmp)->{floating_nodes}};
254 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
255 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
256 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
257 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
258 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
259 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
261 # up, but with a different amount of px
262 $oldrect = $content[0]->{rect};
264 cmd 'resize grow up 12 px or 25 ppt';
266 @content = @{get_ws($tmp)->{floating_nodes}};
267 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
268 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
269 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
270 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
271 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
272 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
275 $oldrect = $content[0]->{rect};
277 cmd 'resize grow left 10 px or 25 ppt';
279 @content = @{get_ws($tmp)->{floating_nodes}};
280 cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
281 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
284 $oldrect = $content[0]->{rect};
286 cmd 'resize grow right 10 px or 25 ppt';
288 @content = @{get_ws($tmp)->{floating_nodes}};
289 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
290 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
291 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
292 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
295 $oldrect = $content[0]->{rect};
297 cmd 'resize grow down 10 px or 25 ppt';
299 @content = @{get_ws($tmp)->{floating_nodes}};
300 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
301 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
302 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
303 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
306 $oldrect = $content[0]->{rect};
308 cmd 'resize grow width 10px or 10ppt';
310 @content = @{get_ws($tmp)->{floating_nodes}};
311 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
312 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
313 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
314 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
317 $oldrect = $content[0]->{rect};
319 cmd 'resize shrink width 10px or 10ppt';
321 @content = @{get_ws($tmp)->{floating_nodes}};
322 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
323 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
324 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
325 cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');
328 $oldrect = $content[0]->{rect};
330 cmd 'resize grow height 10px or 10ppt';
332 @content = @{get_ws($tmp)->{floating_nodes}};
333 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
334 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
335 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
336 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
339 $oldrect = $content[0]->{rect};
341 cmd 'resize shrink height 10px or 10ppt';
343 @content = @{get_ws($tmp)->{floating_nodes}};
344 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
345 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
346 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
347 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
349 ################################################################################
350 # Check that resizing with criteria works
351 ################################################################################
353 $tmp = fresh_workspace;
355 $left = open_floating_window;
356 $right = open_floating_window;
358 sub get_floating_rect {
359 my ($window_id) = @_;
361 my $floating_nodes = get_ws($tmp)->{floating_nodes};
362 for my $floating_node (@$floating_nodes) {
363 # Get all the windows within that floating container
364 my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
365 if ($window_id ~~ @window_ids) {
366 return $floating_node->{rect};
373 # focus is on the right window, so we resize the left one using criteria
374 my $leftold = get_floating_rect($left->id);
375 my $rightold = get_floating_rect($right->id);
376 cmd '[id="' . $left->id . '"] resize grow height 10px or 10ppt';
378 my $leftnew = get_floating_rect($left->id);
379 my $rightnew = get_floating_rect($right->id);
380 is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
381 is($leftnew->{height}, $leftold->{height} + 10, 'height of left container changed');