]> git.sur5r.net Git - i3/i3/blob - testcases/t/167-workspace_layout.t
Add regression tests for #2846
[i3/i3] / testcases / t / 167-workspace_layout.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 the workspace_layout config option.
18 #
19
20 use i3test i3_autostart => 0;
21
22 #####################################################################
23 # 1: check that with an empty config, cons are place next to each
24 # other and no split containers are created
25 #####################################################################
26
27 my $config = <<EOT;
28 # i3 config file (v4)
29 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
30 EOT
31
32 my $pid = launch_with_config($config);
33
34 my $tmp = fresh_workspace;
35
36 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
37
38 my $first = open_window;
39 my $second = open_window;
40
41 is($x->input_focus, $second->id, 'second window focused');
42 my @content = @{get_ws_content($tmp)};
43 ok(@content == 2, 'two containers opened');
44 isnt($content[0]->{layout}, 'stacked', 'layout not stacked');
45 isnt($content[1]->{layout}, 'stacked', 'layout not stacked');
46
47 exit_gracefully($pid);
48
49 #####################################################################
50 # 2: set workspace_layout stacked, check that when opening two cons,
51 # they end up in a stacked con
52 #####################################################################
53
54 $config = <<EOT;
55 # i3 config file (v4)
56 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
57 workspace_layout stacked
58 EOT
59
60 $pid = launch_with_config($config);
61
62 $tmp = fresh_workspace;
63
64 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
65
66 $first = open_window;
67 $second = open_window;
68
69 is($x->input_focus, $second->id, 'second window focused');
70 @content = @{get_ws_content($tmp)};
71 ok(@content == 1, 'one con at workspace level');
72 is($content[0]->{layout}, 'stacked', 'layout stacked');
73
74 #####################################################################
75 # 3: focus parent, open two new cons, check that they end up in a stacked
76 # con
77 #####################################################################
78
79 cmd 'focus parent';
80 my $right_top = open_window;
81 my $right_bot = open_window;
82
83 @content = @{get_ws_content($tmp)};
84 is(@content, 2, 'two cons at workspace level after focus parent');
85 is($content[0]->{layout}, 'stacked', 'layout stacked');
86 is($content[1]->{layout}, 'stacked', 'layout stacked');
87
88 #####################################################################
89 # 4: move one of the cons to the right, check that it will end up in
90 # a stacked con
91 #####################################################################
92
93 cmd 'move right';
94
95 @content = @{get_ws_content($tmp)};
96 is(@content, 3, 'three cons at workspace level after move');
97 is($content[0]->{layout}, 'stacked', 'layout stacked');
98 is($content[1]->{layout}, 'stacked', 'layout stacked');
99 is($content[2]->{layout}, 'stacked', 'layout stacked');
100
101 #####################################################################
102 # 5: move it to the left again, check that the stacked con is deleted
103 #####################################################################
104
105 cmd 'move left';
106
107 @content = @{get_ws_content($tmp)};
108 is(@content, 2, 'two cons at workspace level after moving back');
109 is($content[0]->{layout}, 'stacked', 'layout stacked');
110 is($content[1]->{layout}, 'stacked', 'layout stacked');
111
112 #####################################################################
113 # 6: move it to a different workspace, check that it ends up in a
114 # stacked con
115 #####################################################################
116
117 my $otmp = get_unused_workspace;
118
119 cmd "move workspace $otmp";
120
121 @content = @{get_ws_content($tmp)};
122 is(@content, 2, 'still two cons on this workspace');
123 is($content[0]->{layout}, 'stacked', 'layout stacked');
124 is($content[1]->{layout}, 'stacked', 'layout stacked');
125
126 @content = @{get_ws_content($otmp)};
127 is(@content, 1, 'one con on target workspace');
128 is($content[0]->{layout}, 'stacked', 'layout stacked');
129
130 #####################################################################
131 # 7: toggle floating mode and check that we have a stacked con when
132 # re-inserting a floating container.
133 #####################################################################
134
135 $tmp = fresh_workspace;
136
137 $first = open_window;
138 cmd 'floating toggle';
139 cmd 'floating toggle';
140
141 $second = open_window;
142
143 is($x->input_focus, $second->id, 'second window focused');
144 @content = @{get_ws_content($tmp)};
145 ok(@content == 1, 'one con at workspace level');
146 is($content[0]->{layout}, 'stacked', 'layout stacked');
147
148 #####################################################################
149 # 8: when the workspace is empty check that its layout can be changed
150 # from stacked to horizontal split using the 'layout splith' command.
151 #####################################################################
152
153 $tmp = fresh_workspace;
154
155 cmd 'layout stacked';
156 $first = open_window;
157 $second = open_window;
158
159 @content = @{get_ws_content($tmp)};
160 is($content[0]->{layout}, 'stacked', 'layout stacked');
161
162 cmd '[id="' . $first->id . '"] kill';
163 cmd '[id="' . $second->id . '"] kill';
164 sync_with_i3;
165
166 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
167
168 cmd 'layout splith';
169 $first = open_window;
170 $second = open_window;
171 @content = @{get_ws_content($tmp)};
172 ok(@content == 2, 'two containers opened');
173 isnt($content[0]->{layout}, 'stacked', 'layout not stacked');
174 isnt($content[1]->{layout}, 'stacked', 'layout not stacked');
175
176 #####################################################################
177 # 9: when the workspace is empty check that its layout can be changed
178 # from stacked to vertical split using the 'layout splitv' command.
179 #####################################################################
180
181 $tmp = fresh_workspace;
182
183 cmd 'layout stacked';
184 $first = open_window;
185 $second = open_window;
186
187 @content = @{get_ws_content($tmp)};
188 is($content[0]->{layout}, 'stacked', 'layout stacked');
189
190 cmd '[id="' . $first->id . '"] kill';
191 cmd '[id="' . $second->id . '"] kill';
192 sync_with_i3;
193
194 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
195
196 cmd 'layout splitv';
197 $first = open_window;
198 $second = open_window;
199
200 @content = @{get_ws_content($tmp)};
201 ok(@content == 2, 'two containers opened');
202 isnt($content[0]->{layout}, 'stacked', 'layout not stacked');
203 isnt($content[1]->{layout}, 'stacked', 'layout not stacked');
204
205 #####################################################################
206 # 10: when the workspace is empty check that its layout can be changed
207 # from tabbed to horizontal split using the 'layout splith' command.
208 #####################################################################
209
210 $tmp = fresh_workspace;
211
212 cmd 'layout tabbed';
213 $first = open_window;
214 $second = open_window;
215
216 @content = @{get_ws_content($tmp)};
217 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
218
219 cmd '[id="' . $first->id . '"] kill';
220 cmd '[id="' . $second->id . '"] kill';
221 sync_with_i3;
222
223 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
224
225 cmd 'layout splith';
226 $first = open_window;
227 $second = open_window;
228
229 @content = @{get_ws_content($tmp)};
230 ok(@content == 2, 'two containers opened');
231 isnt($content[0]->{layout}, 'tabbed', 'layout not tabbed');
232 isnt($content[1]->{layout}, 'tabbed', 'layout not tabbed');
233
234 #####################################################################
235 # 11: when the workspace is empty check that its layout can be changed
236 # from tabbed to vertical split using the 'layout splitv' command.
237 #####################################################################
238
239 $tmp = fresh_workspace;
240
241 cmd 'layout tabbed';
242 $first = open_window;
243 $second = open_window;
244
245 @content = @{get_ws_content($tmp)};
246 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
247
248 cmd '[id="' . $first->id . '"] kill';
249 cmd '[id="' . $second->id . '"] kill';
250 sync_with_i3;
251
252 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
253
254 cmd 'layout splitv';
255 $first = open_window;
256 $second = open_window;
257
258 @content = @{get_ws_content($tmp)};
259 ok(@content == 2, 'two containers opened');
260 isnt($content[0]->{layout}, 'tabbed', 'layout not tabbed');
261 isnt($content[1]->{layout}, 'tabbed', 'layout not tabbed');
262
263 #####################################################################
264 # 12: when the workspace is empty check that its layout can be changed
265 # from stacked to horizontal split using the 'split horizontal' command.
266 #####################################################################
267
268 $tmp = fresh_workspace;
269
270 cmd 'layout stacked';
271 $first = open_window;
272 $second = open_window;
273
274 @content = @{get_ws_content($tmp)};
275 is($content[0]->{layout}, 'stacked', 'layout stacked');
276
277 cmd '[id="' . $first->id . '"] kill';
278 cmd '[id="' . $second->id . '"] kill';
279 sync_with_i3;
280
281 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
282
283 cmd 'split horizontal';
284 $first = open_window;
285 $second = open_window;
286 @content = @{get_ws_content($tmp)};
287 ok(@content == 2, 'two containers opened');
288 isnt($content[0]->{layout}, 'stacked', 'layout not stacked');
289 isnt($content[1]->{layout}, 'stacked', 'layout not stacked');
290
291 #####################################################################
292 # 13: when the workspace is empty check that its layout can be changed
293 # from stacked to vertical split using the 'split vertical' command.
294 #####################################################################
295
296 $tmp = fresh_workspace;
297
298 cmd 'layout stacked';
299 $first = open_window;
300 $second = open_window;
301
302 @content = @{get_ws_content($tmp)};
303 is($content[0]->{layout}, 'stacked', 'layout stacked');
304
305 cmd '[id="' . $first->id . '"] kill';
306 cmd '[id="' . $second->id . '"] kill';
307 sync_with_i3;
308
309 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
310
311 cmd 'split vertical';
312 $first = open_window;
313 $second = open_window;
314
315 @content = @{get_ws_content($tmp)};
316 ok(@content == 2, 'two containers opened');
317 isnt($content[0]->{layout}, 'stacked', 'layout not stacked');
318 isnt($content[1]->{layout}, 'stacked', 'layout not stacked');
319
320 #####################################################################
321 # 14: when the workspace is empty check that its layout can be changed
322 # from tabbed to horizontal split using the 'split horizontal' command.
323 #####################################################################
324
325 $tmp = fresh_workspace;
326
327 cmd 'layout tabbed';
328 $first = open_window;
329 $second = open_window;
330
331 @content = @{get_ws_content($tmp)};
332 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
333
334 cmd '[id="' . $first->id . '"] kill';
335 cmd '[id="' . $second->id . '"] kill';
336 sync_with_i3;
337
338 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
339
340 cmd 'split horizontal';
341 $first = open_window;
342 $second = open_window;
343
344 @content = @{get_ws_content($tmp)};
345 ok(@content == 2, 'two containers opened');
346 isnt($content[0]->{layout}, 'tabbed', 'layout not tabbed');
347 isnt($content[1]->{layout}, 'tabbed', 'layout not tabbed');
348
349 #####################################################################
350 # 15: when the workspace is empty check that its layout can be changed
351 # from tabbed to vertical split using the 'split vertical' command.
352 #####################################################################
353
354 $tmp = fresh_workspace;
355
356 cmd 'layout tabbed';
357 $first = open_window;
358 $second = open_window;
359
360 @content = @{get_ws_content($tmp)};
361 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
362
363 cmd '[id="' . $first->id . '"] kill';
364 cmd '[id="' . $second->id . '"] kill';
365 sync_with_i3;
366
367 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
368
369 cmd 'split vertical';
370 $first = open_window;
371 $second = open_window;
372
373 @content = @{get_ws_content($tmp)};
374 ok(@content == 2, 'two containers opened');
375 isnt($content[0]->{layout}, 'tabbed', 'layout not tabbed');
376 isnt($content[1]->{layout}, 'tabbed', 'layout not tabbed');
377
378 exit_gracefully($pid);
379
380 #####################################################################
381 # 16: Check that the command 'layout toggle split' works regardless
382 # of what layout we're using.
383 #####################################################################
384
385 $config = <<EOT;
386 # i3 config file (v4)
387 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
388 workspace_layout default
389 EOT
390
391 $pid = launch_with_config($config);
392
393 $tmp = fresh_workspace;
394
395 my @layouts = ('splith', 'splitv', 'tabbed', 'stacked');
396 my $first_layout;
397
398 foreach $first_layout (@layouts) {
399     cmd 'layout ' . $first_layout;
400     $first = open_window;
401     $second = open_window;
402     cmd 'layout toggle split';
403     @content = @{get_ws_content($tmp)};
404     if ($first_layout eq 'splith') {
405         is($content[0]->{layout}, 'splitv', 'layout toggles to splitv');
406     } else {
407         is($content[0]->{layout}, 'splith', 'layout toggles to splith');
408     }
409
410     cmd '[id="' . $first->id . '"] kill';
411     cmd '[id="' . $second->id . '"] kill';
412     sync_with_i3;
413 }
414
415 exit_gracefully($pid);
416
417 #####################################################################
418 # 17: Check about setting a new layout.
419 #####################################################################
420
421 $config = <<EOT;
422 # i3 config file (v4)
423 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
424 workspace_layout default
425 EOT
426
427 $pid = launch_with_config($config);
428
429 $tmp = fresh_workspace;
430
431 my $second_layout;
432
433 foreach $first_layout (@layouts) {
434     foreach $second_layout (@layouts) {
435         cmd 'layout ' . $first_layout;
436         $first = open_window;
437         $second = open_window;
438         cmd 'layout ' . $second_layout;
439         @content = @{get_ws_content($tmp)};
440         is($content[0]->{layout}, $second_layout, 'layout changes to ' . $second_layout);
441
442         cmd '[id="' . $first->id . '"] kill';
443         cmd '[id="' . $second->id . '"] kill';
444         sync_with_i3;
445     }
446 }
447
448 done_testing;