Fuzzyzilla / octotablet

High-level Tablet/Stylus API for Rust
https://crates.io/crates/octotablet
MIT License
14 stars 2 forks source link

X11 `xinput2` Support #10

Open Fuzzyzilla opened 2 months ago

Fuzzyzilla commented 2 months ago

Support X11 through the XInputExtension version 2.2 interface.

Some attempts have been made to introduce this into octotablet - as of now, I have some rudimentary tablet device capabilities listing - however I have repeatedly run into a fundamental issue: xlib and xcb are extraordinarily stateful. Snooping on and snatching events from a given windowing interface (i.e. winit, sdl2) through their Display pointer is a deeply fragile process due to this shared and unsynchronized state. Often times, winit will unpredictably panic (understandably!) due to the tiniest meddling.

The two solutions I have thought of are:

Fuzzyzilla commented 1 month ago

After some more tinkering, a two-client system works great, and basic stylus events are printed out in my tests. Xorg does indeed allow several clients to listen to events on the same window, but contrary to the cursed display-sharing technique attempted before, each client gets it's own event queue and no thrashing of global state occurs. The problem of correctly duplicating a connection to the same server as another display pointer remains, but I suppose that will just have to remain a limitation. As far as I know, there does not exist a windowing abstraction API that allows anything other than the default display anyway, so I suppose it should be fine!

Following more experiments to ensure every part of the API that I will need to touch is working as expected under this less-than-normal circumstance, I will begin to work on a PR :3

Fuzzyzilla commented 1 month ago

An unfortunate roadblock was hit a few hundred lines into the implementation, in that Xlib uses global variables for the error handling state and thus it is not possible to soundly maintain two independent clients in the same process unless they coordinate in some way. I probably shoulda spotted this sooner before pouring a good number of hours into it!

I suppose a rewrite in x11rb is needed as the usual alternative, xcb, does not support the xinput2 extension (or at least, I cannot figure how to configure it to generate the necessary glue code).