rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.76k stars 892 forks source link

feat(#3759): Implements Apple Pencil double tap functionality #3768

Open ActuallyHappening opened 3 months ago

ActuallyHappening commented 3 months ago

Implements #3759 Also see #99 Based on the master branch

Ported from #3763, relevant sections pasted below:

I have tested these changes on my iPad and they work exactly as expected. In an ideal world, I would like this to be released on crates.io in a way that bevy could integrate so I could use it in my bevy application (https://github.com/bevyengine/bevy/issues/14060)

Also, the public API I have chosen seems reasonable to me but I am totally open to it being tweaked or re-worked. But I would ideally want this functionality exposed in some way without me having to maintain my own fork as bevy releases roll around. I have intentionally included #[non_exhaustive] in places that I or other developers may add or improve features to. Notably, this PR only handles pen double tap events since that is all I can physically test with my current hardware, but newer Apple Pencil models support squeeze actions that I know (theoretically) how to implement but haven't. The API intentionally allows for this addition later. The public API I added is also intended to be extendable by other platform implementations, but again I can't test them physically so haven't included here. Each section has ## Platform Specific \n - iOS only documentation for that reason.

Also, I have renamed the API name from PenEvent -> PenSpecialEvent (can refactor to SpecialPenEvent I don't mind) to disambiguate these events from the generic pen events as discussed in #99

To re-iterate why I don't think these can be implemented as part of the Web API in #99, these sorts of events are not associated with a screen tap or specific touch gesture. I want the ability to handle these events either way they are implemented however, so happy to help in any way to get this functionality into a release usable from bevy

ActuallyHappening commented 3 months ago

The windows nightly checks are failing for a completely unrelated reason

ActuallyHappening commented 3 months ago

Shouldn't this be supported on MacOS as well?

You can't connect Apple Pencils to MacOS, even using Mac Catalyst. If you can I don't know about it and would love to play around!

See #99 (comment) as well. Though I'm not entirely against just going ahead here, I would prefer if we implement barrel and eraser first and plan ahead a bit so we don't introduce another completely platform-specific event before moving WindowEvent to traits and allowing platform-specific extensions.

Hold on a minute, you can define platform specific events? That fits this PR way better than adding the current API, since this PR's API must be platform-independent but has only one implementation!

About barrel and eraser, I don't know what those are and doubt I have the hardware for it anyway since I only have an Apple Pencil Gen 2. I don't really want to implement too much more than this since it is my original use case and all I can physically test at the moment, but I could certainly add it if it will help this functionality get merged. By barrel and eraser your referring to windows stylus pens (among others)? Reading the spec I really can't find any mention of handling PenSpecialEvent::DoubleTap anywhere in any form, though I definitely might have missed something.

daxpedda commented 3 months ago

You can't connect Apple Pencils to MacOS, even using Mac Catalyst. If you can I don't know about it and would love to play around!

Its possible through Apple Sidecar or third party alternatives like Duet Display and Luna Display.

Hold on a minute, you can define platform specific events?

Unfortunately not, I was speaking about future changes to the API we have planned, where we could merge something like this without much of a second thought.

About barrel and eraser, I don't know what those are and doubt I have the hardware for it anyway since I only have an Apple Pencil Gen 2. I don't really want to implement too much more than this since it is my original use case and all I can physically test at the moment, but I could certainly add it if it will help this functionality get merged. By barrel and eraser your referring to windows stylus pens (among others)?

I think there is a misunderstanding. My proposal is to implement a basic pen API that follows the Web API spec before implementing platform specific functionality so we know how and where to fit it in the API.

Reading the spec I really can't find any mention of handling PenSpecialEvent::DoubleTap anywhere in any form, though I definitely might have missed something.

Indeed, which is why its platform specific.


I'm planning to make a PR that implements the basic pen API for Web today. So hopefully we will have a clearer picture afterwards.