aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/132-move-workspace.t
blob: bcfdaa7e7a630a00c1191843c5d7b5c0547b0127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • https://i3wm.org/downloads/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Checks if the 'move [window/container] to workspace' command works correctly
#
use i3test;

my $i3 = i3(get_socket_path());

# We move the pointer out of our way to avoid a bug where the focus will
# be set to the window under the cursor
sync_with_i3;
$x->root->warp_pointer(0, 0);
sync_with_i3;

sub move_workspace_test {
    my ($movecmd) = @_;

    my $tmp = get_unused_workspace();
    my $tmp2 = get_unused_workspace();
    cmd "workspace $tmp";

    is_num_children($tmp, 0, 'no containers yet');

    my $first = open_empty_con($i3);
    my $second = open_empty_con($i3);
    is_num_children($tmp, 2, 'two containers on first ws');

    cmd "workspace $tmp2";
    is_num_children($tmp2, 0, 'no containers on second ws yet');

    cmd "workspace $tmp";

    cmd "$movecmd $tmp2";
    is_num_children($tmp, 1, 'one container on first ws anymore');
    is_num_children($tmp2, 1, 'one container on second ws');
    my ($nodes, $focus) = get_ws_content($tmp2);

    is($focus->[0], $second, 'same container on different ws');

    ($nodes, $focus) = get_ws_content($tmp);
    ok($nodes->[0]->{focused}, 'first container focused on first ws');
}

move_workspace_test('move workspace');  # supported for legacy reasons
move_workspace_test('move to workspace');
# Those are just synonyms and more verbose ways of saying the same thing:
move_workspace_test('move window to workspace');
move_workspace_test('move container to workspace');

################################################################################
# Check that 'move to workspace number <number>' works to move a window to
# named workspaces which start with <number>.
################################################################################

cmd 'workspace 13: meh';
cmd 'open';
is_num_children('13: meh', 1, 'one container on 13: meh');

ok(!workspace_exists('13'), 'workspace 13 does not exist yet');

cmd 'workspace 12';
cmd 'open';

cmd 'move to workspace number 13';
is_num_children('13: meh', 2, 'one container on 13: meh');
is_num_children('12', 0, 'no container on 12 anymore');

ok(!workspace_exists('13'), 'workspace 13 does still not exist');

################################################################################
# Check that 'move to workspace number <number><name>' works to move a window to
# named workspaces which start with <number>.
################################################################################

cmd 'workspace 15: meh';
cmd 'open';
is_num_children('15: meh', 1, 'one container on 15: meh');

ok(!workspace_exists('15'), 'workspace 15 does not exist yet');
ok(!workspace_exists('15: duh'), 'workspace 15: duh does not exist yet');

cmd 'workspace 14';
cmd 'open';

cmd 'move to workspace number 15: duh';
is_num_children('15: meh', 2, 'two containers on 15: meh');
is_num_children('14', 0, 'no container on 14 anymore');

ok(!workspace_exists('15'), 'workspace 15 does still not exist');
ok(!workspace_exists('15: duh'), 'workspace 15 does still not exist');

###################################################################
# check if 'move workspace next' and 'move workspace prev' work
###################################################################

# Open two containers on the first workspace, one container on the second
# workspace. Because the workspaces are named, they will be sorted by order of
# creation.
my $tmp = get_unused_workspace();
my $tmp2 = get_unused_workspace();
cmd "workspace $tmp";
is_num_children($tmp, 0, 'no containers yet');
my $first = open_empty_con($i3);
my $second = open_empty_con($i3);
is_num_children($tmp, 2, 'two containers');

cmd "workspace $tmp2";
is_num_children($tmp2, 0, 'no containers yet');
my $third = open_empty_con($i3);
is_num_children($tmp2, 1, 'one container on second ws');

# go back to the first workspace, move one of the containers to the next one
cmd "workspace $tmp";
cmd 'move workspace next';
is_num_children($tmp, 1, 'one container on first ws');
is_num_children($tmp2, 2, 'two containers on second ws');

# go to the second workspace and move two containers to the first one
cmd "workspace $tmp2";
cmd 'move workspace prev';
cmd 'move workspace prev';
is_num_children($tmp, 3, 'three containers on first ws');
is_num_children($tmp2, 0, 'no containers on second ws');

###################################################################
# check if 'move workspace current' works
###################################################################

$tmp = get_unused_workspace();
$tmp2 = get_unused_workspace();

cmd "workspace $tmp";
$first = open_window(name => 'win-name');
is_num_children($tmp, 1, 'one container on first ws');

cmd "workspace $tmp2";
is_num_children($tmp2, 0, 'no containers yet');

cmd qq|[title="win-name"] move workspace $tmp2|;
is_num_children($tmp2, 1, 'one container on second ws');

cmd qq|[title="win-name"] move workspace $tmp|;
is_num_children($tmp2, 0, 'no containers on second ws');

###################################################################
# check if floating cons are moved to new workspaces properly
# (that is, if they are floating on the target ws, too)
###################################################################

$tmp = get_unused_workspace();
$tmp2 = get_unused_workspace();
cmd "workspace $tmp";

cmd "open";
cmd "floating toggle";

my $ws = get_ws($tmp);
is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');

cmd "move workspace $tmp2";

$ws = get_ws($tmp2);
is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');

################################################################################
# Check that 'move workspace number' works correctly.
################################################################################

$tmp = get_unused_workspace();
cmd 'open';

cmd 'workspace 16';
cmd 'open';
is_num_children('16', 1, 'one node on ws 16');

cmd "workspace $tmp";
cmd 'open';
cmd 'move workspace number 16';
is_num_children('16', 2, 'two nodes on ws 16');

ok(!workspace_exists('17'), 'workspace 17 does not exist yet');
cmd 'open';
cmd 'move workspace number 17';
ok(workspace_exists('17'), 'workspace 17 created by moving');
is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16');

################################################################################
# The following four tests verify the various 'move workspace' commands when
# the selection is itself a workspace.
################################################################################

# borrowed from 122-split.t
# recursively sums up all nodes and their children
sub sum_nodes {
    my ($nodes) = @_;

    return 0 if !@{$nodes};

    my @children = (map { @{$_->{nodes}} } @{$nodes},
                    map { @{$_->{'floating_nodes'}} } @{$nodes});

    return @{$nodes} + sum_nodes(\@children);
}

############################################################
# move workspace 'next|prev'
############################################################
$tmp = get_unused_workspace();
$tmp2 = get_unused_workspace();

cmd "workspace $tmp";
cmd 'open';
is_num_children($tmp, 1, 'one container on first ws');

cmd "workspace $tmp2";
cmd 'open';
is_num_children($tmp2, 1, 'one container on second ws');
cmd 'open';
is_num_children($tmp2, 2, 'two containers on second ws');

cmd 'focus parent';
cmd 'move workspace prev';

is_num_children($tmp, 2, 'two child containers on first ws');
is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws');
is_num_children($tmp2, 0, 'no containers on second ws');

############################################################
# move workspace current
# This is a special case that should be a no-op.
############################################################
$tmp = fresh_workspace();

cmd 'open';
is_num_children($tmp, 1, 'one container on first ws');
my $tmpcount = sum_nodes(get_ws_content($tmp));

cmd 'focus parent';
cmd "move workspace $tmp";

is(sum_nodes(get_ws_content($tmp)), $tmpcount, 'number of containers in first ws unchanged');

############################################################
# move workspace '<name>'
############################################################
$tmp2 = get_unused_workspace();
$tmp = fresh_workspace();

cmd 'open';
is_num_children($tmp, 1, 'one container on first ws');

cmd "workspace $tmp2";
cmd 'open';
is_num_children($tmp2, 1, 'one container on second ws');
cmd 'open';
is_num_children($tmp2, 2, 'two containers on second ws');

cmd 'focus parent';
cmd "move workspace $tmp";

is_num_children($tmp, 2, 'two child containers on first ws');
is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws');
is_num_children($tmp2, 0, 'no containers on second ws');

############################################################
# move workspace number '<number>'
############################################################
cmd 'workspace 18';
cmd 'open';
is_num_children('18', 1, 'one container on ws 18');

cmd 'workspace 19';
cmd 'open';
is_num_children('19', 1, 'one container on ws 19');
cmd 'open';
is_num_children('19', 2, 'two containers on ws 19');

cmd 'focus parent';
cmd 'move workspace number 18';

is_num_children('18', 2, 'two child containers on ws 18');
is(sum_nodes(get_ws_content('18')), 4, 'four total containers on ws 18');
is_num_children('19', 0, 'no containers on ws 19');

###################################################################
# move workspace '<name>' with a floating child
###################################################################
$tmp2 = get_unused_workspace();
$tmp = fresh_workspace();
cmd 'open';
cmd 'floating toggle';
cmd 'open';
cmd 'floating toggle';
cmd 'open';

$ws = get_ws($tmp);
is_num_children($tmp, 1, 'one container on first workspace');
is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on first workspace');

cmd 'focus parent';
cmd "move workspace $tmp2";

$ws = get_ws($tmp2);
is_num_children($tmp2, 1, 'one container on second workspace');
is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on second workspace');

###################################################################
# same as the above, but with only floating children
###################################################################
$tmp2 = get_unused_workspace();
$tmp = fresh_workspace();
cmd 'open';
cmd 'floating toggle';

$ws = get_ws($tmp);
is_num_children($tmp, 0, 'no regular nodes on first workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on first workspace');

cmd 'focus parent';
cmd "move workspace $tmp2";

$ws = get_ws($tmp2);
is_num_children($tmp2, 0, 'no regular nodes on second workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace');

###################################################################
# Test that when moving a fullscreen floating window to a workspace
# that already has an other fullscreen container, the second
# container gets un-fullscreened.
# See #4124
###################################################################
$tmp2 = fresh_workspace;
$second = open_window;
cmd 'fullscreen enable';
$ws = get_ws($tmp2);
is($ws->{nodes}->[0]->{fullscreen_mode}, 1, 'sanity check: fullscreen enabled');

$tmp = fresh_workspace;
$first = open_window;
cmd 'floating enable, fullscreen enable';
cmd "move workspace $tmp2";

$ws = get_ws($tmp2);
is_num_children($tmp2, 1, 'one regular node on second workspace');
is_num_fullscreen($tmp2, 1, 'one fullscreen node on second workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace');
is($ws->{nodes}->[0]->{fullscreen_mode}, 0, 'previous fullscreen disabled');

###################################################################
# Same as above, but trigger the bug with the parent of a
# fullscreen container, instead of a CT_FLOATING_CON.
###################################################################
$tmp2 = fresh_workspace;
$second = open_window;
cmd 'fullscreen enable';
$ws = get_ws($tmp2);
is($ws->{nodes}->[0]->{fullscreen_mode}, 1, 'sanity check: fullscreen enabled');

$tmp = fresh_workspace;
open_window;
$first = open_window;
cmd 'layout tabbed';
cmd 'focus parent, mark a, focus child';
cmd 'fullscreen enable';
cmd "[con_mark=a] move workspace $tmp2";

$ws = get_ws($tmp2);
is(sum_nodes(get_ws_content($tmp2)), 4, '3 leafs & 1 split node in second workspace');
# is_num_fullscreen does not catch this nested fullscreen container
is($ws->{nodes}->[0]->{fullscreen_mode}, 0, 'previous fullscreen disabled');
is($ws->{nodes}->[1]->{nodes}->[1]->{fullscreen_mode}, 1, 'nested fullscreen from moved container preserved');

###################################################################
# Check that moving an empty workspace using criteria doesn't
# create unfocused empty workspace.
###################################################################
$tmp2 = get_unused_workspace();
$tmp = fresh_workspace();
cmd 'mark a';
cmd "[con_mark=a] move to workspace $tmp2";

is (get_ws($tmp2), undef, 'No empty workspace created');

done_testing;