With glib 2.28, we'll be able to have one GSource per device manager
with child sources for earch device. Make a note to update the code
in a few months.
An array is used to translate the button to its mask. Clutter defines
the masks for button 1 to 5 but we report BTN_LEFT..BTN_TASK ie
0x110..0x117. We need to pad the array for the translation not to access
random data for buttons between 0x115 and 0x117.
We know support EV_REL events comming from evdev devices. This addition
is pretty straigthforward, it adds a x,y per GSource listening to a
evdev device, updates from EL_REL (relative) events and craft new
ClutterMotionEvents. As for buttons, BTN_LEFT..BTN_TASK are translated
to ClutterButtonEvents with 1..8 as button number.
Even with udev, the read fails before udev has a chance to signal the
change. Hence (and to handle errors gracefully anyway), let's remove the
device from the device manager in case of a read() error.
The device manager now fully owns the GSources corresponding to the
devices it manages. This will allow not only to remove the source when
udev signals a device removal but also handle read() errors gracefully
by removing the faulty device from the manager.
Just connect to the GUdevClient "uevent" signal and deals with
"add"/"remove" commands. This drives the installation/removal of
GSource to listen to the device.
Let's use the sysfs path of the device to make sure we only load evdev
device, not legacy mousedev ones for instance. We rely on the sysfs
API/ABI guarantees and look for devices finishing by /input%d/event%d.
This backend is a event backend that can be enabled for EGL (for now).
It uses udev (gudev) to query input devices on a linux system, listens to
keyboard events from input devices and xkbcommon to translate raw key
codes into key keysyms.
This commit only supports key events, more to follow.
Looking at what the X11 backend does: the unicode value is being
translated to the unicode codepoint of the symbol if possible. Let's do
the same then.
Before that, key events for say KEY_Right (0xff53) had the unicode_value
set to the keysym, which meant "This key event is actually printable and
is Unicode codepoint is 0xff53", which lead to interesting results.
The wayland client code has support for translating raw linux input
device key codes coming from the wayland compositor into key symbols
thanks to libxkbcommon.
A backend directly listening to linux input devices (called evdev, just
like the Xorg one) could use exactly the same code for the translation,
so abstract it a bit in a separate file.