2 # vim:ts=4:sw=4:expandtab
4 # Tests whether the 'move workspace <ws> to [output] <output>' command works
6 use List::Util qw(first);
10 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
12 ################################################################################
13 # Setup workspaces so that they stay open (with an empty container).
14 ################################################################################
16 is(focused_ws, '1', 'starting on workspace 1');
17 # ensure workspace 1 stays open
20 cmd 'focus output right';
21 is(focused_ws, '2', 'workspace 2 on second output');
22 # ensure workspace 2 stays open
25 cmd 'focus output right';
26 is(focused_ws, '1', 'back on workspace 1');
28 # We don’t use fresh_workspace with named workspaces here since they come last
29 # when using 'workspace next'.
31 # ensure workspace 5 stays open
34 ################################################################################
35 # Move a workspace over and verify that it is on the right output.
36 ################################################################################
38 # The current order should be:
42 is(focused_ws, '5', 'workspace 5 focused');
44 my ($x0, $x1) = workspaces_per_screen();
45 ok('5' ~~ @$x0, 'workspace 5 on xinerama-0');
47 cmd 'move workspace to output xinerama-1';
49 sub workspaces_per_screen {
50 my $i3 = i3(get_socket_path());
51 my $tree = $i3->get_tree->recv;
52 my @outputs = @{$tree->{nodes}};
54 my $xinerama0 = first { $_->{name} eq 'xinerama-0' } @outputs;
55 my $xinerama0_content = first { $_->{type} == 2 } @{$xinerama0->{nodes}};
57 my $xinerama1 = first { $_->{name} eq 'xinerama-1' } @outputs;
58 my $xinerama1_content = first { $_->{type} == 2 } @{$xinerama1->{nodes}};
60 my @xinerama0_workspaces = map { $_->{name} } @{$xinerama0_content->{nodes}};
61 my @xinerama1_workspaces = map { $_->{name} } @{$xinerama1_content->{nodes}};
63 return \@xinerama0_workspaces, \@xinerama1_workspaces;
66 ($x0, $x1) = workspaces_per_screen();
67 ok('5' ~~ @$x1, 'workspace 5 now on xinerama-1');
69 ################################################################################
70 # Verify that a new workspace will be created when moving the last workspace.
71 ################################################################################
73 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on xinerama-0');
76 cmd 'move workspace to output xinerama-1';
78 ($x0, $x1) = workspaces_per_screen();
79 ok('1' ~~ @$x1, 'workspace 1 now on xinerama-1');
80 is_deeply($x0, [ '3' ], 'workspace 2 created on xinerama-0');
82 ################################################################################
83 # Verify that 'move workspace to output <direction>' works
84 ################################################################################
87 cmd 'move workspace to output left';
89 ($x0, $x1) = workspaces_per_screen();
90 ok('5' ~~ @$x0, 'workspace 5 back on xinerama-0');
92 ################################################################################
93 # Verify that coordinates of floating windows are fixed correctly when moving a
94 # workspace to a different output.
95 ################################################################################
98 my $floating_window = open_floating_window;
100 my $old_rect = $floating_window->rect;
102 cmd 'move workspace to output right';
104 my $new_rect = $floating_window->rect;
106 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
107 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
108 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
109 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');