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

Richer Touch events / unified pointer event model #336

Closed
chris-morgan opened this issue Nov 1, 2017 · 8 comments · Fixed by #3876
Closed

Richer Touch events / unified pointer event model #336

chris-morgan opened this issue Nov 1, 2017 · 8 comments · Fixed by #3876
Labels
C - needs discussion Direction must be ironed out D - hard Likely harder than most tasks here H - help wanted Someone please save us P - normal Great to have S - api Design and usability

Comments

@chris-morgan
Copy link

I note Touch, but it’s rather limited. My Surface Book, for example, has a pressure-sensitive pen, which neither Touch nor Mouse can model; and the latest such pens support tilt as well.

I suspect it’s worth looking into something like the Pointer Events API which browsers have all comparatively recently taken up.

@tomaka tomaka added the S - api Design and usability label Nov 1, 2017
@francesca64 francesca64 added H - help wanted Someone please save us C - needs discussion Direction must be ironed out D - hard Likely harder than most tasks here P - normal Great to have labels May 6, 2018
@marcianx
Copy link

I'd also like to note rust-windowing/glutin#916 which I was asked to forward to here:

The Touch event does not include a touch radius or any other obvious way to distinguish finger and stylus touch events. This is particularly useful for palm rejection on large screens when using a stylus. Could such support be added?

@francesca64 francesca64 changed the title A unified pointer model is probably a good idea Richer Touch events / unified pointer event model Jun 2, 2018
@tangmi
Copy link
Contributor

tangmi commented Sep 11, 2019

Would a precursor to this be getting pen/tablet support first (#99)?

Edit: some literature that might help implementing pointer events cross-platform: https://gist.github.com/k3a/ef98593a3571b1b399169448327ad333

Edit2: It seems like there needs to be a decision on whether to keep Mouse/Touch/Pen separate or unify them under a "PointerEvent" type. Perhaps winit could redundantly fire the separate events with the unified and let the app decide whether to handle them separately or unified (like how the web pointer events api currently is?)

@Osspial
Copy link
Contributor

Osspial commented Sep 11, 2019

@tangmi I think it goes the other way - getting richer touch support will lay the ground for adding pen/tablet events. We've slowly been making progress towards richer touch events, via recent touch pressure PRs for iOS and Windows, and I expect that once more cross-platform support for rich touch events has been added pen/tablet support won't be too much of a technical or API jump.

It seems like there needs to be a decision on whether to keep Mouse/Touch/Pen separate or unify them under a "PointerEvent" type.

That's... an intriguing idea, actually. I'd support unifying pointer events into a single type, especially since that'll improve usability in the naive case where an application is designed for just one input type and given input of a format it didn't necessarily expect.

@chris-morgan
Copy link
Author

The Pointer Events API which I suggested as a model is all about unified event types. If you’re not familiar with it, please do read up on it before implementing anything in Winit.

The web still does click events for touch and pen, mousedown et al for pen events, and scrolling/zooming for touch events (adjustable via the touch-action CSS property). Naive users should use those things rather than pointerdown et al. This is a sane model for more than just the web’s backwards compatibility, because touch should generally act differently from a mouse or pen.

@tangmi
Copy link
Contributor

tangmi commented Oct 1, 2019

@Osspial I wanted to try pen input on web through winit, so I've hacked together basic support for pointer events in winit-legacy (diff here: 2e11615...tangmi:winit-legacy-2).

Some observations that may already be known:

  • A unified pointer event API was super easy to consume from my app's point of view, although there needs to be some thought done on e.g. what pointerdown (and no button pressed) vs mousedown means, scrolling events, etc. But, I think there definitely is an argument for more semantic events on top (like mouse click, double click, two-finger zoom/pan, etc), maybe as a library that can hook into the custom events on winit 0.20?
  • The Windows provides APIs to handle all inputs in a given frame at once (which allows for handling e.g. multitouch gestures). winit (legacy) currently doesn't provide support for this?
  • Switching from multiple input event kinds to a single input event kind was disruptive enough to the API that I decided to leave the mouse events as is to keep support in third-party libraries (like imgui-winit-support). I wonder if the pointer events/richer touch event support should be considered before 0.20 is released?

Notes on this changeset:

  • Only implemented for web (via an ugly stdweb shim) and windows
  • I've routed touch and pen events (but not mouse events) through pointer events (and disabled the touch event from winit)
  • I don't fully understand how to call the pointerinfo APIs on windows, so on some hardware pen input skips?

Cheers!

@Osspial
Copy link
Contributor

Osspial commented Oct 3, 2019

@tangmi Thank you so much for investigating this!

A unified pointer event API was super easy to consume from my app's point of view, although there needs to be some thought done on e.g. what pointerdown (and no button pressed) vs mousedown means, scrolling events, etc.

I think the cleanest way to expose input-specific events would be to have an enum field within Pointer that contains any non-shared data. I don't know what to do about other sorts of events (like scrolling), though - that'll warrant some further thought.

The Windows provides APIs to handle all inputs in a given frame at once (which allows for handling e.g. multitouch gestures). winit (legacy) currently doesn't provide support for this?

I don't fully understand how to call the pointerinfo APIs on windows, so on some hardware pen input skips?

Our touch handling has been improved quite a bit on master, actually (see #991 and #1134). I'm not familiar with the specifics of how the Windows touch API works, but I'd guess that those features would be easier to support with the new implementation. That implementation also seems to handle pointerinfo gracefully.

Switching from multiple input event kinds to a single input event kind was disruptive enough to the API that I decided to leave the mouse events as is to keep support in third-party libraries (like imgui-winit-support). I wonder if the pointer events/richer touch event support should be considered before 0.20 is released?

0.20 is already big enough - I'd rather not expand its scope further and end up in a perpetual alpha. I'm totally fine with removing the old-style mouse events in a future release, though. When we're improving our APIs, we should kill the clunky, thrown-together APIs while we aren't tied to stability guarantees.

@tangmi
Copy link
Contributor

tangmi commented Nov 18, 2020

@Osspial: I'm revisiting this because I got some emails on other issues relating to this... Since 0.20 got released, is there any additional blockers preventing this? I think I can port my Windows impl to head and start the investigation/discussion for other platforms?

@kirawi
Copy link

kirawi commented Nov 22, 2020

@tangmi I was investigating doing that myself before I scrolled down to your comment. Though I'm not very familiar with the overall winit codebase, the design of the existing Touch event/struct is similar enough to your implementation that you could likely reuse much of what's already there and merge your other changes. I'm not too sure on the mouse or touchpad, however.

Here are my notes:

  • Force's Calibrated and Normalized variants look very hacky, Calibrated having the unexpected field, altitude_angle.
  • There are unecessary Options being used for both Force and Touch.

tmfink pushed a commit to tmfink/winit that referenced this issue Jan 5, 2022
Fix non-integer HiDPI support in demo
This was referenced Jul 22, 2024
kchibisov pushed a commit to daxpedda/winit that referenced this issue Oct 4, 2024
- Rename `CursorMoved` to `PointerMoved`.
- Rename `CursorEntered` to `PointerEntered`.
- Rename `CursorLeft` to `PointerLeft`.
- Rename `MouseInput` to `PointerButton`.
- Add `position` to every `PointerEvent`.
- Remove `Touch`, which is folded into the `Pointer*` events.
- New `PointerType` added to `PointerEntered` and `PointerLeft`,
  signifying which pointer type is the source of this event.
- New `PointerSource` added to `PointerMoved`, similar to `PointerType`
  but holding additional data.
- New `ButtonSource` added to `PointerButton`, similar to `PointerType`
  but holding pointer type specific buttons. Use
  `ButtonSource::mouse_button()` to easily normalize any pointer button
  type to a generic mouse button.
- In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`.
- Remove `Force::Calibrated::altitude_angle`.

Fixes rust-windowing#3833.
Fixes rust-windowing#883.
Fixes rust-windowing#336.
kchibisov added a commit to daxpedda/winit that referenced this issue Oct 8, 2024
- Rename `CursorMoved` to `PointerMoved`.
- Rename `CursorEntered` to `PointerEntered`.
- Rename `CursorLeft` to `PointerLeft`.
- Rename `MouseInput` to `PointerButton`.
- Add `position` to every `PointerEvent`.
- Remove `Touch`, which is folded into the `Pointer*` events.
- New `PointerType` added to `PointerEntered` and `PointerLeft`,
  signifying which pointer type is the source of this event.
- New `PointerSource` added to `PointerMoved`, similar to `PointerType`
  but holding additional data.
- New `ButtonSource` added to `PointerButton`, similar to `PointerType`
  but holding pointer type specific buttons. Use
  `ButtonSource::mouse_button()` to easily normalize any pointer button
  type to a generic mouse button.
- In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`.
- Remove `Force::Calibrated::altitude_angle`.

Fixes rust-windowing#3833.
Fixes rust-windowing#883.
Fixes rust-windowing#336.

Co-authored-by: Kirill Chibisov <[email protected]>
kchibisov added a commit that referenced this issue Oct 8, 2024
- Rename `CursorMoved` to `PointerMoved`.
- Rename `CursorEntered` to `PointerEntered`.
- Rename `CursorLeft` to `PointerLeft`.
- Rename `MouseInput` to `PointerButton`.
- Add `position` to every `PointerEvent`.
- Remove `Touch`, which is folded into the `Pointer*` events.
- New `PointerType` added to `PointerEntered` and `PointerLeft`,
  signifying which pointer type is the source of this event.
- New `PointerSource` added to `PointerMoved`, similar to `PointerType`
  but holding additional data.
- New `ButtonSource` added to `PointerButton`, similar to `PointerType`
  but holding pointer type specific buttons. Use
  `ButtonSource::mouse_button()` to easily normalize any pointer button
  type to a generic mouse button.
- In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`.
- Remove `Force::Calibrated::altitude_angle`.

Fixes #3833.
Fixes #883.
Fixes #336.

Co-authored-by: Kirill Chibisov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - needs discussion Direction must be ironed out D - hard Likely harder than most tasks here H - help wanted Someone please save us P - normal Great to have S - api Design and usability
Development

Successfully merging a pull request may close this issue.

8 participants