-
Notifications
You must be signed in to change notification settings - Fork 920
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
api: move primary from FingerId to Pointer events #3947
Conversation
1a9cfd7
to
d7e8cfe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daxpedda I left the web, since it's starting to get messy with those callbacks, so you might want to refactor things to your liking. I could still plumb those bools though.
Seems you already did.
@madsmtm I did only
true
forios
, which is likely fine, but I guess we could track based on someOption<Touch>
? I decided not to, since ios uses pointer casts for its id, etc.
Pointer cast for ID is the proper way to do this on iOS according to my research I did last time already.
I don't believe its fine to merge it with just true
.
Will look into it shortly.
MacOS, Web and Windows LGTM.
In general, my main issue is not that to e.g. track fingers like you did, but which styles + finger should result in primary tracking stuff. For example, all ios input is done the same way via touch, as I said, so e.g. pencil/pen/whatever is also going here, and given that ID is a pointer cast, it's not really a touch in some cases, and according to the primary in the web docs, it seems like for pen/whatever it should be true. |
Yes, good point, we should only apply |
That already works for Android though the way I've implemented If I read the docs correctly, it's not though for ios here, but its docs are not that clear what things actually are. That's the reason I check those |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only reviewed Android, iOS, MacOS, Web and Windows.
I believe before we merge we should let @madsmtm approve and test iOS for us.
let primary = if let UITouchType::Pencil = touch_type { | ||
true | ||
} else { | ||
ivars.fingers.set(ivars.fingers.get() + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need all of this set
logic? I think just checking the finger_id == self.primary_finger
and only updating it, like it's on Android will work the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the primary finger is lifted while other fingers are pressed, it should still be possible to recognize the same finger again when its pressed. By that logic, we should only reset the primary finger ID when all fingers are lifted.
This isn't an issue on Android because ACTION_DOWN
and ACTION_UP
only get triggered on the primary finger. So which finger exactly is the primary finger, even if it was lifted during a multi-touch interaction, is already tracked for us by the OS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @daxpedda's reasoning here. I can imagine a case like this occurring in multitasking mode, where a finger is moved from one application to another and then back again - or maybe if the user lifted the finger so briefly that the OS is able to identify the finger as being the same one.
It'd be nice to have this discussed a bit in a comment in the source code though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Android looks good!
- Add `primary` to every `PointerEvent` as a way to identify discard non-primary pointers in a | ||
multi-touch interaction. | ||
- Add `position` to every `PointerEvent`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason why these are duplicated between ### Changed
here and ### Added
above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, its because we didn't really add a new event per se, but we changed the name of an existing event.
But the pointer event overhaul is a bit too big to describe with just "what changed", so the idea was to add what changed on a syntactic level for easy migration in the ### Changed
section and add an actual description of the new API in the ### Added
one.
I'm happy to take any suggestions!
src/platform_impl/android/mod.rs
Outdated
MotionAction::Down | MotionAction::PointerDown => { | ||
let primary = action == MotionAction::Down; | ||
if primary { | ||
self.primary_pointer = finger_id.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could technically have a debug_assert_eq!(self.primary_pointer, FingerId::dummy())
here, but might be a bit too scary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do that plenty of times to check API sanity ... so I'm in favor actually.
Let me know if you approve and I'm happy to add it.
ea1e4b3
to
45ffa9f
Compare
I've pushed a separate commit with merging all the |
/// | ||
/// A pointer is considered primary when it's a mouse, the first finger in a multi-touch | ||
/// interaction, or an unknown pointer source. | ||
primary: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to link to https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary as a reference for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think, since it's present on a lot of platforms. At least one could follow up if there will be questions, but linking in docs to external resources when we can explain ourselves is a bit to much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something called "primary" is present on many platforms, but we implement the semantics of the web, which is why I thought it useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a web semantic, web also forwards platform primary information forward.
I can add, but I think it's pretty clear right now, since it states basically the same as the link, without confusing parts.
let primary = if let UITouchType::Pencil = touch_type { | ||
true | ||
} else { | ||
ivars.fingers.set(ivars.fingers.get() + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @daxpedda's reasoning here. I can imagine a case like this occurring in multitasking mode, where a finger is moved from one application to another and then back again - or maybe if the user lifted the finger so briefly that the OS is able to identify the finger as being the same one.
It'd be nice to have this discussed a bit in a comment in the source code though.
@@ -513,14 +518,35 @@ impl WinitView { | |||
) | |||
}; | |||
let window_id = window.id(); | |||
let finger_id = RootFingerId(FingerId(touch_id)); | |||
let finger_id = FingerId::from_raw(touch_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be wrong, but have opened #3970 to track there instead.
45ffa9f
to
f34ead6
Compare
Rebased/changed the type to |
f34ead6
to
753c166
Compare
Whether the pointer event is primary or not generally matters for the context where all input is done by the same event, so users can _ignore_ non-primary events since they are likely from users clicking something else with their other fingers. Having it only on a FingerId made it useless, since it's usually used to avoid multi-touch, but if you start mapping on touch event you already can track things like that yourself. Fixes #3943. Co-authored-by: daxpedda <[email protected]>
The same as for `WindowId`.
3ec95b2
to
8788675
Compare
Whether the pointer event is primary or not generally matters for the
context where all input is done by the same event, so users can
ignore non-primary events since they are likely from users clicking
something else with their other fingers.
Having it only on a FingerId made it useless, since it's usually used
to avoid multi-touch, but if you start mapping on touch event you
already can track things like that yourself.
Fixes #3943.
--
@daxpedda I left the web, since it's starting to get messy with those callbacks, so you might want to refactor things to your liking. I could still plumb those bools though.
That's also the reason PR doesn't really build.
@madsmtm I did only
true
forios
, which is likely fine, but I guess we could track based on someOption<Touch>
? I decided not to, since ios uses pointer casts for its id, etc.