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