]> git.sur5r.net Git - i3/i3/blob - testcases/t/156-fullscreen-focus.t
Restrict directional focus in fullscreen.
[i3/i3] / testcases / t / 156-fullscreen-focus.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Test if new containers get focused when there is a fullscreen container at
5 # the time of launching the new one. Also make sure that focusing containers
6 # in other workspaces work even when there is a fullscreen container.
7 #
8 use i3test;
9
10 my $i3 = i3(get_socket_path());
11
12 my $tmp = fresh_workspace;
13
14 ################################################################################
15 # Open the left window.
16 ################################################################################
17
18 my $left = open_window({ background_color => '#ff0000' });
19
20 is($x->input_focus, $left->id, 'left window focused');
21
22 diag("left = " . $left->id);
23
24 ################################################################################
25 # Open the right window.
26 ################################################################################
27
28 my $right = open_window({ background_color => '#00ff00' });
29
30 diag("right = " . $right->id);
31
32 ################################################################################
33 # Set the right window to fullscreen.
34 ################################################################################
35
36 cmd 'nop setting fullscreen';
37 cmd 'fullscreen';
38
39 ################################################################################
40 # Open a third window. Since we're fullscreen, the window won't be # mapped, so
41 # don't wait for it to be mapped. Instead, just send the map request and sync
42 # with i3 to make sure i3 recognizes it.
43 ################################################################################
44
45 my $third = open_window({
46         background_color => '#0000ff',
47         name => 'Third window',
48         dont_map => 1,
49     });
50
51 $third->map;
52
53 sync_with_i3;
54
55 diag("third = " . $third->id);
56
57 ################################################################################
58 # Move the window to a different workspace, and verify that the third window now
59 # gets focused in the current workspace.
60 ################################################################################
61
62 my $tmp2 = get_unused_workspace;
63
64 cmd "move workspace $tmp2";
65
66 is($x->input_focus, $third->id, 'third window focused');
67
68 ################################################################################
69 # Ensure that moving a window to a workspace which has a fullscreen window does
70 # not focus it (otherwise the user cannot get out of fullscreen mode anymore).
71 ################################################################################
72
73 $tmp = fresh_workspace;
74
75 my $fullscreen_window = open_window;
76 cmd 'fullscreen';
77
78 my $nodes = get_ws_content($tmp);
79 is(scalar @$nodes, 1, 'precisely one window');
80 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
81 my $old_id = $nodes->[0]->{id};
82
83 $tmp2 = fresh_workspace;
84 my $move_window = open_window;
85 cmd "move workspace $tmp";
86
87 cmd "workspace $tmp";
88
89 $nodes = get_ws_content($tmp);
90 is(scalar @$nodes, 2, 'precisely two windows');
91 is($nodes->[0]->{id}, $old_id, 'id unchanged');
92 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
93
94 ################################################################################
95 # Ensure it's possible to change focus if it doesn't escape the fullscreen
96 # container with fullscreen global. We can't even focus a container in a
97 # different workspace.
98 ################################################################################
99
100 cmd 'fullscreen';
101
102 $tmp = fresh_workspace;
103 cmd "workspace $tmp";
104 my $diff_ws = open_window;
105
106 $tmp2 = fresh_workspace;
107 cmd "workspace $tmp2";
108 cmd 'split h';
109
110 $left = open_window;
111 my $right1 = open_window;
112 cmd 'split v';
113 my $right2 = open_window;
114 $nodes = get_ws_content($tmp);
115
116 cmd 'focus parent';
117 cmd 'fullscreen global';
118
119 cmd '[id="' . $right1->id . '"] focus';
120 is($x->input_focus, $right1->id, 'upper right window focused');
121
122 cmd '[id="' . $right2->id . '"] focus';
123 is($x->input_focus, $right2->id, 'bottom right window focused');
124
125 cmd 'focus parent';
126 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
127
128 cmd 'focus child';
129 is($x->input_focus, $right2->id, 'bottom right window focused again');
130
131 cmd '[id="' . $left->id . '"] focus';
132 is($x->input_focus, $right2->id, 'prevented focus change to left window');
133
134 cmd 'focus up';
135 is($x->input_focus, $right1->id, 'allowed focus up');
136
137 cmd 'focus down';
138 is($x->input_focus, $right2->id, 'allowed focus down');
139
140 cmd 'focus left';
141 is($x->input_focus, $right2->id, 'prevented focus left');
142
143 cmd 'focus right';
144 is($x->input_focus, $right2->id, 'prevented focus right');
145
146 cmd 'focus down';
147 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
148
149 cmd 'focus up';
150 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
151
152 cmd '[id="' . $diff_ws->id . '"] focus';
153 is($x->input_focus, $right2->id, 'prevented focus change to different ws');
154
155 ################################################################################
156 # Same tests when we're in non-global fullscreen mode. It should now be possible
157 # to focus a container in a different workspace.
158 ################################################################################
159
160 cmd 'focus parent';
161 cmd 'fullscreen global';
162 cmd 'fullscreen';
163
164 cmd '[id="' . $right1->id . '"] focus';
165 is($x->input_focus, $right1->id, 'upper right window focused');
166
167 cmd '[id="' . $right2->id . '"] focus';
168 is($x->input_focus, $right2->id, 'bottom right window focused');
169
170 cmd 'focus parent';
171 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
172
173 cmd 'focus child';
174 is($x->input_focus, $right2->id, 'bottom right window focused again');
175
176 cmd '[id="' . $left->id . '"] focus';
177 is($x->input_focus, $right2->id, 'prevented focus change to left window');
178
179 cmd 'focus up';
180 is($x->input_focus, $right1->id, 'allowed focus up');
181
182 cmd 'focus down';
183 is($x->input_focus, $right2->id, 'allowed focus down');
184
185 cmd 'focus left';
186 is($x->input_focus, $right2->id, 'prevented focus left');
187
188 cmd 'focus right';
189 is($x->input_focus, $right2->id, 'prevented focus right');
190
191 cmd 'focus down';
192 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
193
194 cmd 'focus up';
195 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
196
197 cmd '[id="' . $diff_ws->id . '"] focus';
198 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws');
199
200 ################################################################################
201 # More testing of the interaction between wrapping and the fullscreen focus
202 # restrictions.
203 ################################################################################
204
205 cmd '[id="' . $right1->id . '"] focus';
206 is($x->input_focus, $right1->id, 'upper right window focused');
207
208 cmd 'focus parent';
209 cmd 'fullscreen';
210 cmd 'focus child';
211
212 cmd 'split v';
213 my $right12 = open_window;
214
215 cmd 'focus down';
216 is($x->input_focus, $right2->id, 'bottom right window focused');
217
218 cmd 'split v';
219 my $right22 = open_window;
220
221 cmd 'focus parent';
222 cmd 'fullscreen';
223 cmd 'focus child';
224
225 cmd 'focus down';
226 is($x->input_focus, $right2->id, 'focus did not leave parent container (1)');
227
228 cmd 'focus down';
229 is($x->input_focus, $right22->id, 'focus did not leave parent container (2)');
230
231 cmd 'focus up';
232 is($x->input_focus, $right2->id, 'focus did not leave parent container (3)');
233
234 cmd 'focus up';
235 is($x->input_focus, $right22->id, 'focus did not leave parent container (4)');
236
237 done_testing;