]> git.sur5r.net Git - i3/i3/blob - testcases/t/504-move-workspace-to-output.t
tests: use i3_config arg instead of precisely one launch_with_config
[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 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 EOT
26
27 # TODO: get rid of smartmatch in this test
28
29 ################################################################################
30 # Setup workspaces so that they stay open (with an empty container).
31 ################################################################################
32
33 is(focused_ws, '1', 'starting on workspace 1');
34 # ensure workspace 1 stays open
35 open_window;
36
37 cmd 'focus output right';
38 is(focused_ws, '2', 'workspace 2 on second output');
39 # ensure workspace 2 stays open
40 open_window;
41
42 cmd 'focus output right';
43 is(focused_ws, '1', 'back on workspace 1');
44
45 # We don’t use fresh_workspace with named workspaces here since they come last
46 # when using 'workspace next'.
47 cmd 'workspace 5';
48 # ensure workspace 5 stays open
49 open_window;
50
51 ################################################################################
52 # Move a workspace over and verify that it is on the right output.
53 ################################################################################
54
55 # The current order should be:
56 # output 1: 1, 5
57 # output 2: 2
58 cmd 'workspace 5';
59 is(focused_ws, '5', 'workspace 5 focused');
60
61 my ($x0, $x1) = workspaces_per_screen();
62 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
63
64 cmd 'move workspace to output fake-1';
65
66 sub workspaces_per_screen {
67     my $i3 = i3(get_socket_path());
68     my $tree = $i3->get_tree->recv;
69     my @outputs = @{$tree->{nodes}};
70
71     my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
72     my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
73
74     my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
75     my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
76
77     my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
78     my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
79
80     return \@fake0_workspaces, \@fake1_workspaces;
81 }
82
83 ($x0, $x1) = workspaces_per_screen();
84 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
85
86 ################################################################################
87 # Verify that a new workspace will be created when moving the last workspace.
88 ################################################################################
89
90 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
91
92 cmd 'workspace 1';
93 cmd 'move workspace to output fake-1';
94
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');
98
99 ################################################################################
100 # Verify that 'move workspace to output <direction>' works
101 ################################################################################
102
103 cmd 'workspace 5';
104 cmd 'move workspace to output left';
105
106 ($x0, $x1) = workspaces_per_screen();
107 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
108
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');
113
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');
118
119 ################################################################################
120 # Verify that coordinates of floating windows are fixed correctly when moving a
121 # workspace to a different output.
122 ################################################################################
123
124 cmd 'workspace 5';
125 my $floating_window = open_floating_window;
126
127 my $old_rect = $floating_window->rect;
128
129 cmd 'move workspace to output right';
130
131 my $new_rect = $floating_window->rect;
132
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');
137
138 ################################################################################
139 # Verify that empty workspaces get cleaned up when moving a different workspace
140 # to that output.
141 ################################################################################
142
143 my $empty_ws = fresh_workspace(output => 0);
144 my $other_output_ws = fresh_workspace(output => 1);
145 cmd 'open';
146
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');
150
151 cmd 'move workspace to output left';
152
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');
157
158 ################################################################################
159 # Verify that the special word 'current' can be used for the output.
160 ################################################################################
161
162 my $ws1 = fresh_workspace(output => 1);
163 open_window;
164 cmd 'mark marked';
165
166 my $ws0 = fresh_workspace(output => 0);
167
168 ($x0, $x1) = workspaces_per_screen();
169 ok($ws0 ~~ @$x0, 'ws0 on fake-0');
170 ok($ws1 ~~ @$x1, 'ws1 on fake-1');
171
172 cmd '[con_mark=marked] move workspace to output current';
173
174 ($x0, $x1) = workspaces_per_screen();
175 ok($ws1 ~~ @$x0, 'ws1 on fake-0');
176
177 ################################################################################
178
179 done_testing;