]> git.sur5r.net Git - i3/i3/blob - testcases/t/264-keypress-numlock.t
464fe7481a7fc97752db3368a38cd250f6c9a333
[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 the binding is only triggered for KP_End, not KP_1
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 KP_End nop KP_End
218 bindcode 88 nop KP_Down
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(87); # KP_End
228         xtest_key_release(87); # KP_End
229     },
230     ),
231    'KP_End',
232    'triggered the "KP_End" keybinding');
233
234 is(listen_for_binding(
235     sub {
236         xtest_key_press(88); # KP_Down
237         xtest_key_release(88); # KP_Down
238     },
239     ),
240    'KP_Down',
241    'triggered the "KP_Down" keybinding');
242
243 is(listen_for_binding(
244     sub {
245         xtest_key_press(77); # enable Num_Lock
246         xtest_key_release(77); # enable Num_Lock
247         xtest_key_press(87); # KP_1
248         xtest_key_release(87); # KP_1
249         xtest_key_press(77); # disable Num_Lock
250         xtest_key_release(77); # disable Num_Lock
251     },
252     ),
253    'timeout',
254    'Did not trigger the KP_End keybinding with KP_1');
255
256 is(listen_for_binding(
257     sub {
258         xtest_key_press(77); # enable Num_Lock
259         xtest_key_release(77); # enable Num_Lock
260         xtest_key_press(88); # KP_2
261         xtest_key_release(88); # KP_2
262         xtest_key_press(77); # disable Num_Lock
263         xtest_key_release(77); # disable Num_Lock
264     },
265     ),
266    'timeout',
267    'Did not trigger the KP_Down keybinding with KP_2');
268
269 # TODO: This test does not verify that i3 does _NOT_ grab keycode 87 with Mod2.
270
271 sync_with_i3;
272 is(scalar @i3test::XTEST::binding_events, 14, 'Received exactly 14 binding events');
273
274 exit_gracefully($pid);
275
276 }
277
278 done_testing;