]> git.sur5r.net Git - i3/i3/blob - testcases/t/264-keypress-numlock.t
Fix --release bindings broken by previous commit
[i3/i3] / testcases / t / 264-keypress-numlock.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 # 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 # Binding which should work with numlock and without, see issue #2559.
218 bindcode --release 133 nop Super_L
219 EOT
220
221 $pid = launch_with_config($config);
222
223 start_binding_capture;
224
225 is(listen_for_binding(
226     sub {
227         xtest_key_press(133); # Super_L
228         xtest_key_release(133); # Super_L
229     },
230     ),
231    'Super_L',
232    'triggered the "Super_L" keybinding without Num_Lock');
233
234 is(listen_for_binding(
235     sub {
236         xtest_key_press(77); # enable Num_Lock
237         xtest_key_release(77); # enable Num_Lock
238         xtest_key_press(133); # Super_L
239         xtest_key_release(133); # Super_L
240         xtest_key_press(77); # disable Num_Lock
241         xtest_key_release(77); # disable Num_Lock
242     },
243     ),
244    'Super_L',
245    'triggered the "Super_L" keybinding with Num_Lock');
246
247 sync_with_i3;
248 is(scalar @i3test::XTEST::binding_events, 14, 'Received exactly 14 binding events');
249
250 exit_gracefully($pid);
251
252 ################################################################################
253 # Verify the binding is only triggered for KP_End, not KP_1
254 ################################################################################
255
256 $config = <<EOT;
257 # i3 config file (v4)
258 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
259
260 bindsym KP_End nop KP_End
261 bindcode 88 nop KP_Down
262 EOT
263
264 $pid = launch_with_config($config);
265
266 start_binding_capture;
267
268 is(listen_for_binding(
269     sub {
270         xtest_key_press(87); # KP_End
271         xtest_key_release(87); # KP_End
272     },
273     ),
274    'KP_End',
275    'triggered the "KP_End" keybinding');
276
277 is(listen_for_binding(
278     sub {
279         xtest_key_press(88); # KP_Down
280         xtest_key_release(88); # KP_Down
281     },
282     ),
283    'KP_Down',
284    'triggered the "KP_Down" keybinding');
285
286 is(listen_for_binding(
287     sub {
288         xtest_key_press(77); # enable Num_Lock
289         xtest_key_release(77); # enable Num_Lock
290         xtest_key_press(87); # KP_1
291         xtest_key_release(87); # KP_1
292         xtest_key_press(77); # disable Num_Lock
293         xtest_key_release(77); # disable Num_Lock
294     },
295     ),
296    'timeout',
297    'Did not trigger the KP_End keybinding with KP_1');
298
299 is(listen_for_binding(
300     sub {
301         xtest_key_press(77); # enable Num_Lock
302         xtest_key_release(77); # enable Num_Lock
303         xtest_key_press(88); # KP_2
304         xtest_key_release(88); # KP_2
305         xtest_key_press(77); # disable Num_Lock
306         xtest_key_release(77); # disable Num_Lock
307     },
308     ),
309    'timeout',
310    'Did not trigger the KP_Down keybinding with KP_2');
311
312 # TODO: This test does not verify that i3 does _NOT_ grab keycode 87 with Mod2.
313
314 sync_with_i3;
315 is(scalar @i3test::XTEST::binding_events, 16, 'Received exactly 16 binding events');
316
317 exit_gracefully($pid);
318
319 }
320
321 done_testing;