udev-builtin-input_id: use heuristics to detect joysticks
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 8 Apr 2022 06:21:47 +0000 (16:21 +1000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 12 Apr 2022 07:24:25 +0000 (09:24 +0200)
commitbc85f8b51d962597360e982811e674c126850f56
treef3933cb88009ea12e69f94a1afe12ab2c248d7da
parente2185ffef8c486e88b6e1dfdcea4d8cb3c3637c1
udev-builtin-input_id: use heuristics to detect joysticks

Several keyboard devices are erroneously tagged with ID_INPUT_JOYSTICK
because of random buttons they set. For example, the LiteOn Lenovo
Calliope USB Keyboard sets BTN_TRIGGER, BTN_TOP2, BTN_PINKIE and
BTN_BASE, see libinput issue 745 for details.

ID_INPUT_JOYSTICK triggers the uaccess rules, making those keyboards
easily accessible. That's not a problem in the LiteOn example since that
event node doesn't contain the normal keys and eavesdropping on volume
keys is probably not very interesting.

Improve the joystick detection by adding heuristics similar to what
libinput 1.20 uses: check for some specific set of keys that are common
on keyboards but very unlikely on joysticks. If enough of those are
present (or the device has less than 2 axes or joysticks), don't tag it
as joystick.

libinput also checks for > 10 keyboard keys, but this is not done here
to be more conservative.
src/udev/udev-builtin-input_id.c