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 whether the 'move workspace <ws> to [output] <output>' command works
19 use List::Util qw(first);
20 use i3test i3_autostart => 0;
23 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
25 # Ensure the pointer is at (0, 0) so that we really start on the first
26 # (the left) workspace.
27 $x->root->warp_pointer(0, 0);
31 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
33 fake-outputs 1024x768+0+0,1024x768+1024+0
35 my $pid = launch_with_config($config);
37 ################################################################################
38 # Setup workspaces so that they stay open (with an empty container).
39 ################################################################################
41 is(focused_ws, '1', 'starting on workspace 1');
42 # ensure workspace 1 stays open
45 cmd 'focus output right';
46 is(focused_ws, '2', 'workspace 2 on second output');
47 # ensure workspace 2 stays open
50 cmd 'focus output right';
51 is(focused_ws, '1', 'back on workspace 1');
53 # We don’t use fresh_workspace with named workspaces here since they come last
54 # when using 'workspace next'.
56 # ensure workspace 5 stays open
59 ################################################################################
60 # Move a workspace over and verify that it is on the right output.
61 ################################################################################
63 # The current order should be:
67 is(focused_ws, '5', 'workspace 5 focused');
69 my ($x0, $x1) = workspaces_per_screen();
70 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
72 cmd 'move workspace to output fake-1';
74 sub workspaces_per_screen {
75 my $i3 = i3(get_socket_path());
76 my $tree = $i3->get_tree->recv;
77 my @outputs = @{$tree->{nodes}};
79 my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
80 my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
82 my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
83 my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
85 my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
86 my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
88 return \@fake0_workspaces, \@fake1_workspaces;
91 ($x0, $x1) = workspaces_per_screen();
92 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
94 ################################################################################
95 # Verify that a new workspace will be created when moving the last workspace.
96 ################################################################################
98 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
101 cmd 'move workspace to output fake-1';
103 ($x0, $x1) = workspaces_per_screen();
104 ok('1' ~~ @$x1, 'workspace 1 now on fake-1');
105 is_deeply($x0, [ '3' ], 'workspace 2 created on fake-0');
107 ################################################################################
108 # Verify that 'move workspace to output <direction>' works
109 ################################################################################
112 cmd 'move workspace to output left';
114 ($x0, $x1) = workspaces_per_screen();
115 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
117 # Verify that wrapping works
118 cmd 'move workspace to output left';
119 ($x0, $x1) = workspaces_per_screen();
120 ok('5' ~~ @$x1, 'workspace 5 on fake-1');
122 # Put workspace 5 where it should
123 cmd 'move workspace to output left';
124 ($x0, $x1) = workspaces_per_screen();
125 ok('5' ~~ @$x0, 'workspace 5 on fake-0 again');
127 ################################################################################
128 # Verify that coordinates of floating windows are fixed correctly when moving a
129 # workspace to a different output.
130 ################################################################################
133 my $floating_window = open_floating_window;
135 my $old_rect = $floating_window->rect;
137 cmd 'move workspace to output right';
139 my $new_rect = $floating_window->rect;
141 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
142 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
143 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
144 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');
146 ################################################################################
147 # Verify that empty workspaces get cleaned up when moving a different workspace
149 ################################################################################
151 my $empty_ws = fresh_workspace(output => 0);
152 my $other_output_ws = fresh_workspace(output => 1);
155 ($x0, $x1) = workspaces_per_screen();
156 ok($empty_ws ~~ @$x0, 'empty_ws on fake-0');
157 ok($other_output_ws ~~ @$x1, 'other_output_ws on fake-1');
159 cmd 'move workspace to output left';
161 ($x0, $x1) = workspaces_per_screen();
162 ok(!($empty_ws ~~ @$x0), 'empty_ws not on fake-0');
163 ok(!($empty_ws ~~ @$x1), 'empty_ws not on fake-1');
164 ok($other_output_ws ~~ @$x0, 'other_output_ws on fake-0');
166 exit_gracefully($pid);