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 the workspace_layout config option.
20 use i3test i3_autostart => 0;
22 #####################################################################
23 # 1: check that with an empty config, cons are place next to each
24 # other and no split containers are created
25 #####################################################################
29 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
32 my $pid = launch_with_config($config);
34 my $tmp = fresh_workspace;
36 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
38 my $first = open_window;
39 my $second = open_window;
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');
47 exit_gracefully($pid);
49 #####################################################################
50 # 2: set workspace_layout stacked, check that when opening two cons,
51 # they end up in a stacked con
52 #####################################################################
56 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
57 workspace_layout stacked
60 $pid = launch_with_config($config);
62 $tmp = fresh_workspace;
64 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
67 $second = open_window;
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');
74 #####################################################################
75 # 3: focus parent, open two new cons, check that they end up in a stacked
77 #####################################################################
80 my $right_top = open_window;
81 my $right_bot = open_window;
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');
88 #####################################################################
89 # 4: move one of the cons to the right, check that it will end up in
91 #####################################################################
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');
101 #####################################################################
102 # 5: move it to the left again, check that the stacked con is deleted
103 #####################################################################
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');
112 #####################################################################
113 # 6: move it to a different workspace, check that it ends up in a
115 #####################################################################
117 my $otmp = get_unused_workspace;
119 cmd "move workspace $otmp";
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');
126 @content = @{get_ws_content($otmp)};
127 is(@content, 1, 'one con on target workspace');
128 is($content[0]->{layout}, 'stacked', 'layout stacked');
130 #####################################################################
131 # 7: toggle floating mode and check that we have a stacked con when
132 # re-inserting a floating container.
133 #####################################################################
135 $tmp = fresh_workspace;
137 $first = open_window;
138 cmd 'floating toggle';
139 cmd 'floating toggle';
141 $second = open_window;
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');
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 #####################################################################
153 $tmp = fresh_workspace;
155 cmd 'layout stacked';
156 $first = open_window;
157 $second = open_window;
159 @content = @{get_ws_content($tmp)};
160 is($content[0]->{layout}, 'stacked', 'layout stacked');
162 cmd '[id="' . $first->id . '"] kill';
163 cmd '[id="' . $second->id . '"] kill';
166 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
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');
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 #####################################################################
181 $tmp = fresh_workspace;
183 cmd 'layout stacked';
184 $first = open_window;
185 $second = open_window;
187 @content = @{get_ws_content($tmp)};
188 is($content[0]->{layout}, 'stacked', 'layout stacked');
190 cmd '[id="' . $first->id . '"] kill';
191 cmd '[id="' . $second->id . '"] kill';
194 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
197 $first = open_window;
198 $second = open_window;
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');
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 #####################################################################
210 $tmp = fresh_workspace;
213 $first = open_window;
214 $second = open_window;
216 @content = @{get_ws_content($tmp)};
217 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
219 cmd '[id="' . $first->id . '"] kill';
220 cmd '[id="' . $second->id . '"] kill';
223 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
226 $first = open_window;
227 $second = open_window;
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');
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 #####################################################################
239 $tmp = fresh_workspace;
242 $first = open_window;
243 $second = open_window;
245 @content = @{get_ws_content($tmp)};
246 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
248 cmd '[id="' . $first->id . '"] kill';
249 cmd '[id="' . $second->id . '"] kill';
252 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
255 $first = open_window;
256 $second = open_window;
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');
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 #####################################################################
268 $tmp = fresh_workspace;
270 cmd 'layout stacked';
271 $first = open_window;
272 $second = open_window;
274 @content = @{get_ws_content($tmp)};
275 is($content[0]->{layout}, 'stacked', 'layout stacked');
277 cmd '[id="' . $first->id . '"] kill';
278 cmd '[id="' . $second->id . '"] kill';
281 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
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');
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 #####################################################################
296 $tmp = fresh_workspace;
298 cmd 'layout stacked';
299 $first = open_window;
300 $second = open_window;
302 @content = @{get_ws_content($tmp)};
303 is($content[0]->{layout}, 'stacked', 'layout stacked');
305 cmd '[id="' . $first->id . '"] kill';
306 cmd '[id="' . $second->id . '"] kill';
309 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
311 cmd 'split vertical';
312 $first = open_window;
313 $second = open_window;
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');
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 #####################################################################
325 $tmp = fresh_workspace;
328 $first = open_window;
329 $second = open_window;
331 @content = @{get_ws_content($tmp)};
332 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
334 cmd '[id="' . $first->id . '"] kill';
335 cmd '[id="' . $second->id . '"] kill';
338 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
340 cmd 'split horizontal';
341 $first = open_window;
342 $second = open_window;
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');
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 #####################################################################
354 $tmp = fresh_workspace;
357 $first = open_window;
358 $second = open_window;
360 @content = @{get_ws_content($tmp)};
361 is($content[0]->{layout}, 'tabbed', 'layout tabbed');
363 cmd '[id="' . $first->id . '"] kill';
364 cmd '[id="' . $second->id . '"] kill';
367 ok(@{get_ws_content($tmp)} == 0, 'workspace is empty');
369 cmd 'split vertical';
370 $first = open_window;
371 $second = open_window;
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');
379 exit_gracefully($pid);