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);
7 use i3test i3_autostart => 0;
10 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
12 # Ensure the pointer is at (0, 0) so that we really start on the first
13 # (the left) workspace.
14 $x->root->warp_pointer(0, 0);
18 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
20 fake-outputs 1024x768+0+0,1024x768+1024+0
22 my $pid = launch_with_config($config);
24 ################################################################################
25 # Setup workspaces so that they stay open (with an empty container).
26 ################################################################################
28 is(focused_ws, '1', 'starting on workspace 1');
29 # ensure workspace 1 stays open
32 cmd 'focus output right';
33 is(focused_ws, '2', 'workspace 2 on second output');
34 # ensure workspace 2 stays open
37 cmd 'focus output right';
38 is(focused_ws, '1', 'back on workspace 1');
40 # We don’t use fresh_workspace with named workspaces here since they come last
41 # when using 'workspace next'.
43 # ensure workspace 5 stays open
46 ################################################################################
47 # Move a workspace over and verify that it is on the right output.
48 ################################################################################
50 # The current order should be:
54 is(focused_ws, '5', 'workspace 5 focused');
56 my ($x0, $x1) = workspaces_per_screen();
57 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
59 cmd 'move workspace to output fake-1';
61 sub workspaces_per_screen {
62 my $i3 = i3(get_socket_path());
63 my $tree = $i3->get_tree->recv;
64 my @outputs = @{$tree->{nodes}};
66 my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
67 my $fake0_content = first { $_->{type} == 2 } @{$fake0->{nodes}};
69 my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
70 my $fake1_content = first { $_->{type} == 2 } @{$fake1->{nodes}};
72 my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
73 my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
75 return \@fake0_workspaces, \@fake1_workspaces;
78 ($x0, $x1) = workspaces_per_screen();
79 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
81 ################################################################################
82 # Verify that a new workspace will be created when moving the last workspace.
83 ################################################################################
85 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
88 cmd 'move workspace to output fake-1';
90 ($x0, $x1) = workspaces_per_screen();
91 ok('1' ~~ @$x1, 'workspace 1 now on fake-1');
92 is_deeply($x0, [ '3' ], 'workspace 2 created on fake-0');
94 ################################################################################
95 # Verify that 'move workspace to output <direction>' works
96 ################################################################################
99 cmd 'move workspace to output left';
101 ($x0, $x1) = workspaces_per_screen();
102 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
104 ################################################################################
105 # Verify that coordinates of floating windows are fixed correctly when moving a
106 # workspace to a different output.
107 ################################################################################
110 my $floating_window = open_floating_window;
112 my $old_rect = $floating_window->rect;
114 cmd 'move workspace to output right';
116 my $new_rect = $floating_window->rect;
118 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
119 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
120 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
121 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');
123 exit_gracefully($pid);