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