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
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 the resize grow/shrink width/height syntax works if a nested split
146 # was set on the container, but no sibling has been opened yet. See #2015.
147 ################################################################################
149 $tmp = fresh_workspace;
151 $right = open_window;
154 cmd 'resize grow width 10px or 25 ppt';
156 ($nodes, $focus) = get_ws_content($tmp);
157 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
158 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
160 ############################################################
161 # checks that resizing floating windows works
162 ############################################################
164 $tmp = fresh_workspace;
168 cmd 'floating enable';
170 my @content = @{get_ws($tmp)->{floating_nodes}};
171 cmp_ok(@content, '==', 1, 'one floating node on this ws');
174 my $oldrect = $content[0]->{rect};
176 cmd 'resize grow up 10 px or 25 ppt';
178 @content = @{get_ws($tmp)->{floating_nodes}};
179 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
180 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
181 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
182 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
183 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
184 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
186 # up, but with a different amount of px
187 $oldrect = $content[0]->{rect};
189 cmd 'resize grow up 12 px or 25 ppt';
191 @content = @{get_ws($tmp)->{floating_nodes}};
192 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
193 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
194 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
195 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
196 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
197 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
200 $oldrect = $content[0]->{rect};
202 cmd 'resize grow left 10 px or 25 ppt';
204 @content = @{get_ws($tmp)->{floating_nodes}};
205 cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
206 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
209 $oldrect = $content[0]->{rect};
211 cmd 'resize grow right 10 px or 25 ppt';
213 @content = @{get_ws($tmp)->{floating_nodes}};
214 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
215 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
216 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
217 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
220 $oldrect = $content[0]->{rect};
222 cmd 'resize grow down 10 px or 25 ppt';
224 @content = @{get_ws($tmp)->{floating_nodes}};
225 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
226 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
227 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
228 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
231 $oldrect = $content[0]->{rect};
233 cmd 'resize grow width 10px or 10ppt';
235 @content = @{get_ws($tmp)->{floating_nodes}};
236 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
237 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
238 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
239 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
242 $oldrect = $content[0]->{rect};
244 cmd 'resize shrink width 10px or 10ppt';
246 @content = @{get_ws($tmp)->{floating_nodes}};
247 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
248 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
249 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
250 cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');
253 $oldrect = $content[0]->{rect};
255 cmd 'resize grow height 10px or 10ppt';
257 @content = @{get_ws($tmp)->{floating_nodes}};
258 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
259 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
260 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
261 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
264 $oldrect = $content[0]->{rect};
266 cmd 'resize shrink height 10px or 10ppt';
268 @content = @{get_ws($tmp)->{floating_nodes}};
269 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
270 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
271 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
272 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
274 ################################################################################
275 # Check that resizing with criteria works
276 ################################################################################
278 $tmp = fresh_workspace;
280 $left = open_floating_window;
281 $right = open_floating_window;
283 sub get_floating_rect {
284 my ($window_id) = @_;
286 my $floating_nodes = get_ws($tmp)->{floating_nodes};
287 for my $floating_node (@$floating_nodes) {
288 # Get all the windows within that floating container
289 my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
290 if ($window_id ~~ @window_ids) {
291 return $floating_node->{rect};
298 # focus is on the right window, so we resize the left one using criteria
299 my $leftold = get_floating_rect($left->id);
300 my $rightold = get_floating_rect($right->id);
301 cmd '[id="' . $left->id . '"] resize grow height 10px or 10ppt';
303 my $leftnew = get_floating_rect($left->id);
304 my $rightnew = get_floating_rect($right->id);
305 is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
306 is($leftnew->{height}, $leftold->{height} + 10, 'height of left container changed');