aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/290-keypress-numlock.t
blob: 94a5747d0ffa9e5f4033ce71b0fab2a8c551b60b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Verifies that one can bind on numpad keys in different numlock states.
# Ticket: #2346
# Bug still in: 4.12-78-g85bb324
use i3test i3_autostart => 0;
use i3test::XTEST;
use ExtUtils::PkgConfig;

SKIP: {
    skip "libxcb-xkb too old (need >= 1.11)", 1 unless
        ExtUtils::PkgConfig->atleast_version('xcb-xkb', '1.11');

my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

# Same key, different numlock states.
bindsym Mod2+KP_1 nop KP_1
bindsym KP_End nop KP_End

# Binding which should work with numlock and without.
bindsym Mod4+a nop a

# Binding which should work with numlock and without, see issue #2418.
bindsym Escape nop Escape

# Binding which should work with numlock and without, see issue #2418.
bindsym Shift+Escape nop Shift+Escape

# Binding which should work with numlock and without, see issue #2418.
bindsym Mod1+Shift+q nop Mod1+Shift+q

# Binding which should work with numlock and without, see issue #2559.
bindcode 39 nop s
EOT

my $pid = launch_with_config($config);

is(listen_for_binding(
    sub {
        xtest_key_press(87); # KP_End
        xtest_key_release(87); # KP_End
        xtest_sync_with_i3;
    },
    ),
   'KP_End',
   'triggered the "KP_End" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(87); # KP_1
        xtest_key_release(87); # KP_1
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'KP_1',
   'triggered the "KP_1" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(133); # Super_L
        xtest_key_press(38); # a
        xtest_key_release(38); # a
        xtest_key_release(133); # Super_L
        xtest_sync_with_i3;
    },
    ),
   'a',
   'triggered the "a" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(133); # Super_L
        xtest_key_press(38); # a
        xtest_key_release(38); # a
        xtest_key_release(133); # Super_L
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'a',
   'triggered the "a" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(9); # Escape
        xtest_key_release(9); # Escape
        xtest_sync_with_i3;
    },
    ),
   'Escape',
   'triggered the "Escape" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(9); # Escape
        xtest_key_release(9); # Escape
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'Escape',
   'triggered the "Escape" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(50); # Shift_L
        xtest_key_press(9); # Escape
        xtest_key_release(9); # Escape
        xtest_key_release(50); # Shift_L
        xtest_sync_with_i3;
    },
    ),
   'Shift+Escape',
   'triggered the "Escape" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(50); # Shift_L
        xtest_key_press(9); # Escape
        xtest_key_release(9); # Escape
        xtest_key_release(50); # Shift_L
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'Shift+Escape',
   'triggered the "Escape" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(50); # Shift_L
        xtest_key_press(64); # Alt_L
        xtest_key_press(24); # q
        xtest_key_release(24); # q
        xtest_key_release(64); # Alt_L
        xtest_key_release(50); # Shift_L
        xtest_sync_with_i3;
    },
    ),
   'Mod1+Shift+q',
   'triggered the "Mod1+Shift+q" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(50); # Shift_L
        xtest_key_press(64); # Alt_L
        xtest_key_press(24); # q
        xtest_key_release(24); # q
        xtest_key_release(64); # Alt_L
        xtest_key_release(50); # Shift_L
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'Mod1+Shift+q',
   'triggered the "Mod1+Shift+q" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(39); # s
        xtest_key_release(39); # s
        xtest_sync_with_i3;
    },
    ),
   's',
   'triggered the "s" keybinding without Num_Lock');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(39); # s
        xtest_key_release(39); # s
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   's',
   'triggered the "s" keybinding with Num_Lock');

exit_gracefully($pid);

################################################################################
# Verify bindings for modifiers work
################################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bindsym Mod4+Return nop Return

# Binding which should work with numlock and without, see issue #2559.
bindcode --release 133 nop Super_L
EOT

$pid = launch_with_config($config);

is(listen_for_binding(
    sub {
        xtest_key_press(133); # Super_L
        xtest_key_release(133); # Super_L
        xtest_sync_with_i3;
    },
    ),
   'Super_L',
   'triggered the "Super_L" keybinding without Num_Lock');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(133); # Super_L
        xtest_key_release(133); # Super_L
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'Super_L',
   'triggered the "Super_L" keybinding with Num_Lock');

is(listen_for_binding(
    sub {
        xtest_key_press(133); # Super_L
        xtest_key_press(36); # Return
        xtest_key_release(36); # Return
        xtest_key_release(133); # Super_L
        xtest_sync_with_i3;
    },
    ),
   'Return',
   'triggered the "Return" keybinding without Num_Lock');

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(133); # Super_L
        xtest_key_press(36); # Return
        xtest_key_release(36); # Return
        xtest_key_release(133); # Super_L
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'Return',
   'triggered the "Return" keybinding with Num_Lock');

exit_gracefully($pid);

################################################################################
# Verify the binding is only triggered for KP_End, not KP_1
################################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bindsym KP_End nop KP_End
bindcode 88 nop KP_Down
EOT

$pid = launch_with_config($config);

is(listen_for_binding(
    sub {
        xtest_key_press(87); # KP_End
        xtest_key_release(87); # KP_End
        xtest_sync_with_i3;
    },
    ),
   'KP_End',
   'triggered the "KP_End" keybinding');

is(listen_for_binding(
    sub {
        xtest_key_press(88); # KP_Down
        xtest_key_release(88); # KP_Down
        xtest_sync_with_i3;
    },
    ),
   'KP_Down',
   'triggered the "KP_Down" keybinding');

my @unexpected = events_for(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(87); # KP_1
        xtest_key_release(87); # KP_1
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    'binding');
is(scalar @unexpected, 0, 'Did not trigger the KP_End keybinding with KP_1');

my @unexpected2 = events_for(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_key_press(88); # KP_2
        xtest_key_release(88); # KP_2
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    'binding');

is(scalar @unexpected2, 0, 'Did not trigger the KP_Down keybinding with KP_2');

# TODO: This test does not verify that i3 does _NOT_ grab keycode 87 with Mod2.

exit_gracefully($pid);

################################################################################
# Verify mouse bindings are unaffected by NumLock
################################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bindsym --whole-window button4 nop button4
EOT

$pid = launch_with_config($config);

my $win = open_window;

is(listen_for_binding(
    sub {
        xtest_key_press(77); # enable Num_Lock
        xtest_key_release(77); # enable Num_Lock
        xtest_button_press(4, 50, 50);
        xtest_button_release(4, 50, 50);
        xtest_key_press(77); # disable Num_Lock
        xtest_key_release(77); # disable Num_Lock
        xtest_sync_with_i3;
    },
    ),
   'button4',
   'triggered the button4 keybinding with NumLock');

is(listen_for_binding(
    sub {
        xtest_button_press(4, 50, 50);
        xtest_button_release(4, 50, 50);
        xtest_sync_with_i3;
    },
    ),
   'button4',
   'triggered the button4 keybinding without NumLock');

exit_gracefully($pid);

}

done_testing;