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
wayland: Add support for PinchGesture and RotationGesture #3656
base: master
Are you sure you want to change the base?
Conversation
01977f7
to
5b4bb44
Compare
5b4bb44
to
50f66ed
Compare
The rotation delta is in degrees on macOS, and that's what the iOS impl tries to match as well. (Though we should perhaps change it to radians, that's the morally superior unit). |
29ee32b
to
3f20162
Compare
Thanks! Now that this other PR is merged, I’ve also implemented |
These two events are synthesized from the same event from the same protocol, zwp_pointer_gestures_v1, and will always come together. I’ve left over the third value, which is a dx/dy from the center of the gesture, it could be exposed as a 2D scroll but I feel like this should be a different event than the normal AxisMotion. The documentation doesn’t indicate the unit of the rotation, so I’ve left it as degrees. I don’t have any Apple OS where I could test whether that event is also in degrees or in radians there. The other two gestures supported by this protocol, a multi-finger swipe, and a multi-finger hold, aren’t currently matched with any event in winit, would it make sense to expose them? I’ve only tested on GNOME, but I expect other compositors to expose the same protocol eventually.
This new event is exactly what was missing for the previous commit.
3f20162
to
8815ac8
Compare
This has only been tested on Wayland against rust-windowing/winit#3656 and allows much nicer interactions when using a touchpad. The values have been chosen based on what felt pleasant to use on my Thinkpad x280, I haven’t given it much thought otherwise, and I expect other touchpads would feel different.
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.
Besides that I have no idea what pan
gesture is and that our docs are a bit confusing about it and when to use.
It seems like it's just a movement within the gesture disregarding amount of fingers, etc?
@@ -281,7 +281,7 @@ pub enum WindowEvent { | |||
/// | |||
/// ## Platform-specific | |||
/// | |||
/// - Only available on **macOS** and **iOS**. | |||
/// - Only available on **macOS**, **iOS** and **Wayland**. |
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 available on **macOS**, **iOS** and **Wayland**. | |
/// - Only available on **macOS**, **iOS**, and **Wayland**. |
@@ -297,7 +297,7 @@ pub enum WindowEvent { | |||
/// | |||
/// ## Platform-specific | |||
/// | |||
/// - Only available on **iOS**. | |||
/// - Only available on **iOS** and **Wayland**. |
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 available on **iOS** and **Wayland**. | |
/// - Only available on **iOS**, and **Wayland**. |
@@ -333,7 +333,7 @@ pub enum WindowEvent { | |||
/// | |||
/// ## Platform-specific | |||
/// | |||
/// - Only available on **macOS** and **iOS**. | |||
/// - Only available on **macOS**, **iOS** and **Wayland**. |
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 available on **macOS**, **iOS** and **Wayland**. | |
/// - Only available on **macOS**, **iOS**, and **Wayland**. |
|
||
### Added | ||
|
||
- On Wayland, add `PinchGesture`, `PanGesture` and `RotationGesture`. |
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.
https://www.grammarbook.com/blog/commas/oxford-comma/
- On Wayland, add `PinchGesture`, `PanGesture` and `RotationGesture`. | |
- On Wayland, add `PinchGesture`, `PanGesture`, and `RotationGesture`. |
(TouchPhase::Started, pan_delta, 0., 0.) | ||
}, | ||
Event::Update { time: _, dx, dy, scale, rotation } => { | ||
let pan_delta = PhysicalPosition::new(dx as f32, dy as f32); |
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.
It's in surface
coordinates, but PhysicalPosition
is buffer, you should convert from logical to physical with the function like in wl_pointer
events above.
let pan_delta = PhysicalPosition::new(0., 0.); | ||
state.previous_scale = 1.; | ||
( | ||
if cancelled == 0 { TouchPhase::Ended } else { TouchPhase::Cancelled }, |
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.
Define it on a separate line, so it'll end up more compact.
state.events_sink.push_window_event( | ||
WindowEvent::PanGesture { device_id, delta: pan_delta, phase }, | ||
state.window_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.
Isn't Pan
basically a swipe?
@madsmtm do you know about it? Also, it's strange that we don't have amount of fingers in Pan
gesture if it's so.
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.
The terminology is probably different elsewhere, but I think a pan gesture (docs) is similar, but distinct from a swipe gesture (docs); the pan is more general (e.g. moving a map around), a swipe is usually short and only in one direction (e.g. dismissing a pop-up).
It would make sense to have the number of fingers in the event.
state.events_sink.push_window_event( | ||
WindowEvent::PinchGesture { device_id, delta: scale_delta, phase }, | ||
state.window_id, | ||
); | ||
state.events_sink.push_window_event( | ||
WindowEvent::RotationGesture { device_id, delta: rotation_delta, phase }, | ||
state.window_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.
You should only send updates if there was a change compared to previous state, so if there was not pinch, but just rotation, only rotation should be send.
/// XXX: Is this really meant to stay here? | ||
pub window_id: WindowId, |
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.
No, it should be like with keyboard focus, on user data.
/// XXX: Is this really meant to stay here? | ||
pub previous_scale: f64, |
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.
No, should be on user data as well.
These two events are synthesized from the same event from the same protocol, zwp_pointer_gestures_v1, and will always come together.
I’ve left over the third value, which is a
dx
/dy
from the center of the gesture, it could be exposed as a 2D scroll but I feel like this should be a different event than the normalAxisMotion
.The documentation doesn’t indicate the unit of the rotation, so I’ve left it as degrees. I don’t have any Apple OS where I could test whether that event is also in degrees or in radians there.
The other two gestures supported by this protocol, a multi-finger swipe, and a multi-finger hold, aren’t currently matched with any event in winit, would it make sense to expose them?
I’ve only tested on GNOME, but I expect other compositors to expose the same protocol eventually.
changelog
module if knowledge of this change could be valuable to usersThe last two items aren’t needed, as they were already added for the other two platforms which support this feature.