]> git.sur5r.net Git - i3/i3/blob - testcases/t/504-move-workspace-to-output.t
tests: replace http:// with https:// where appropriate
[i3/i3] / testcases / t / 504-move-workspace-to-output.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests whether the 'move workspace <ws> to [output] <output>' command works
18 #
19 use List::Util qw(first);
20 use i3test i3_config => <<EOT;
21 # i3 config file (v4)
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
23
24 fake-outputs 1024x768+0+0,1024x768+1024+0
25
26 bar {
27     # Disable i3bar.
28     i3bar_command :
29 }
30 EOT
31
32 # TODO: get rid of smartmatch in this test
33
34 ################################################################################
35 # Setup workspaces so that they stay open (with an empty container).
36 ################################################################################
37
38 is(focused_ws, '1', 'starting on workspace 1');
39 # ensure workspace 1 stays open
40 open_window;
41
42 cmd 'focus output right';
43 is(focused_ws, '2', 'workspace 2 on second output');
44 # ensure workspace 2 stays open
45 open_window;
46
47 cmd 'focus output right';
48 is(focused_ws, '1', 'back on workspace 1');
49
50 # We don’t use fresh_workspace with named workspaces here since they come last
51 # when using 'workspace next'.
52 cmd 'workspace 5';
53 # ensure workspace 5 stays open
54 open_window;
55
56 ################################################################################
57 # Move a workspace over and verify that it is on the right output.
58 ################################################################################
59
60 # The current order should be:
61 # output 1: 1, 5
62 # output 2: 2
63 cmd 'workspace 5';
64 is(focused_ws, '5', 'workspace 5 focused');
65
66 my ($x0, $x1) = workspaces_per_screen();
67 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
68
69 cmd 'move workspace to output fake-1';
70
71 sub workspaces_per_screen {
72     my $i3 = i3(get_socket_path());
73     my $tree = $i3->get_tree->recv;
74     my @outputs = @{$tree->{nodes}};
75
76     my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
77     my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
78
79     my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
80     my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
81
82     my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
83     my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
84
85     return \@fake0_workspaces, \@fake1_workspaces;
86 }
87
88 ($x0, $x1) = workspaces_per_screen();
89 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
90
91 ################################################################################
92 # Verify that a new workspace will be created when moving the last workspace.
93 ################################################################################
94
95 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
96
97 cmd 'workspace 1';
98 cmd 'move workspace to output fake-1';
99
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');
103
104 ################################################################################
105 # Verify that 'move workspace to output <direction>' works
106 ################################################################################
107
108 cmd 'workspace 5';
109 cmd 'move workspace to output left';
110
111 ($x0, $x1) = workspaces_per_screen();
112 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
113
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');
118
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');
123
124 ################################################################################
125 # Verify that coordinates of floating windows are fixed correctly when moving a
126 # workspace to a different output.
127 ################################################################################
128
129 cmd 'workspace 5';
130 my $floating_window = open_floating_window;
131
132 my $old_rect = $floating_window->rect;
133
134 cmd 'move workspace to output right';
135
136 my $new_rect = $floating_window->rect;
137
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');
142
143 ################################################################################
144 # Verify that empty workspaces get cleaned up when moving a different workspace
145 # to that output.
146 ################################################################################
147
148 my $empty_ws = fresh_workspace(output => 0);
149 my $other_output_ws = fresh_workspace(output => 1);
150 cmd 'open';
151
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');
155
156 cmd 'move workspace to output left';
157
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');
162
163 ################################################################################
164 # Verify that the special word 'current' can be used for the output.
165 ################################################################################
166
167 my $ws1 = fresh_workspace(output => 1);
168 open_window;
169 cmd 'mark marked';
170
171 my $ws0 = fresh_workspace(output => 0);
172
173 ($x0, $x1) = workspaces_per_screen();
174 ok($ws0 ~~ @$x0, 'ws0 on fake-0');
175 ok($ws1 ~~ @$x1, 'ws1 on fake-1');
176
177 cmd '[con_mark=marked] move workspace to output current';
178
179 ($x0, $x1) = workspaces_per_screen();
180 ok($ws1 ~~ @$x0, 'ws1 on fake-0');
181
182 ################################################################################
183
184 done_testing;