Codebase list i3-gaps / upstream/4.18.1 testcases / t / 291-swap.t
upstream/4.18.1

Tree @upstream/4.18.1 (Download .tar.gz)

291-swap.t @upstream/4.18.1raw · history · blame

  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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#!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)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests the swap command.
# Ticket: #917
use i3test i3_autostart => 0;

my $config = <<EOT;
# i3 config file (v4)
font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

for_window[class="mark_A"] mark A
for_window[class="mark_B"] mark B
EOT
my $pid = launch_with_config($config);

my ($ws, $ws1, $ws2, $ws3);
my ($node, $nodes, $expected_focus, $A, $B, $F);
my ($result);
my @fullscreen_permutations = ([], ["A"], ["B"], ["A", "B"]);
my $rect_A = [ 100, 100, 100, 100 ];
my $rect_B = [ 200, 200, 200, 200 ];
my @urgent;

sub fullscreen_windows {
    my $ws = shift if @_;

    scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)}
}

sub cmp_floating_rect {
    my ($window, $rect, $prefix) = @_;
    sync_with_i3;
    my ($absolute, $top) = $window->rect;

    is($absolute->{width}, $rect->[2], "$prefix: width matches");
    is($absolute->{height}, $rect->[3], "$prefix: height matches");

    is($top->{x}, $rect->[0], "$prefix: x matches");
    is($top->{y}, $rect->[1], "$prefix: y matches");
}

###############################################################################
# Invalid con_id should not crash i3
# See issue #2895.
###############################################################################

$ws = fresh_workspace;

open_window;
cmd "swap container with con_id 1";

does_i3_live;
kill_all_windows;

###############################################################################
# Swap 2 windows in different workspaces using con_id
###############################################################################

$ws = fresh_workspace;
open_window;
$A = get_focused($ws);

$ws = fresh_workspace;
open_window;

cmd "swap container with con_id $A";
is(get_focused($ws), $A, 'A is now focused');

kill_all_windows;

###############################################################################
# Swap two containers next to each other.
# Focus should stay on B because both windows are on the focused workspace.
# The focused container is B.
#
# +---+---+    Layout: H1[ A B ]
# | A | B |    Focus Stacks:
# +---+---+        H1: B, A
###############################################################################
$ws = fresh_workspace;

$A = open_window(wm_class => 'mark_A');
$B = open_window(wm_class => 'mark_B');
$expected_focus = get_focused($ws);

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws);
is($nodes->[0]->{window}, $B->{id}, 'B is on the left');
is($nodes->[1]->{window}, $A->{id}, 'A is on the right');
is(get_focused($ws), $expected_focus, 'B is still focused');

kill_all_windows;

###############################################################################
# Swap two containers with different parents.
# In this test, the focus head of the left v-split container is A.
# The focused container is B.
#
# +---+---+    Layout: H1[ V1[ A Y ] V2[ X B ] ]
# | A | X |    Focus Stacks:
# +---+---+        H1: V2, V1
# | Y | B |        V1: A, Y
# +---+---+        V2: B, X
###############################################################################
$ws = fresh_workspace;

$A = open_window(wm_class => 'mark_A');
$B = open_window(wm_class => 'mark_B');
cmd 'split v';
open_window;
cmd 'move up, focus left';
cmd 'split v';
open_window;
cmd 'focus up, focus right, focus down';
$expected_focus = get_focused($ws);

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws);
is($nodes->[0]->{nodes}->[0]->{window}, $B->{id}, 'B is on the top left');
is($nodes->[1]->{nodes}->[1]->{window}, $A->{id}, 'A is on the bottom right');
is(get_focused($ws), $expected_focus, 'B is still focused');

kill_all_windows;

###############################################################################
# Swap two containers with different parents.
# In this test, the focus head of the left v-split container is _not_ A.
# The focused container is B.
#
# +---+---+    Layout: H1[ V1[ A Y ] V2[ X B ] ]
# | A | X |    Focus Stacks:
# +---+---+        H1: V2, V1
# | Y | B |        V1: Y, A
# +---+---+        V2: B, X
###############################################################################
$ws = fresh_workspace;

$A = open_window(wm_class => 'mark_A');
$B = open_window(wm_class => 'mark_B');
cmd 'split v';
open_window;
cmd 'move up, focus left';
cmd 'split v';
open_window;
cmd 'focus right, focus down';
$expected_focus = get_focused($ws);

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws);
is($nodes->[0]->{nodes}->[0]->{window}, $B->{id}, 'B is on the top left');
is($nodes->[1]->{nodes}->[1]->{window}, $A->{id}, 'A is on the bottom right');
is(get_focused($ws), $expected_focus, 'B is still focused');

kill_all_windows;

###############################################################################
# Swap two containers with one being on a different workspace.
# The focused container is B.
#
# Layout: O1[ W1[ H1 ] W2[ H2 ] ]
# Focus Stacks:
#     O1: W2, W1
#
# +---+---+    Layout: H1[ A X ]
# | A | X |    Focus Stacks:
# +---+---+        H1: A, X
#
# +---+---+    Layout: H2[ Y, B ]
# | Y | B |    Focus Stacks:
# +---+---+        H2: B, Y
###############################################################################
for my $fullscreen (@fullscreen_permutations){
    $ws1 = fresh_workspace;
    $A = open_window(wm_class => 'mark_A');
    $expected_focus = get_focused($ws1);
    open_window;
    cmd 'focus left';

    $ws2 = fresh_workspace;
    open_window;
    $B = open_window(wm_class => 'mark_B');

    my $A_fullscreen = "A" ~~ @$fullscreen || 0;
    my $B_fullscreen = "B" ~~ @$fullscreen || 0;
    $A->fullscreen($A_fullscreen);
    $B->fullscreen($B_fullscreen);
    sync_with_i3;

    cmd '[con_mark=B] swap container with mark A';

    $nodes = get_ws_content($ws1);
    $node = $nodes->[0];
    is($node->{window}, $B->{id}, 'B is on ws1:left');
    is_num_fullscreen($ws1, $A_fullscreen, 'amount of fullscreen windows in ws1');
    is($node->{fullscreen_mode}, $A_fullscreen, 'B got A\'s fullscreen mode');

    $nodes = get_ws_content($ws2);
    $node = $nodes->[1];
    is($node->{window}, $A->{id}, 'A is on ws2:right');
    is(get_focused($ws2), $expected_focus, 'A is focused');
    is_num_fullscreen($ws2, $B_fullscreen, 'amount of fullscreen windows in ws2');
    is($node->{fullscreen_mode}, $B_fullscreen, 'A got B\'s fullscreen mode');

    kill_all_windows;
}

###############################################################################
# Swap a non-fullscreen window with a fullscreen one in different workspaces.
# Layout: O1[ W1[ H1 ] W2[ B ] ]
#
# +---+---+    Layout: H1[ A F ]
# | A | F |    Focus Stacks:
# +---+---+        H1: F, A
#
# +---+---+
# |   B   |
# +---+---+
###############################################################################
$ws1 = fresh_workspace;

$A = open_window(wm_class => 'mark_A');
$F = open_window();
$F->fullscreen(1);
$expected_focus = get_focused($ws1);

$ws2 = fresh_workspace;
$B = open_window(wm_class => 'mark_B');
$B->fullscreen(1);
sync_with_i3;

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws1);
is($nodes->[0]->{window}, $B->{id}, 'B is on ws1:left');
is_num_fullscreen($ws1, 1, 'F still fullscreen in ws1');
is(get_focused($ws1), $expected_focus, 'F is still focused');

$nodes = get_ws_content($ws2);
is($nodes->[0]->{window}, $A->{id}, 'A is on ws1');

###############################################################################
# Try a more exotic layout with fullscreen containers.
# A and F are fullscreened as a stack of two vertical containers before the
# swap is performed.
# A is swapped with fullscreened window B which is in another workspace.
#
# +---+---+    Layout: H1[ X V1[ A F ] ]
# |   | A |    Focus Stacks:
# | X +---+        H1: V1, X
# |   | F |        V1: F, A
# +---+---+
###############################################################################
$ws1 = fresh_workspace;

open_window;
$A = open_window(wm_class => 'mark_A');
cmd "split v";
open_window;
cmd "focus parent";
cmd "fullscreen enable";
$expected_focus = get_focused($ws1);

$ws2 = fresh_workspace;
$B = open_window(wm_class => 'mark_B');
$B->fullscreen(1);
sync_with_i3;

cmd '[con_mark=B] swap container with mark A';

does_i3_live;

$nodes = get_ws_content($ws1);
is($nodes->[1]->{nodes}->[0]->{window}, $B->{id}, 'B is on top right in ws1');
is(get_focused($ws1), $expected_focus, 'The container of the stacked windows remains focused in ws1');
is_num_fullscreen($ws1, 1, 'Same amount of fullscreen windows in ws1');

$nodes = get_ws_content($ws2);
is($nodes->[0]->{window}, $A->{id}, 'A is on ws2');
is_num_fullscreen($ws2, 1, 'A is in fullscreen mode');

###############################################################################
# Swap two non-focused containers within the same workspace.
#
# +---+---+    Layout: H1[ V1[ A X ] V2[ F B ] ]
# | A | F |    Focus Stacks:
# +---+---+        H1: V2, V1
# | X | B |        V1: A, X
# +---+---+        V2: F, B
###############################################################################
$ws = fresh_workspace;

$A = open_window(wm_class => 'mark_A');
$B = open_window(wm_class => 'mark_B');
cmd 'split v';
open_window;
cmd 'move up, focus left';
cmd 'split v';
open_window;
cmd 'focus up, focus right';
$expected_focus = get_focused($ws);

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws);
is($nodes->[0]->{nodes}->[0]->{window}, $B->{id}, 'B is on the top left');
is($nodes->[1]->{nodes}->[1]->{window}, $A->{id}, 'A is on the bottom right');
is(get_focused($ws), $expected_focus, 'F is still focused');

kill_all_windows;

###############################################################################
# Swap two non-focused containers which are both on different workspaces.
#
# Layout: O1[ W1[ A ] W2[ B ] W3[ F ] ]
# Focus Stacks:
#     O1: W3, W2, W1
#
# +---+
# | A |
# +---+
#
# +---+
# | B |
# +---+
#
# +---+
# | F |
# +---+
###############################################################################
for my $fullscreen (@fullscreen_permutations){
    $ws1 = fresh_workspace;
    $A = open_window(wm_class => 'mark_A');

    $ws2 = fresh_workspace;
    $B = open_window(wm_class => 'mark_B');

    $ws3 = fresh_workspace;
    open_window;
    $expected_focus = get_focused($ws3);

    my $A_fullscreen = "A" ~~ @$fullscreen || 0;
    my $B_fullscreen = "B" ~~ @$fullscreen || 0;
    $A->fullscreen($A_fullscreen);
    $B->fullscreen($B_fullscreen);
    sync_with_i3;

    cmd '[con_mark=B] swap container with mark A';

    $nodes = get_ws_content($ws1);
    $node = $nodes->[0];
    is($node->{window}, $B->{id}, 'B is on the first workspace');
    is_num_fullscreen($ws1, $A_fullscreen, 'amount of fullscreen windows in ws1');
    is($node->{fullscreen_mode}, $A_fullscreen, 'B got A\'s fullscreen mode');

    $nodes = get_ws_content($ws2);
    $node = $nodes->[0];
    is($node->{window}, $A->{id}, 'A is on the second workspace');
    is_num_fullscreen($ws2, $B_fullscreen, 'amount of fullscreen windows in ws2');
    is($node->{fullscreen_mode}, $B_fullscreen, 'A got B\'s fullscreen mode');

    is(get_focused($ws3), $expected_focus, 'F is still focused');

    kill_all_windows;
}

###############################################################################
# Swap two non-focused containers with one being on a different workspace.
#
# Layout: O1[ W1[ A ] W2[ H2 ] ]
# Focus Stacks:
#     O1: W2, W1
#
# +---+
# | A |
# +---+
#
# +---+---+    Layout: H2[ B, F ]
# | B | F |    Focus Stacks:
# +---+---+        H2: F, B
#
# See issue: #3259
###############################################################################

for my $fullscreen (0..1){
    $ws1 = fresh_workspace;
    $A = open_window(wm_class => 'mark_A');

    $ws2 = fresh_workspace;
    $B = open_window(wm_class => 'mark_B');
    open_window;
    cmd 'fullscreen enable' if $fullscreen;
    $expected_focus = get_focused($ws2);

    cmd '[con_mark=B] swap container with mark A';

    $nodes = get_ws_content($ws1);
    is($nodes->[0]->{window}, $B->{id}, 'B is on the first workspace');

    $nodes = get_ws_content($ws2);
    is($nodes->[0]->{window}, $A->{id}, 'A is on the left of the second workspace');
    is(get_focused($ws2), $expected_focus, 'F is still focused');

    kill_all_windows;
}

###############################################################################
# 1. A container cannot be swapped with its parent.
# 2. A container cannot be swapped with one of its children.
#
#      ↓A↓
# +---+---+    Layout: H1[ X V1[ Y B ] ]
# |   | Y |        (with A := V1)
# | X +---+
# |   | B |
# +---+---+
###############################################################################
$ws = fresh_workspace;
open_window;
open_window;
cmd 'split v';
$B = open_window(wm_class => 'mark_B');
cmd 'focus parent, mark A, focus child';

$result = cmd '[con_mark=B] swap container with mark A';
is($result->[0]->{success}, 0, 'B cannot be swappd with its parent');

$result = cmd '[con_mark=A] swap container with mark B';
is($result->[0]->{success}, 0, 'A cannot be swappd with one of its children');

kill_all_windows;

###############################################################################
# Swapping two containers preserves the geometry of the container they are
# being swapped with.
#
# Before:
# +---+-------+
# | A |   B   |
# +---+-------+
#
# After:
# +---+-------+
# | B |   A   |
# +---+-------+
###############################################################################
$ws = fresh_workspace;
$A = open_window(wm_class => 'mark_A');
$B = open_window(wm_class => 'mark_B');
cmd 'resize grow width 0 or 25 ppt';

# sanity checks
$nodes = get_ws_content($ws);
cmp_float($nodes->[0]->{percent}, 0.25, 'A has 25% width');
cmp_float($nodes->[1]->{percent}, 0.75, 'B has 75% width');

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws);
cmp_float($nodes->[0]->{percent}, 0.25, 'B has 25% width');
cmp_float($nodes->[1]->{percent}, 0.75, 'A has 75% width');

kill_all_windows;

###############################################################################
# Swapping containers not sharing the same parent preserves the geometry of
# the container they are swapped with.
#
# Before:
# +---+-----+
# | A |     |
# +---+  B  |
# |   |     |
# | Y +-----+
# |   |  X  |
# +---+-----+
#
# After:
# +---+-----+
# | B |     |
# +---+  A  |
# |   |     |
# | Y +-----+
# |   |  X  |
# +---+-----+
###############################################################################
$ws = fresh_workspace;

$A = open_window(wm_class => 'mark_A');
$B = open_window(wm_class => 'mark_B');
cmd 'split v';
open_window;
cmd 'focus up, resize grow height 0 or 25 ppt';
cmd 'focus left, split v';
open_window;
cmd 'resize grow height 0 or 25 ppt';

# sanity checks
$nodes = get_ws_content($ws);
cmp_float($nodes->[0]->{nodes}->[0]->{percent}, 0.25, 'A has 25% height');
cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.75, 'B has 75% height');

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws_content($ws);
cmp_float($nodes->[0]->{nodes}->[0]->{percent}, 0.25, 'B has 25% height');
cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.75, 'A has 75% height');

kill_all_windows;

###############################################################################
# Swap floating windows in the same workspace. Check that they exchange rects.
###############################################################################
$ws = fresh_workspace;

$A = open_floating_window(wm_class => 'mark_A', rect => $rect_A);
$B = open_floating_window(wm_class => 'mark_B', rect => $rect_B);

cmd '[con_mark=B] swap container with mark A';
cmp_floating_rect($A, $rect_B, 'A got B\'s rect');
cmp_floating_rect($B, $rect_A, 'B got A\'s rect');

kill_all_windows;

###############################################################################
# Swap a fullscreen floating and a normal floating window.
###############################################################################
$ws1 = fresh_workspace;
$A = open_floating_window(wm_class => 'mark_A', rect => $rect_A, fullscreen => 1);
$ws2 = fresh_workspace;
$B = open_floating_window(wm_class => 'mark_B', rect => $rect_B);

cmd '[con_mark=B] swap container with mark A';

cmp_floating_rect($A, $rect_B, 'A got B\'s rect');

$nodes = get_ws($ws1);
$node = $nodes->{floating_nodes}->[0]->{nodes}->[0];
is($node->{window}, $B->{id}, 'B is on the first workspace');
is($node->{fullscreen_mode}, 1, 'B is now fullscreened');

$nodes = get_ws($ws2);
$node = $nodes->{floating_nodes}->[0]->{nodes}->[0];
is($node->{window}, $A->{id}, 'A is on the second workspace');
is($node->{fullscreen_mode}, 0, 'A is not fullscreened anymore');

kill_all_windows;

###############################################################################
# Swap a floating window which is in a workspace that has another, regular
# window with a regular window in another workspace. A & B focused.
#
# Before:
# +-----------+
# |         F |
# |   +---+   |
# |   | A |   |
# |   +---+   |
# |           |
# +-----------+
#
# +-----------+
# |           |
# |           |
# |     B     |
# |           |
# |           |
# +-----------+
#
# After: Same as above but A <-> B. A & B focused.
###############################################################################
$ws1 = fresh_workspace;
open_window;
$A = open_floating_window(wm_class => 'mark_A', rect => $rect_A);
$ws2 = fresh_workspace;
$B = open_window(wm_class => 'mark_B');
$expected_focus = get_focused($ws2);

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws($ws1);
$node = $nodes->{floating_nodes}->[0]->{nodes}->[0];
is($node->{window}, $B->{id}, 'B is floating on the first workspace');
is(get_focused($ws1), $expected_focus, 'B is focused');
cmp_floating_rect($B, $rect_A, 'B got A\'s rect');

$nodes = get_ws_content($ws2);
$node = $nodes->[0];
is($node->{window}, $A->{id}, 'A is on the second workspace');

kill_all_windows;

###################################################################
# Test that swapping a floating window maintains the correct
# floating order.
###################################################################
$ws = fresh_workspace;
$A = open_floating_window(wm_class => 'mark_A', rect => $rect_A);
$B = open_window(wm_class => 'mark_B');
$F = open_floating_window;
$expected_focus = get_focused($ws);

cmd '[con_mark=B] swap container with mark A';

$nodes = get_ws($ws);

$node = $nodes->{floating_nodes}->[0]->{nodes}->[0];
is($node->{window}, $B->{id}, 'B is floating, bottom');
cmp_floating_rect($B, $rect_A, 'B got A\'s rect');

$node = $nodes->{floating_nodes}->[1]->{nodes}->[0];
is($node->{window}, $F->{id}, 'F is floating, top');
is(get_focused($ws), $expected_focus, 'F still focused');

$node = $nodes->{nodes}->[0];
is($node->{window}, $A->{id}, 'A is tiling');

kill_all_windows;

###############################################################################
# Swap a sticky, floating container A and a floating fullscreen container B.
# A should remain sticky and floating and should be fullscreened.
###############################################################################
$ws1 = fresh_workspace;
open_window;
$A = open_floating_window(wm_class => 'mark_A', rect => $rect_A);
$expected_focus = get_focused($ws1);
cmd 'sticky enable';
$B = open_floating_window(wm_class => 'mark_B', rect => $rect_B);
cmd 'fullscreen enable';

cmd '[con_mark=B] swap container with mark A';

is(@{get_ws($ws1)->{floating_nodes}}, 2, '2 fullscreen containers on first workspace');
is(get_focused($ws1), $expected_focus, 'A is focused');

$ws2 = fresh_workspace;
cmd 'fullscreen disable';
cmp_floating_rect($A, $rect_B, 'A got B\'s rect');
is(@{get_ws($ws2)->{floating_nodes}}, 1, 'only A in new workspace');

cmd "workspace $ws1"; # TODO: Why does rect check fails without switching workspaces?
cmp_floating_rect($B, $rect_A, 'B got A\'s rect');

kill_all_windows;

###############################################################################
# Swapping containers moves the urgency hint correctly.
###############################################################################

$ws1 = fresh_workspace;
$A = open_window(wm_class => 'mark_A');
$ws2 = fresh_workspace;
$B = open_window(wm_class => 'mark_B');
open_window;

$B->add_hint('urgency');
sync_with_i3;

cmd '[con_mark=B] swap container with mark A';

@urgent = grep { $_->{urgent} } @{get_ws_content($ws1)};
is(@urgent, 1, 'B is marked urgent');
is(get_ws($ws1)->{urgent}, 1, 'the first workspace is marked urgent');

@urgent = grep { $_->{urgent} } @{get_ws_content($ws2)};
is(@urgent, 0, 'A is not marked urgent');
is(get_ws($ws2)->{urgent}, 0, 'the second workspace is not marked urgent');

kill_all_windows;

###############################################################################
# Swapping an urgent container from another workspace with the focused
# container removes the urgency hint from both the container and the previous
# workspace.
###############################################################################

$ws2 = fresh_workspace;
$B = open_window(wm_class => 'mark_B');
$ws1 = fresh_workspace;
$A = open_window(wm_class => 'mark_A');

$B->add_hint('urgency');
sync_with_i3;

cmd '[con_mark=B] swap container with mark A';

@urgent = grep { $_->{urgent} } @{get_ws_content($ws1)};
is(@urgent, 0, 'B is not marked urgent');
is(get_ws($ws1)->{urgent}, 0, 'the first workspace is not marked urgent');

@urgent = grep { $_->{urgent} } @{get_ws_content($ws2)};
is(@urgent, 0, 'A is not marked urgent');
is(get_ws($ws2)->{urgent}, 0, 'the second workspace is not marked urgent');

kill_all_windows;

exit_gracefully($pid);

###############################################################################
# Test that swapping with workspace_layout doesn't crash i3.
# See issue #3280.
###############################################################################

$config = <<EOT;
# i3 config file (v4)
font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

workspace_layout stacking
EOT
$pid = launch_with_config($config);

$ws = fresh_workspace;
open_window;
open_window;
$B = open_window;

cmd 'move right';
cmd 'focus left, focus parent, mark a';
cmd 'focus right';
cmd 'swap with mark a';

does_i3_live;

$nodes = get_ws_content($ws);
is($nodes->[0]->{window}, $B->{id}, 'B is on the left');

exit_gracefully($pid);

###############################################################################

done_testing;