Fuzzyzilla / octotablet

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

Implementation for SDL2 #8

Closed Khalzz closed 2 months ago

Khalzz commented 2 months ago

I have seen in the examples that the implementation can be done with winit's window, but im a common user of sdl2 and im not sure if is there a way of using it with the sdl2 binding for Rust.

Fuzzyzilla commented 2 months ago

Hello!

Octotablet is generic over windowing APIs through the use of the raw-window-handle traits - which sdl2 does implement. Unfortunately, it is using version 0.5.0 of raw-window-handle while octotablet uses v0.6.0 due to it's stronger lifetime guarantees.

There are a few solutions here, we could make a PR to sdl2 to bump the version, or I could implement more versions of raw-window-handle in octotablet (with an unsafe API due to eroded safety guarantees of older versions!),

In the meantime, this is possible to implement in client code, making a thin wrapper type that that implements the newer raw-window-handle traits by deferring to the older version of the traits used by sdl2, and passing that wrapper type to octotablet::Builder::build_raw() - an unsafe function, as it would then be up to you to guarantee that the octotablet instance doesn't outlive your window.

Khalzz commented 2 months ago

Thanks for the response.

Do you know how to access to the raw window handle traits in sdl2? i since the reply i have been searching for them to make some tests with the build_raw() and sadly i cant find info about it to use

Fuzzyzilla commented 2 months ago

Support for it in sdl2 seems to be under the feature "raw-window-handle," so add

sdl2 = { version ="0.36.0", features = ["raw-window-handle"] }

to your Cargo.toml :3

That feature flag doesn't seem to be documented anywhere, but it is visible under the required features for the wgpu example of the sdl2 project. Weird!

Khalzz commented 2 months ago

Thanks, i surrendered to the idea since i found some "use of raw-window-handle" in some places, i didn't found info about how to work with it, i tested using winit and found that in Huion tablets the pressure its not working.

Even though, nice job, im looking forward to see the updates of this project. :D

Fuzzyzilla commented 2 months ago

Hello, I have made a PR with demo code for SDL2, which you can view here!

i tested using winit and found that in Huion tablets the pressure its not working.

Oh my! Would you mind opening a new issue for that with some details on your system? E.g., OS, tablet model, driver version, or some output from the eframe-viewer octotablet example. Every existing octotablet platform supports styluses with pressure sensitivity so this is probably a bug if octotablet is not properly reporting it.

If you're on windows, the Huion tablet driver has a checkbox for "Windows Ink", the API that octotablet relies on for windows, does that affect anything?

Khalzz commented 2 months ago

I didn't knew about the existence of the "windows ink api selector" on the huion drivers, i will test that and based on the output i will open the new issue.