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
27 # TODO: get rid of smartmatch in this test
29 ################################################################################
30 # Setup workspaces so that they stay open (with an empty container).
31 ################################################################################
33 is(focused_ws, '1', 'starting on workspace 1');
34 # ensure workspace 1 stays open
37 cmd 'focus output right';
38 is(focused_ws, '2', 'workspace 2 on second output');
39 # ensure workspace 2 stays open
42 cmd 'focus output right';
43 is(focused_ws, '1', 'back on workspace 1');
45 # We don’t use fresh_workspace with named workspaces here since they come last
46 # when using 'workspace next'.
48 # ensure workspace 5 stays open
51 ################################################################################
52 # Move a workspace over and verify that it is on the right output.
53 ################################################################################
55 # The current order should be:
59 is(focused_ws, '5', 'workspace 5 focused');
61 my ($x0, $x1) = workspaces_per_screen();
62 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
64 cmd 'move workspace to output fake-1';
66 sub workspaces_per_screen {
67 my $i3 = i3(get_socket_path());
68 my $tree = $i3->get_tree->recv;
69 my @outputs = @{$tree->{nodes}};
71 my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
72 my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
74 my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
75 my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
77 my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
78 my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
80 return \@fake0_workspaces, \@fake1_workspaces;
83 ($x0, $x1) = workspaces_per_screen();
84 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
86 ################################################################################
87 # Verify that a new workspace will be created when moving the last workspace.
88 ################################################################################
90 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
93 cmd 'move workspace to output fake-1';
95 ($x0, $x1) = workspaces_per_screen();
96 ok('1' ~~ @$x1, 'workspace 1 now on fake-1');
97 is_deeply($x0, [ '3' ], 'workspace 2 created on fake-0');
99 ################################################################################
100 # Verify that 'move workspace to output <direction>' works
101 ################################################################################
104 cmd 'move workspace to output left';
106 ($x0, $x1) = workspaces_per_screen();
107 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
109 # Verify that wrapping works
110 cmd 'move workspace to output left';
111 ($x0, $x1) = workspaces_per_screen();
112 ok('5' ~~ @$x1, 'workspace 5 on fake-1');
114 # Put workspace 5 where it should
115 cmd 'move workspace to output left';
116 ($x0, $x1) = workspaces_per_screen();
117 ok('5' ~~ @$x0, 'workspace 5 on fake-0 again');
119 ################################################################################
120 # Verify that coordinates of floating windows are fixed correctly when moving a
121 # workspace to a different output.
122 ################################################################################
125 my $floating_window = open_floating_window;
127 my $old_rect = $floating_window->rect;
129 cmd 'move workspace to output right';
131 my $new_rect = $floating_window->rect;
133 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
134 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
135 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
136 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');
138 ################################################################################
139 # Verify that empty workspaces get cleaned up when moving a different workspace
141 ################################################################################
143 my $empty_ws = fresh_workspace(output => 0);
144 my $other_output_ws = fresh_workspace(output => 1);
147 ($x0, $x1) = workspaces_per_screen();
148 ok($empty_ws ~~ @$x0, 'empty_ws on fake-0');
149 ok($other_output_ws ~~ @$x1, 'other_output_ws on fake-1');
151 cmd 'move workspace to output left';
153 ($x0, $x1) = workspaces_per_screen();
154 ok(!($empty_ws ~~ @$x0), 'empty_ws not on fake-0');
155 ok(!($empty_ws ~~ @$x1), 'empty_ws not on fake-1');
156 ok($other_output_ws ~~ @$x0, 'other_output_ws on fake-0');
158 ################################################################################
159 # Verify that the special word 'current' can be used for the output.
160 ################################################################################
162 my $ws1 = fresh_workspace(output => 1);
166 my $ws0 = fresh_workspace(output => 0);
168 ($x0, $x1) = workspaces_per_screen();
169 ok($ws0 ~~ @$x0, 'ws0 on fake-0');
170 ok($ws1 ~~ @$x1, 'ws1 on fake-1');
172 cmd '[con_mark=marked] move workspace to output current';
174 ($x0, $x1) = workspaces_per_screen();
175 ok($ws1 ~~ @$x0, 'ws1 on fake-0');
177 ################################################################################