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_config => <<EOT;
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24 fake-outputs 1024x768+0+0,1024x768+1024+0
32 # TODO: get rid of smartmatch in this test
34 ################################################################################
35 # Setup workspaces so that they stay open (with an empty container).
36 ################################################################################
38 is(focused_ws, '1', 'starting on workspace 1');
39 # ensure workspace 1 stays open
42 cmd 'focus output right';
43 is(focused_ws, '2', 'workspace 2 on second output');
44 # ensure workspace 2 stays open
47 cmd 'focus output right';
48 is(focused_ws, '1', 'back on workspace 1');
50 # We don’t use fresh_workspace with named workspaces here since they come last
51 # when using 'workspace next'.
53 # ensure workspace 5 stays open
56 ################################################################################
57 # Move a workspace over and verify that it is on the right output.
58 ################################################################################
60 # The current order should be:
64 is(focused_ws, '5', 'workspace 5 focused');
66 my ($x0, $x1) = workspaces_per_screen();
67 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
69 cmd 'move workspace to output fake-1';
71 sub workspaces_per_screen {
72 my $i3 = i3(get_socket_path());
73 my $tree = $i3->get_tree->recv;
74 my @outputs = @{$tree->{nodes}};
76 my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
77 my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
79 my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
80 my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
82 my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
83 my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
85 return \@fake0_workspaces, \@fake1_workspaces;
88 ($x0, $x1) = workspaces_per_screen();
89 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
91 ################################################################################
92 # Verify that a new workspace will be created when moving the last workspace.
93 ################################################################################
95 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
98 cmd 'move workspace to output fake-1';
100 ($x0, $x1) = workspaces_per_screen();
101 ok('1' ~~ @$x1, 'workspace 1 now on fake-1');
102 is_deeply($x0, [ '3' ], 'workspace 2 created on fake-0');
104 ################################################################################
105 # Verify that 'move workspace to output <direction>' works
106 ################################################################################
109 cmd 'move workspace to output left';
111 ($x0, $x1) = workspaces_per_screen();
112 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
114 # Verify that wrapping works
115 cmd 'move workspace to output left';
116 ($x0, $x1) = workspaces_per_screen();
117 ok('5' ~~ @$x1, 'workspace 5 on fake-1');
119 # Put workspace 5 where it should
120 cmd 'move workspace to output left';
121 ($x0, $x1) = workspaces_per_screen();
122 ok('5' ~~ @$x0, 'workspace 5 on fake-0 again');
124 ################################################################################
125 # Verify that coordinates of floating windows are fixed correctly when moving a
126 # workspace to a different output.
127 ################################################################################
130 my $floating_window = open_floating_window;
132 my $old_rect = $floating_window->rect;
134 cmd 'move workspace to output right';
136 my $new_rect = $floating_window->rect;
138 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
139 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
140 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
141 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');
143 ################################################################################
144 # Verify that empty workspaces get cleaned up when moving a different workspace
146 ################################################################################
148 my $empty_ws = fresh_workspace(output => 0);
149 my $other_output_ws = fresh_workspace(output => 1);
152 ($x0, $x1) = workspaces_per_screen();
153 ok($empty_ws ~~ @$x0, 'empty_ws on fake-0');
154 ok($other_output_ws ~~ @$x1, 'other_output_ws on fake-1');
156 cmd 'move workspace to output left';
158 ($x0, $x1) = workspaces_per_screen();
159 ok(!($empty_ws ~~ @$x0), 'empty_ws not on fake-0');
160 ok(!($empty_ws ~~ @$x1), 'empty_ws not on fake-1');
161 ok($other_output_ws ~~ @$x0, 'other_output_ws on fake-0');
163 ################################################################################
164 # Verify that the special word 'current' can be used for the output.
165 ################################################################################
167 my $ws1 = fresh_workspace(output => 1);
171 my $ws0 = fresh_workspace(output => 0);
173 ($x0, $x1) = workspaces_per_screen();
174 ok($ws0 ~~ @$x0, 'ws0 on fake-0');
175 ok($ws1 ~~ @$x1, 'ws1 on fake-1');
177 cmd '[con_mark=marked] move workspace to output current';
179 ($x0, $x1) = workspaces_per_screen();
180 ok($ws1 ~~ @$x0, 'ws1 on fake-0');
182 ################################################################################