]> git.sur5r.net Git - i3/i3/blob - testcases/t/141-resize.t
Make cmd_resize_tiling_direction work with pixels
[i3/i3] / testcases / t / 141-resize.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests resizing tiling containers
18 use i3test;
19
20 my ($left, $right);
21 my $tmp = fresh_workspace;
22
23 cmd 'split v';
24
25 my $top = open_window;
26 my $bottom = open_window;
27
28 diag("top = " . $top->id . ", bottom = " . $bottom->id);
29
30 is($x->input_focus, $bottom->id, 'Bottom window focused');
31
32 ############################################################
33 # resize
34 ############################################################
35
36 cmd 'resize grow up 10 px or 25 ppt';
37
38 my ($nodes, $focus) = get_ws_content($tmp);
39
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%');
42
43
44 ############################################################
45 # split and check if the 'percent' factor is still correct
46 ############################################################
47
48 cmd 'split h';
49
50 ($nodes, $focus) = get_ws_content($tmp);
51
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%');
54
55 ############################################################
56 # checks that resizing within stacked/tabbed cons works
57 ############################################################
58
59 $tmp = fresh_workspace;
60
61 cmd 'split v';
62
63 $top = open_window;
64 $bottom = open_window;
65
66 cmd 'split h';
67 cmd 'layout stacked';
68
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%');
72
73 cmd 'resize grow up 10 px or 25 ppt';
74
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%');
78
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 ############################################################
85
86 $tmp = fresh_workspace;
87
88 $left = open_window;
89 $right = open_window;
90
91 cmd 'split v';
92
93 $top = open_window;
94 $bottom = open_window;
95
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%');
99
100 cmd 'resize grow left 10 px or 25 ppt';
101
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%');
105
106 ################################################################################
107 # Check that the resize grow/shrink width/height syntax works.
108 ################################################################################
109
110 # Use two windows
111 $tmp = fresh_workspace;
112
113 $left = open_window;
114 $right = open_window;
115
116 cmd 'resize grow width 10 px or 25 ppt';
117
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%');
121
122 # Now test it with four windows
123 $tmp = fresh_workspace;
124
125 open_window for (1..4);
126
127 cmd 'resize grow width 10 px or 25 ppt';
128
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%');
134
135 # height should be a no-op in this situation
136 cmd 'resize grow height 10 px or 25 ppt';
137
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%');
143
144 ################################################################################
145 # Check that we can grow tiled windows by pixels
146 ################################################################################
147
148 $tmp = fresh_workspace;
149
150 $left = open_window;
151 $right = open_window;
152
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');
156
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');
161
162 ################################################################################
163 # Check that we can shrink tiled windows by pixels
164 ################################################################################
165
166 $tmp = fresh_workspace;
167
168 $left = open_window;
169 $right = open_window;
170
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');
174
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');
179
180
181 ################################################################################
182 # Check that we can shrink vertical tiled windows by pixels
183 ################################################################################
184
185 $tmp = fresh_workspace;
186
187 cmd 'split v';
188
189 $top = open_window;
190 $bottom = open_window;
191
192 ($nodes, $focus) = get_ws_content($tmp);
193 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
194
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');
199
200 ################################################################################
201 # Check that we can shrink vertical tiled windows by pixels
202 ################################################################################
203
204 $tmp = fresh_workspace;
205
206 cmd 'split v';
207
208 $top = open_window;
209 $bottom = open_window;
210
211 ($nodes, $focus) = get_ws_content($tmp);
212 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
213
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');
218
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 ################################################################################
223
224 $tmp = fresh_workspace;
225 $left = open_window;
226 $right = open_window;
227
228 cmd 'split h';
229 cmd 'resize grow width 10px or 25 ppt';
230
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%');
234
235 ############################################################
236 # checks that resizing floating windows works
237 ############################################################
238
239 $tmp = fresh_workspace;
240
241 $top = open_window;
242
243 cmd 'floating enable';
244
245 my @content = @{get_ws($tmp)->{floating_nodes}};
246 cmp_ok(@content, '==', 1, 'one floating node on this ws');
247
248 # up
249 my $oldrect = $content[0]->{rect};
250
251 cmd 'resize grow up 10 px or 25 ppt';
252
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');
260
261 # up, but with a different amount of px
262 $oldrect = $content[0]->{rect};
263
264 cmd 'resize grow up 12 px or 25 ppt';
265
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');
273
274 # left
275 $oldrect = $content[0]->{rect};
276
277 cmd 'resize grow left 10 px or 25 ppt';
278
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');
282
283 # right
284 $oldrect = $content[0]->{rect};
285
286 cmd 'resize grow right 10 px or 25 ppt';
287
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');
293
294 # down
295 $oldrect = $content[0]->{rect};
296
297 cmd 'resize grow down 10 px or 25 ppt';
298
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');
304
305 # grow width
306 $oldrect = $content[0]->{rect};
307
308 cmd 'resize grow width 10px or 10ppt';
309
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');
315
316 # shrink width
317 $oldrect = $content[0]->{rect};
318
319 cmd 'resize shrink width 10px or 10ppt';
320
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');
326
327 # grow height
328 $oldrect = $content[0]->{rect};
329
330 cmd 'resize grow height 10px or 10ppt';
331
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');
337
338 # shrink height
339 $oldrect = $content[0]->{rect};
340
341 cmd 'resize shrink height 10px or 10ppt';
342
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');
348
349 ################################################################################
350 # Check that resizing with criteria works
351 ################################################################################
352
353 $tmp = fresh_workspace;
354
355 $left = open_floating_window;
356 $right = open_floating_window;
357
358 sub get_floating_rect {
359     my ($window_id) = @_;
360
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};
367         }
368     }
369
370     return undef;
371 }
372
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';
377
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');
382
383 done_testing;