]> git.sur5r.net Git - i3/i3/blob - testcases/t/510-focus-across-outputs.t
Merge pull request #3441 from stapelberg/template
[i3/i3] / testcases / t / 510-focus-across-outputs.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 that switching workspaces via 'focus $dir' never leaves a floating
18 # window focused.
19 #
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,1024x768+0+768,1024x768+1024+768
25 EOT
26
27 my $s0_ws = fresh_workspace;
28 my $first = open_window;
29 my $second = open_window;
30 my $third = open_window;
31 cmd 'floating toggle';
32
33 # Focus screen 1
34 sync_with_i3;
35 $x->root->warp_pointer(1025, 0);
36 sync_with_i3;
37 my $s1_ws = fresh_workspace;
38
39 my $fourth = open_window;
40
41 # Focus screen 2
42 sync_with_i3;
43 $x->root->warp_pointer(0, 769);
44 sync_with_i3;
45 my $s2_ws = fresh_workspace;
46
47 my $fifth = open_window;
48
49 # Focus screen 3
50 sync_with_i3;
51 $x->root->warp_pointer(1025, 769);
52 sync_with_i3;
53 my $s3_ws = fresh_workspace;
54
55 my $sixth = open_window;
56 my $seventh = open_window;
57 my $eighth = open_window;
58 cmd 'floating toggle';
59
60 # Layout should look like this (windows 3 and 8 are floating):
61 #     S0      S1
62 # ┌───┬───┬───────┐
63 # │ ┌─┴─┐ │       │
64 # │1│ 3 │2│   4   │
65 # │ └─┬─┘ │       │
66 # ├───┴───┼───┬───┤
67 # │       │ ┌─┴─┐ │
68 # │   5   │6│ 8 │7│
69 # │       │ └─┬─┘ │
70 # └───────┴───┴───┘
71 #    S2       S3
72 #
73 ###################################################################
74 # Test that focus (left|down|right|up) doesn't focus floating
75 # windows when moving into horizontally-split workspaces.
76 ###################################################################
77
78 sub reset_focus {
79     my $ws = shift;
80     cmd "workspace $ws; focus floating";
81 }
82
83 cmd "workspace $s1_ws";
84 cmd 'focus left';
85 is($x->input_focus, $second->id, 'second window focused');
86 reset_focus $s0_ws;
87
88 cmd "workspace $s1_ws";
89 cmd 'focus down';
90 is($x->input_focus, $seventh->id, 'seventh window focused');
91 reset_focus $s3_ws;
92
93 cmd "workspace $s2_ws";
94 cmd 'focus right';
95 is($x->input_focus, $seventh->id, 'seventh window focused');
96 reset_focus $s3_ws;
97
98 cmd "workspace $s2_ws";
99 cmd 'focus up';
100 is($x->input_focus, $second->id, 'second window focused');
101 reset_focus $s0_ws;
102
103 ###################################################################
104 # Put the workspaces on screens 0 and 3 into vertical split mode
105 # and test focus (left|down|right|up) again.
106 ###################################################################
107
108 cmd "workspace $s0_ws";
109 is($x->input_focus, $third->id, 'third window focused');
110 cmd 'focus parent';
111 cmd 'focus parent';
112 cmd 'split v';
113 # Focus second or else $first gets to the top of the focus stack.
114 cmd '[id=' . $second->id . '] focus';
115 reset_focus $s0_ws;
116
117 cmd "workspace $s3_ws";
118 is($x->input_focus, $eighth->id, 'eighth window focused');
119 cmd 'focus parent';
120 cmd 'focus parent';
121 cmd 'split v';
122 cmd '[id=' . $sixth->id . '] focus';
123 reset_focus $s3_ws;
124
125 cmd "workspace $s1_ws";
126 cmd 'focus left';
127 is($x->input_focus, $second->id, 'second window focused');
128 reset_focus $s0_ws;
129
130 cmd "workspace $s1_ws";
131 cmd 'focus down';
132 is($x->input_focus, $sixth->id, 'sixth window focused');
133 reset_focus $s3_ws;
134
135 cmd "workspace $s2_ws";
136 cmd 'focus right';
137 is($x->input_focus, $sixth->id, 'sixth window focused');
138
139 cmd "workspace $s2_ws";
140 cmd 'focus up';
141 is($x->input_focus, $second->id, 'second window focused');
142
143 ###################################################################
144 # Test that focus (left|down|right|up), when focusing across
145 # outputs, doesn't focus the next window in the given direction but
146 # the most focused window of the container in the given direction.
147 # In the following layout:
148 # [ WS1*[ ] WS2[ H[ A B* ] ] ]
149 # (where the asterisk denotes the focused container within its
150 # parent) moving right from WS1 should focus B which is focused
151 # inside WS2, not A which is the next window on the right of WS1.
152 # See issue #1160.
153 ###################################################################
154
155 kill_all_windows;
156
157 sync_with_i3;
158 $x->root->warp_pointer(1025, 0);  # Second screen.
159 sync_with_i3;
160 $s1_ws = fresh_workspace;
161 $first = open_window;
162 $second = open_window;
163
164 sync_with_i3;
165 $x->root->warp_pointer(0, 0);  # First screen.
166 sync_with_i3;
167 $s0_ws = fresh_workspace;
168 open_window;
169 $third = open_window;
170
171 cmd 'focus right';
172 is($x->input_focus, $second->id, 'second window (rightmost) focused');
173 cmd 'focus left';
174 is($x->input_focus, $first->id, 'first window focused');
175 cmd 'focus left';
176 is($x->input_focus, $third->id, 'third window focused');
177
178
179 ###################################################################
180 # Similar but with a tabbed layout.
181 ###################################################################
182
183 cmd 'layout tabbed';
184 $fourth = open_window;
185 cmd 'focus left';
186 is($x->input_focus, $third->id, 'third window (tabbed) focused');
187 cmd "workspace $s1_ws";
188 cmd 'focus left';
189 is($x->input_focus, $third->id, 'third window (tabbed) focused');
190
191
192 ###################################################################
193 # Similar but with a stacked layout on the bottom screen.
194 ###################################################################
195
196 sync_with_i3;
197 $x->root->warp_pointer(0, 769);  # Third screen.
198 sync_with_i3;
199 $s2_ws = fresh_workspace;
200 cmd 'layout stacked';
201 $fifth = open_window;
202 $sixth = open_window;
203
204 cmd "workspace $s0_ws";
205 cmd 'focus down';
206 is($x->input_focus, $sixth->id, 'sixth window (stacked) focused');
207
208 ###################################################################
209 # Similar but with a more complex layout.
210 ###################################################################
211
212 sync_with_i3;
213 $x->root->warp_pointer(1025, 769);  # Fourth screen.
214 sync_with_i3;
215 $s3_ws = fresh_workspace;
216 open_window;
217 open_window;
218 cmd 'split v';
219 open_window;
220 open_window;
221 cmd 'split h';
222 my $nested = open_window;
223 open_window;
224 cmd 'focus left';
225 is($x->input_focus, $nested->id, 'nested window focused');
226
227 cmd "workspace $s1_ws";
228 cmd 'focus down';
229 is($x->input_focus, $nested->id, 'nested window focused from workspace above');
230
231 cmd "workspace $s2_ws";
232 cmd 'focus right';
233 is($x->input_focus, $nested->id, 'nested window focused from workspace on the left');
234
235 done_testing;