]> git.sur5r.net Git - i3/i3/blob - testcases/t/290-keypress-numlock.t
tests: implement xtest_sync_with_i3
[i3/i3] / testcases / t / 290-keypress-numlock.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 # Verifies that one can bind on numpad keys in different numlock states.
18 # Ticket: #2346
19 # Bug still in: 4.12-78-g85bb324
20 use i3test i3_autostart => 0;
21 use i3test::XTEST;
22 use ExtUtils::PkgConfig;
23
24 SKIP: {
25     skip "libxcb-xkb too old (need >= 1.11)", 1 unless
26         ExtUtils::PkgConfig->atleast_version('xcb-xkb', '1.11');
27
28 my $config = <<EOT;
29 # i3 config file (v4)
30 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
31
32 # Same key, different numlock states.
33 bindsym Mod2+KP_1 nop KP_1
34 bindsym KP_End nop KP_End
35
36 # Binding which should work with numlock and without.
37 bindsym Mod4+a nop a
38
39 # Binding which should work with numlock and without, see issue #2418.
40 bindsym Escape nop Escape
41
42 # Binding which should work with numlock and without, see issue #2418.
43 bindsym Shift+Escape nop Shift+Escape
44
45 # Binding which should work with numlock and without, see issue #2418.
46 bindsym Mod1+Shift+q nop Mod1+Shift+q
47
48 # Binding which should work with numlock and without, see issue #2559.
49 bindcode 39 nop s
50 EOT
51
52 my $pid = launch_with_config($config);
53
54 start_binding_capture;
55
56 is(listen_for_binding(
57     sub {
58         xtest_key_press(87); # KP_End
59         xtest_key_release(87); # KP_End
60         xtest_sync_with_i3;
61     },
62     ),
63    'KP_End',
64    'triggered the "KP_End" keybinding');
65
66 is(listen_for_binding(
67     sub {
68         xtest_key_press(77); # enable Num_Lock
69         xtest_key_release(77); # enable Num_Lock
70         xtest_key_press(87); # KP_1
71         xtest_key_release(87); # KP_1
72         xtest_key_press(77); # disable Num_Lock
73         xtest_key_release(77); # disable Num_Lock
74         xtest_sync_with_i3;
75     },
76     ),
77    'KP_1',
78    'triggered the "KP_1" keybinding');
79
80 is(listen_for_binding(
81     sub {
82         xtest_key_press(133); # Super_L
83         xtest_key_press(38); # a
84         xtest_key_release(38); # a
85         xtest_key_release(133); # Super_L
86         xtest_sync_with_i3;
87     },
88     ),
89    'a',
90    'triggered the "a" keybinding');
91
92 is(listen_for_binding(
93     sub {
94         xtest_key_press(77); # enable Num_Lock
95         xtest_key_release(77); # enable Num_Lock
96         xtest_key_press(133); # Super_L
97         xtest_key_press(38); # a
98         xtest_key_release(38); # a
99         xtest_key_release(133); # Super_L
100         xtest_key_press(77); # disable Num_Lock
101         xtest_key_release(77); # disable Num_Lock
102         xtest_sync_with_i3;
103     },
104     ),
105    'a',
106    'triggered the "a" keybinding');
107
108 is(listen_for_binding(
109     sub {
110         xtest_key_press(9); # Escape
111         xtest_key_release(9); # Escape
112         xtest_sync_with_i3;
113     },
114     ),
115    'Escape',
116    'triggered the "Escape" keybinding');
117
118 is(listen_for_binding(
119     sub {
120         xtest_key_press(77); # enable Num_Lock
121         xtest_key_release(77); # enable Num_Lock
122         xtest_key_press(9); # Escape
123         xtest_key_release(9); # Escape
124         xtest_key_press(77); # disable Num_Lock
125         xtest_key_release(77); # disable Num_Lock
126         xtest_sync_with_i3;
127     },
128     ),
129    'Escape',
130    'triggered the "Escape" keybinding');
131
132 is(listen_for_binding(
133     sub {
134         xtest_key_press(50); # Shift_L
135         xtest_key_press(9); # Escape
136         xtest_key_release(9); # Escape
137         xtest_key_release(50); # Shift_L
138         xtest_sync_with_i3;
139     },
140     ),
141    'Shift+Escape',
142    'triggered the "Escape" keybinding');
143
144 is(listen_for_binding(
145     sub {
146         xtest_key_press(77); # enable Num_Lock
147         xtest_key_release(77); # enable Num_Lock
148         xtest_key_press(50); # Shift_L
149         xtest_key_press(9); # Escape
150         xtest_key_release(9); # Escape
151         xtest_key_release(50); # Shift_L
152         xtest_key_press(77); # disable Num_Lock
153         xtest_key_release(77); # disable Num_Lock
154         xtest_sync_with_i3;
155     },
156     ),
157    'Shift+Escape',
158    'triggered the "Escape" keybinding');
159
160 is(listen_for_binding(
161     sub {
162         xtest_key_press(50); # Shift_L
163         xtest_key_press(64); # Alt_L
164         xtest_key_press(24); # q
165         xtest_key_release(24); # q
166         xtest_key_release(64); # Alt_L
167         xtest_key_release(50); # Shift_L
168         xtest_sync_with_i3;
169     },
170     ),
171    'Mod1+Shift+q',
172    'triggered the "Mod1+Shift+q" keybinding');
173
174 is(listen_for_binding(
175     sub {
176         xtest_key_press(77); # enable Num_Lock
177         xtest_key_release(77); # enable Num_Lock
178         xtest_key_press(50); # Shift_L
179         xtest_key_press(64); # Alt_L
180         xtest_key_press(24); # q
181         xtest_key_release(24); # q
182         xtest_key_release(64); # Alt_L
183         xtest_key_release(50); # Shift_L
184         xtest_key_press(77); # disable Num_Lock
185         xtest_key_release(77); # disable Num_Lock
186         xtest_sync_with_i3;
187     },
188     ),
189    'Mod1+Shift+q',
190    'triggered the "Mod1+Shift+q" keybinding');
191
192 is(listen_for_binding(
193     sub {
194         xtest_key_press(39); # s
195         xtest_key_release(39); # s
196         xtest_sync_with_i3;
197     },
198     ),
199    's',
200    'triggered the "s" keybinding without Num_Lock');
201
202 is(listen_for_binding(
203     sub {
204         xtest_key_press(77); # enable Num_Lock
205         xtest_key_release(77); # enable Num_Lock
206         xtest_key_press(39); # s
207         xtest_key_release(39); # s
208         xtest_key_press(77); # disable Num_Lock
209         xtest_key_release(77); # disable Num_Lock
210         xtest_sync_with_i3;
211     },
212     ),
213    's',
214    'triggered the "s" keybinding with Num_Lock');
215
216 sync_with_i3;
217 is(scalar @i3test::XTEST::binding_events, 12, 'Received exactly 12 binding events');
218
219 exit_gracefully($pid);
220
221 ################################################################################
222 # Verify bindings for modifiers work
223 ################################################################################
224
225 $config = <<EOT;
226 # i3 config file (v4)
227 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
228
229 bindsym Mod4+Return nop Return
230
231 # Binding which should work with numlock and without, see issue #2559.
232 bindcode --release 133 nop Super_L
233 EOT
234
235 $pid = launch_with_config($config);
236
237 start_binding_capture;
238
239 is(listen_for_binding(
240     sub {
241         xtest_key_press(133); # Super_L
242         xtest_key_release(133); # Super_L
243         xtest_sync_with_i3;
244     },
245     ),
246    'Super_L',
247    'triggered the "Super_L" keybinding without Num_Lock');
248
249 is(listen_for_binding(
250     sub {
251         xtest_key_press(77); # enable Num_Lock
252         xtest_key_release(77); # enable Num_Lock
253         xtest_key_press(133); # Super_L
254         xtest_key_release(133); # Super_L
255         xtest_key_press(77); # disable Num_Lock
256         xtest_key_release(77); # disable Num_Lock
257         xtest_sync_with_i3;
258     },
259     ),
260    'Super_L',
261    'triggered the "Super_L" keybinding with Num_Lock');
262
263 is(listen_for_binding(
264     sub {
265         xtest_key_press(133); # Super_L
266         xtest_key_press(36); # Return
267         xtest_key_release(36); # Return
268         xtest_key_release(133); # Super_L
269         xtest_sync_with_i3;
270     },
271     ),
272    'Return',
273    'triggered the "Return" keybinding without Num_Lock');
274
275 is(listen_for_binding(
276     sub {
277         xtest_key_press(77); # enable Num_Lock
278         xtest_key_release(77); # enable Num_Lock
279         xtest_key_press(133); # Super_L
280         xtest_key_press(36); # Return
281         xtest_key_release(36); # Return
282         xtest_key_release(133); # Super_L
283         xtest_key_press(77); # disable Num_Lock
284         xtest_key_release(77); # disable Num_Lock
285         xtest_sync_with_i3;
286     },
287     ),
288    'Return',
289    'triggered the "Return" keybinding with Num_Lock');
290
291 sync_with_i3;
292 is(scalar @i3test::XTEST::binding_events, 16, 'Received exactly 16 binding events');
293
294 exit_gracefully($pid);
295
296 ################################################################################
297 # Verify the binding is only triggered for KP_End, not KP_1
298 ################################################################################
299
300 $config = <<EOT;
301 # i3 config file (v4)
302 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
303
304 bindsym KP_End nop KP_End
305 bindcode 88 nop KP_Down
306 EOT
307
308 $pid = launch_with_config($config);
309
310 start_binding_capture;
311
312 is(listen_for_binding(
313     sub {
314         xtest_key_press(87); # KP_End
315         xtest_key_release(87); # KP_End
316         xtest_sync_with_i3;
317     },
318     ),
319    'KP_End',
320    'triggered the "KP_End" keybinding');
321
322 is(listen_for_binding(
323     sub {
324         xtest_key_press(88); # KP_Down
325         xtest_key_release(88); # KP_Down
326         xtest_sync_with_i3;
327     },
328     ),
329    'KP_Down',
330    'triggered the "KP_Down" keybinding');
331
332 is(listen_for_binding(
333     sub {
334         xtest_key_press(77); # enable Num_Lock
335         xtest_key_release(77); # enable Num_Lock
336         xtest_key_press(87); # KP_1
337         xtest_key_release(87); # KP_1
338         xtest_key_press(77); # disable Num_Lock
339         xtest_key_release(77); # disable Num_Lock
340         xtest_sync_with_i3;
341     },
342     ),
343    'timeout',
344    'Did not trigger the KP_End keybinding with KP_1');
345
346 is(listen_for_binding(
347     sub {
348         xtest_key_press(77); # enable Num_Lock
349         xtest_key_release(77); # enable Num_Lock
350         xtest_key_press(88); # KP_2
351         xtest_key_release(88); # KP_2
352         xtest_key_press(77); # disable Num_Lock
353         xtest_key_release(77); # disable Num_Lock
354         xtest_sync_with_i3;
355     },
356     ),
357    'timeout',
358    'Did not trigger the KP_Down keybinding with KP_2');
359
360 # TODO: This test does not verify that i3 does _NOT_ grab keycode 87 with Mod2.
361
362 sync_with_i3;
363 is(scalar @i3test::XTEST::binding_events, 18, 'Received exactly 18 binding events');
364
365 exit_gracefully($pid);
366
367 ################################################################################
368 # Verify mouse bindings are unaffected by NumLock
369 ################################################################################
370
371 $config = <<EOT;
372 # i3 config file (v4)
373 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
374
375 bindsym --whole-window button4 nop button4
376 EOT
377
378 $pid = launch_with_config($config);
379
380 my $win = open_window;
381
382 start_binding_capture;
383
384 is(listen_for_binding(
385     sub {
386         xtest_key_press(77); # enable Num_Lock
387         xtest_key_release(77); # enable Num_Lock
388         xtest_button_press(4, 50, 50);
389         xtest_button_release(4, 50, 50);
390         xtest_key_press(77); # disable Num_Lock
391         xtest_key_release(77); # disable Num_Lock
392         xtest_sync_with_i3;
393     },
394     ),
395    'button4',
396    'triggered the button4 keybinding with NumLock');
397
398 is(listen_for_binding(
399     sub {
400         xtest_button_press(4, 50, 50);
401         xtest_button_release(4, 50, 50);
402         xtest_sync_with_i3;
403     },
404     ),
405    'button4',
406    'triggered the button4 keybinding without NumLock');
407
408 exit_gracefully($pid);
409
410 }
411
412 done_testing;