While you (yes, you! no, not you, the one behind you) have been sweltering in
the heatwaves of the northern hemispheres (Assisted-by: AI), I've been busy
adding graphics tablet support to libei. This is scheduled for the soon to be
released libei 1.7.0.
The initial work was done by Jason Gerecke and Josh Dickens from Wacom, I've
been extending, polishing and testing it for the last few weeks.
Also, upfront: this only covers the stylus part of a tablet, we do not yet have
an implementation for the "pad" part (the buttons, dials, rings, strips).
libei is, of course, the library for Emulated Input, a good-enough transport
layer for sending logical input events between processes. We're already using
libei as part of the XDG Portal Remote Desktop and Input Capture portals where
we've been busy hurtling key and pointer events between the participating
parties (and soon
gesture
events
and
text
).
In the next release of libei, we will now also have "ei stylus" capabilities, i.e.
the ability to send tablet stylus events. Getting pointer, keyboard and touch events
supported was a long undertaking, everything was new and shiny and needed to be
added everywhere in the stack. Now that all this is in place, scuffed and scratched,
adding tablet events will be quite simple.
The ei stylus interface
Here's a short outline of how libei handles tablet events because it is, of
course, different to how libinput handles them. Logical events are much nicer
after all than physical hardware events.
First: we have a new interface: "ei_stylus". An EIS implementation (e.g. your
compositor) may provide you, the libei client, with a device that supports this
interface and one or more associated regions (typically representing the
available screen areas). Typically this will be a separate device to the
pointer devices or the keyboard devices but it's not a requirement. The
ei_stylus interface comes with a bunch of capabilities you'd expect from a stylus
(tilt, pressure, distance, ...) that you can selectively enable to emulate the
stylus you want to. So basically, EIS will say "here's a stylus device, I support
pressure, tilt, rotation, ..." and then the libei client says "This stylus should have
pressure and tilt but nothing else". And then you do the normal thing: send
proximity events, send tip down/up events, send data for the various
capabilities you've enabled.
Happily for the EIS implementation, libei forces the client to take the
guesswork out of everything: if you select the pressure capability, you must
send a pressure value when coming into proximity. Where libei is used to
forward data from a physical stylus (e.g. via some remoting protocol) it is
up to the client to deal with firmware bugs that e.g. won't send data
until a few frames in.
Note that there is no "tablet" anywhere. The tablet is represented by the
region that the device may interact with. So in some ways every tablet is an
on-screen tablet (which makes sense since we have logical events).
Multiple styli
The only quirky thing is how to request multiple styli[1]: libei 1.5.0 has
added a "request device" request that allows a client to say "hey, EIS, I
want a new device with capabilities pointer, keyboard, ...". And, if you've
been a nice client, minding your own business, the EIS implementation may
just create such a device for you.
So for the case of multiple styli: if the default stylus (if any) isn't
good enough, you can now tell EIS that you want a(nother) device with stylus
capability, configure the stylus capabilities once the device shows up
and voila, you now have a normal pen, an art pen and maybe even an airbrush
represented as logical device in libei. And since they're all separate
devices in the protocol, they can be individually tracked and used, much like
libinput tracks individual styli.
[1] For the "lots" of users that actually use multiple styli...