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

wayland: Add support for PinchGesture and RotationGesture #3656

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

linkmauve
Copy link
Contributor

@linkmauve linkmauve commented Apr 27, 2024

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.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

The last two items aren’t needed, as they were already added for the other two platforms which support this feature.

@linkmauve linkmauve force-pushed the wayland-pinch-gesture branch 3 times, most recently from 01977f7 to 5b4bb44 Compare April 27, 2024 11:51
@linkmauve linkmauve mentioned this pull request Apr 27, 2024
3 tasks
@madsmtm
Copy link
Member

madsmtm commented Apr 27, 2024

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).

@linkmauve linkmauve force-pushed the wayland-pinch-gesture branch 2 times, most recently from 29ee32b to 3f20162 Compare April 27, 2024 15:46
@linkmauve
Copy link
Contributor Author

Thanks! Now that this other PR is merged, I’ve also implemented PanGesture during the pinch.

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.
linkmauve added a commit to linkmauve/gltf-viewer that referenced this pull request Apr 27, 2024
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.
Copy link
Member

@kchibisov kchibisov left a 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**.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - 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**.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - 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**.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - Only available on **macOS**, **iOS** and **Wayland**.
/// - Only available on **macOS**, **iOS**, and **Wayland**.


### Added

- On Wayland, add `PinchGesture`, `PanGesture` and `RotationGesture`.
Copy link
Member

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/

Suggested change
- 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);
Copy link
Member

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 },
Copy link
Member

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.

Comment on lines +553 to +556
state.events_sink.push_window_event(
WindowEvent::PanGesture { device_id, delta: pan_delta, phase },
state.window_id,
);
Copy link
Member

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.

Copy link
Member

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.

Comment on lines +557 to +564
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,
);
Copy link
Member

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.

Comment on lines +106 to +107
/// XXX: Is this really meant to stay here?
pub window_id: WindowId,
Copy link
Member

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.

Comment on lines +109 to +110
/// XXX: Is this really meant to stay here?
pub previous_scale: f64,
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants