]> git.sur5r.net Git - i3/i3/blob - testcases/t/141-resize.t
Merge branch 'fix-split-indicator'
[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 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 $tmp = fresh_workspace;
21
22 cmd 'split v';
23
24 my $top = open_window;
25 my $bottom = open_window;
26
27 diag("top = " . $top->id . ", bottom = " . $bottom->id);
28
29 is($x->input_focus, $bottom->id, 'Bottom window focused');
30
31 ############################################################
32 # resize
33 ############################################################
34
35 cmd 'resize grow up 10 px or 25 ppt';
36
37 my ($nodes, $focus) = get_ws_content($tmp);
38
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%');
41
42
43 ############################################################
44 # split and check if the 'percent' factor is still correct
45 ############################################################
46
47 cmd 'split h';
48
49 ($nodes, $focus) = get_ws_content($tmp);
50
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%');
53
54 ############################################################
55 # checks that resizing within stacked/tabbed cons works
56 ############################################################
57
58 $tmp = fresh_workspace;
59
60 cmd 'split v';
61
62 $top = open_window;
63 $bottom = open_window;
64
65 cmd 'split h';
66 cmd 'layout stacked';
67
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%');
71
72 cmd 'resize grow up 10 px or 25 ppt';
73
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%');
77
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 ############################################################
84
85 $tmp = fresh_workspace;
86
87 my $left = open_window;
88 my $right = open_window;
89
90 cmd 'split v';
91
92 $top = open_window;
93 $bottom = open_window;
94
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%');
98
99 cmd 'resize grow left 10 px or 25 ppt';
100
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%');
104
105 ################################################################################
106 # Check that the resize grow/shrink width/height syntax works.
107 ################################################################################
108
109 # Use two windows
110 $tmp = fresh_workspace;
111
112 $left = open_window;
113 $right = open_window;
114
115 cmd 'resize grow width 10 px or 25 ppt';
116
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%');
120
121 # Now test it with four windows
122 $tmp = fresh_workspace;
123
124 open_window for (1..4);
125
126 cmd 'resize grow width 10 px or 25 ppt';
127
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%');
133
134 # height should be a no-op in this situation
135 cmd 'resize grow height 10 px or 25 ppt';
136
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%');
142
143
144 ############################################################
145 # checks that resizing floating windows works
146 ############################################################
147
148 $tmp = fresh_workspace;
149
150 $top = open_window;
151
152 cmd 'floating enable';
153
154 my @content = @{get_ws($tmp)->{floating_nodes}};
155 cmp_ok(@content, '==', 1, 'one floating node on this ws');
156
157 # up
158 my $oldrect = $content[0]->{rect};
159
160 cmd 'resize grow up 10 px or 25 ppt';
161
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');
169
170 # up, but with a different amount of px
171 $oldrect = $content[0]->{rect};
172
173 cmd 'resize grow up 12 px or 25 ppt';
174
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');
182
183 # left
184 $oldrect = $content[0]->{rect};
185
186 cmd 'resize grow left 10 px or 25 ppt';
187
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');
191
192 # right
193 $oldrect = $content[0]->{rect};
194
195 cmd 'resize grow right 10 px or 25 ppt';
196
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');
202
203 # down
204 $oldrect = $content[0]->{rect};
205
206 cmd 'resize grow down 10 px or 25 ppt';
207
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');
213
214 # grow width
215 $oldrect = $content[0]->{rect};
216
217 cmd 'resize grow width 10px or 10ppt';
218
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');
224
225 # shrink width
226 $oldrect = $content[0]->{rect};
227
228 cmd 'resize shrink width 10px or 10ppt';
229
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');
235
236 # grow height
237 $oldrect = $content[0]->{rect};
238
239 cmd 'resize grow height 10px or 10ppt';
240
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');
246
247 # shrink height
248 $oldrect = $content[0]->{rect};
249
250 cmd 'resize shrink height 10px or 10ppt';
251
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');
257
258 done_testing;