2 # vim:ts=4:sw=4:expandtab
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.
10 my $i3 = i3(get_socket_path());
12 my $tmp = fresh_workspace;
14 ################################################################################
15 # Open the left window.
16 ################################################################################
18 my $left = open_window({ background_color => '#ff0000' });
20 is($x->input_focus, $left->id, 'left window focused');
22 diag("left = " . $left->id);
24 ################################################################################
25 # Open the right window.
26 ################################################################################
28 my $right = open_window({ background_color => '#00ff00' });
30 diag("right = " . $right->id);
32 ################################################################################
33 # Set the right window to fullscreen.
34 ################################################################################
36 cmd 'nop setting fullscreen';
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 ################################################################################
45 my $third = open_window({
46 background_color => '#0000ff',
47 name => 'Third window',
55 diag("third = " . $third->id);
57 ################################################################################
58 # Move the window to a different workspace, and verify that the third window now
59 # gets focused in the current workspace.
60 ################################################################################
62 my $tmp2 = get_unused_workspace;
64 cmd "move workspace $tmp2";
66 is($x->input_focus, $third->id, 'third window focused');
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 ################################################################################
73 $tmp = fresh_workspace;
75 my $fullscreen_window = open_window;
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};
83 $tmp2 = fresh_workspace;
84 my $move_window = open_window;
85 cmd "move workspace $tmp";
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');
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 ################################################################################
102 $tmp = fresh_workspace;
103 cmd "workspace $tmp";
104 my $diff_ws = open_window;
106 $tmp2 = fresh_workspace;
107 cmd "workspace $tmp2";
111 my $right1 = open_window;
113 my $right2 = open_window;
114 $nodes = get_ws_content($tmp);
117 cmd 'fullscreen global';
119 cmd '[id="' . $right1->id . '"] focus';
120 is($x->input_focus, $right1->id, 'upper right window focused');
122 cmd '[id="' . $right2->id . '"] focus';
123 is($x->input_focus, $right2->id, 'bottom right window focused');
126 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
129 is($x->input_focus, $right2->id, 'bottom right window focused again');
131 cmd '[id="' . $left->id . '"] focus';
132 is($x->input_focus, $right2->id, 'prevented focus change to left window');
135 is($x->input_focus, $right1->id, 'allowed focus up');
138 is($x->input_focus, $right2->id, 'allowed focus down');
141 is($x->input_focus, $right2->id, 'prevented focus left');
144 is($x->input_focus, $right2->id, 'prevented focus right');
147 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
150 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
152 cmd '[id="' . $diff_ws->id . '"] focus';
153 is($x->input_focus, $right2->id, 'prevented focus change to different ws');
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 ################################################################################
161 cmd 'fullscreen global';
164 cmd '[id="' . $right1->id . '"] focus';
165 is($x->input_focus, $right1->id, 'upper right window focused');
167 cmd '[id="' . $right2->id . '"] focus';
168 is($x->input_focus, $right2->id, 'bottom right window focused');
171 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
174 is($x->input_focus, $right2->id, 'bottom right window focused again');
176 cmd '[id="' . $left->id . '"] focus';
177 is($x->input_focus, $right2->id, 'prevented focus change to left window');
180 is($x->input_focus, $right1->id, 'allowed focus up');
183 is($x->input_focus, $right2->id, 'allowed focus down');
186 is($x->input_focus, $right2->id, 'prevented focus left');
189 is($x->input_focus, $right2->id, 'prevented focus right');
192 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
195 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
197 cmd '[id="' . $diff_ws->id . '"] focus';
198 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws');
200 ################################################################################
201 # More testing of the interaction between wrapping and the fullscreen focus
203 ################################################################################
205 cmd '[id="' . $right1->id . '"] focus';
206 is($x->input_focus, $right1->id, 'upper right window focused');
213 my $right12 = open_window;
216 is($x->input_focus, $right2->id, 'bottom right window focused');
219 my $right22 = open_window;
226 is($x->input_focus, $right2->id, 'focus did not leave parent container (1)');
229 is($x->input_focus, $right22->id, 'focus did not leave parent container (2)');
232 is($x->input_focus, $right2->id, 'focus did not leave parent container (3)');
235 is($x->input_focus, $right22->id, 'focus did not leave parent container (4)');