Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11 xinput2 Support #10

Open
Fuzzyzilla opened this issue May 2, 2024 · 2 comments · May be fixed by #11
Open

X11 xinput2 Support #10

Fuzzyzilla opened this issue May 2, 2024 · 2 comments · May be fixed by #11
Labels
enhancement New feature or request x11 Specific to the X11 backend
Milestone

Comments

@Fuzzyzilla
Copy link
Owner

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:

  • Snoop events through XCheckMaskEvent. This requires octotablet to have priority control over the shared state than the windowing API that actually owns it, and could break some things. (E.g., winit would no longer send DeviceEvents.) It also ends up being super fragile on account of that shared state, like event masks and error messages, which would need to be repeatedly context-switched by octotablet unbeknownst to the window owner. If the window owner is multi-threaded (though I can't think of any that are), this is a total nonstarter.

  • Have octotablet manage it's own connection to the same server, snooping on the user window's (or possibly the root window's) events - similar to what the Wayland integration does. As far as I know, this is allowable under X. This also allows octotablet to be asynchronous in relation to the window and agnostic across Xcb or Xlib client implementations. Trouble here is I do not know of any way to reliably duplicate and Xlib or Xcb server connection in this way - just assuming the display comes from the default environment is a 99% solution but still not technically correct.

@Fuzzyzilla
Copy link
Owner Author

Fuzzyzilla commented May 20, 2024

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
Copy link
Owner Author

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).

@Fuzzyzilla Fuzzyzilla removed the help wanted Extra attention is needed label Sep 10, 2024
@Fuzzyzilla Fuzzyzilla linked a pull request Sep 15, 2024 that will close this issue
8 tasks
@Fuzzyzilla Fuzzyzilla added this to the Next Major Release milestone Sep 28, 2024
@Fuzzyzilla Fuzzyzilla added the x11 Specific to the X11 backend label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request x11 Specific to the X11 backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant