]> git.sur5r.net Git - i3/i3/blob - testcases/t/264-keypress-numlock.t
Bugfix: don’t apply shift+numlock fallback for keypad keys
[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 EOT
48
49 my $pid = launch_with_config($config);
50
51 start_binding_capture;
52
53 is(listen_for_binding(
54     sub {
55         xtest_key_press(87); # KP_End
56         xtest_key_release(87); # KP_End
57     },
58     ),
59    'KP_End',
60    'triggered the "KP_End" keybinding');
61
62 is(listen_for_binding(
63     sub {
64         xtest_key_press(77); # enable Num_Lock
65         xtest_key_release(77); # enable Num_Lock
66         xtest_key_press(87); # KP_1
67         xtest_key_release(87); # KP_1
68         xtest_key_press(77); # disable Num_Lock
69         xtest_key_release(77); # disable Num_Lock
70     },
71     ),
72    'KP_1',
73    'triggered the "KP_1" keybinding');
74
75 is(listen_for_binding(
76     sub {
77         xtest_key_press(133); # Super_L
78         xtest_key_press(38); # a
79         xtest_key_release(38); # a
80         xtest_key_release(133); # Super_L
81     },
82     ),
83    'a',
84    'triggered the "a" keybinding');
85
86 is(listen_for_binding(
87     sub {
88         xtest_key_press(77); # enable Num_Lock
89         xtest_key_release(77); # enable Num_Lock
90         xtest_key_press(133); # Super_L
91         xtest_key_press(38); # a
92         xtest_key_release(38); # a
93         xtest_key_release(133); # Super_L
94         xtest_key_press(77); # disable Num_Lock
95         xtest_key_release(77); # disable Num_Lock
96     },
97     ),
98    'a',
99    'triggered the "a" keybinding');
100
101 is(listen_for_binding(
102     sub {
103         xtest_key_press(9); # Escape
104         xtest_key_release(9); # Escape
105     },
106     ),
107    'Escape',
108    'triggered the "Escape" keybinding');
109
110 is(listen_for_binding(
111     sub {
112         xtest_key_press(77); # enable Num_Lock
113         xtest_key_release(77); # enable Num_Lock
114         xtest_key_press(9); # Escape
115         xtest_key_release(9); # Escape
116         xtest_key_press(77); # disable Num_Lock
117         xtest_key_release(77); # disable Num_Lock
118     },
119     ),
120    'Escape',
121    'triggered the "Escape" keybinding');
122
123 is(listen_for_binding(
124     sub {
125         xtest_key_press(50); # Shift_L
126         xtest_key_press(9); # Escape
127         xtest_key_release(9); # Escape
128         xtest_key_release(50); # Shift_L
129     },
130     ),
131    'Shift+Escape',
132    'triggered the "Escape" keybinding');
133
134 is(listen_for_binding(
135     sub {
136         xtest_key_press(77); # enable Num_Lock
137         xtest_key_release(77); # enable Num_Lock
138         xtest_key_press(50); # Shift_L
139         xtest_key_press(9); # Escape
140         xtest_key_release(9); # Escape
141         xtest_key_release(50); # Shift_L
142         xtest_key_press(77); # disable Num_Lock
143         xtest_key_release(77); # disable Num_Lock
144     },
145     ),
146    'Shift+Escape',
147    'triggered the "Escape" keybinding');
148
149 is(listen_for_binding(
150     sub {
151         xtest_key_press(50); # Shift_L
152         xtest_key_press(64); # Alt_L
153         xtest_key_press(24); # q
154         xtest_key_release(24); # q
155         xtest_key_release(64); # Alt_L
156         xtest_key_release(50); # Shift_L
157     },
158     ),
159    'Mod1+Shift+q',
160    'triggered the "Mod1+Shift+q" keybinding');
161
162
163 is(listen_for_binding(
164     sub {
165         xtest_key_press(77); # enable Num_Lock
166         xtest_key_release(77); # enable Num_Lock
167         xtest_key_press(50); # Shift_L
168         xtest_key_press(64); # Alt_L
169         xtest_key_press(24); # q
170         xtest_key_release(24); # q
171         xtest_key_release(64); # Alt_L
172         xtest_key_release(50); # Shift_L
173         xtest_key_press(77); # disable Num_Lock
174         xtest_key_release(77); # disable Num_Lock
175     },
176     ),
177    'Mod1+Shift+q',
178    'triggered the "Mod1+Shift+q" keybinding');
179
180 sync_with_i3;
181 is(scalar @i3test::XTEST::binding_events, 10, 'Received exactly 10 binding events');
182
183 exit_gracefully($pid);
184
185 ################################################################################
186 # Verify the binding is only triggered for KP_End, not KP_1
187 ################################################################################
188
189 $config = <<EOT;
190 # i3 config file (v4)
191 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
192
193 bindsym KP_End nop KP_End
194 EOT
195
196 $pid = launch_with_config($config);
197
198 start_binding_capture;
199
200 is(listen_for_binding(
201     sub {
202         xtest_key_press(87); # KP_End
203         xtest_key_release(87); # KP_End
204     },
205     ),
206    'KP_End',
207    'triggered the "KP_End" keybinding');
208
209 is(listen_for_binding(
210     sub {
211         xtest_key_press(77); # enable Num_Lock
212         xtest_key_release(77); # enable Num_Lock
213         xtest_key_press(87); # KP_1
214         xtest_key_release(87); # KP_1
215         xtest_key_press(77); # disable Num_Lock
216         xtest_key_release(77); # disable Num_Lock
217     },
218     ),
219    'timeout',
220    'Did not trigger the KP_End keybinding with KP_1');
221
222 # TODO: This test does not verify that i3 does _NOT_ grab keycode 87 with Mod2.
223
224 sync_with_i3;
225 is(scalar @i3test::XTEST::binding_events, 11, 'Received exactly 11 binding events');
226
227 exit_gracefully($pid);
228
229 }
230
231 done_testing;