]> git.sur5r.net Git - i3/i3/blob - testcases/t/135-floating-focus.t
Merge branch 'fix-split-indicator'
[i3/i3] / testcases / t / 135-floating-focus.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 use i3test;
18
19 my $tmp = fresh_workspace;
20
21 #############################################################################
22 # 1: see if focus stays the same when toggling tiling/floating mode
23 #############################################################################
24
25 my $first = open_window;
26 my $second = open_window;
27
28 is($x->input_focus, $second->id, 'second window focused');
29
30 cmd 'floating enable';
31 cmd 'floating disable';
32
33 is($x->input_focus, $second->id, 'second window still focused after mode toggle');
34
35 #############################################################################
36 # 2: see if focus stays on the current floating window if killing another
37 # floating window
38 #############################################################################
39
40 $tmp = fresh_workspace;
41
42 $first = open_window;    # window 2
43 $second = open_window;   # window 3
44 my $third = open_window; # window 4
45
46 is($x->input_focus, $third->id, 'last container focused');
47
48 cmd 'floating enable';
49
50 cmd '[id="' . $second->id . '"] focus';
51
52 is($x->input_focus, $second->id, 'second con focused');
53
54 cmd 'floating enable';
55
56 # now kill the third one (it's floating). focus should stay unchanged
57 cmd '[id="' . $third->id . '"] kill';
58
59 wait_for_unmap($third);
60
61 is($x->input_focus, $second->id, 'second con still focused after killing third');
62
63
64 #############################################################################
65 # 3: see if the focus gets reverted correctly when closing floating clients
66 # (first to the next floating client, then to the last focused tiling client)
67 #############################################################################
68
69 $tmp = fresh_workspace;
70
71 $first = open_window({ background_color => '#ff0000' });    # window 5
72 $second = open_window({ background_color => '#00ff00' });   # window 6
73 $third = open_window({ background_color => '#0000ff' }); # window 7
74
75 is($x->input_focus, $third->id, 'last container focused');
76
77 cmd 'floating enable';
78
79 cmd '[id="' . $second->id . '"] focus';
80
81 is($x->input_focus, $second->id, 'second con focused');
82
83 cmd 'floating enable';
84
85 # now kill the second one. focus should fall back to the third one, which is
86 # also floating
87 cmd 'kill';
88 wait_for_unmap($second);
89
90 is($x->input_focus, $third->id, 'third con focused');
91
92 cmd 'kill';
93 wait_for_unmap($third);
94
95 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
96
97 #############################################################################
98 # 4: same test as 3, but with another split con
99 #############################################################################
100
101 $tmp = fresh_workspace;
102
103 $first = open_window({ background_color => '#ff0000' });    # window 5
104 cmd 'split v';
105 cmd 'layout stacked';
106 $second = open_window({ background_color => '#00ff00' });   # window 6
107 $third = open_window({ background_color => '#0000ff' }); # window 7
108
109 is($x->input_focus, $third->id, 'last container focused');
110
111 cmd 'floating enable';
112
113 cmd '[id="' . $second->id . '"] focus';
114
115 is($x->input_focus, $second->id, 'second con focused');
116
117 cmd 'floating enable';
118
119 sync_with_i3;
120
121 # now kill the second one. focus should fall back to the third one, which is
122 # also floating
123 cmd 'kill';
124 wait_for_unmap($second);
125
126 is($x->input_focus, $third->id, 'third con focused');
127
128 cmd 'kill';
129 wait_for_unmap($third);
130
131 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
132
133 #############################################################################
134 # 5: see if the 'focus tiling' and 'focus floating' commands work
135 #############################################################################
136
137 $tmp = fresh_workspace;
138
139 $first = open_window({ background_color => '#ff0000' });    # window 8
140 $second = open_window({ background_color => '#00ff00' });   # window 9
141
142 is($x->input_focus, $second->id, 'second container focused');
143
144 cmd 'floating enable';
145
146 is($x->input_focus, $second->id, 'second container focused');
147
148 cmd 'focus tiling';
149
150 is($x->input_focus, $first->id, 'first (tiling) container focused');
151
152 cmd 'focus floating';
153
154 is($x->input_focus, $second->id, 'second (floating) container focused');
155
156 cmd 'focus floating';
157
158 is($x->input_focus, $second->id, 'second (floating) container still focused');
159
160 cmd 'focus mode_toggle';
161
162 is($x->input_focus, $first->id, 'first (tiling) container focused');
163
164 cmd 'focus mode_toggle';
165
166 is($x->input_focus, $second->id, 'second (floating) container focused');
167
168 #############################################################################
169 # 6: see if switching floating focus using the focus left/right command works
170 #############################################################################
171
172 $tmp = fresh_workspace;
173
174 $first = open_floating_window({ background_color => '#ff0000' });# window 10
175 $second = open_floating_window({ background_color => '#00ff00' }); # window 11
176 $third = open_floating_window({ background_color => '#0000ff' }); # window 12
177
178 is($x->input_focus, $third->id, 'third container focused');
179
180 cmd 'focus left';
181
182 is($x->input_focus, $second->id, 'second container focused');
183
184 cmd 'focus left';
185
186 is($x->input_focus, $first->id, 'first container focused');
187
188 cmd 'focus left';
189
190 is($x->input_focus, $third->id, 'focus wrapped to third container');
191
192 cmd 'focus right';
193
194 is($x->input_focus, $first->id, 'focus wrapped to first container');
195
196 cmd 'focus right';
197
198 is($x->input_focus, $second->id, 'focus on second container');
199
200 done_testing;