Skip to content

Commit

Permalink
wayland: Also synthesize PanGesture from a pinch
Browse files Browse the repository at this point in the history
This new event is exactly what was missing for the previous commit.
  • Loading branch information
linkmauve committed Apr 27, 2024
1 parent 4e04741 commit 8815ac8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ changelog entry.

### Added

- On Wayland, add `PinchGesture` and `RotationGesture`
- On Wayland, add `PinchGesture`, `PanGesture` and `RotationGesture`.
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub enum WindowEvent {
///
/// ## Platform-specific
///
/// - Only available on **iOS**.
/// - Only available on **iOS** and **Wayland**.
/// - On iOS, not recognized by default. It must be enabled when needed.
PanGesture {
device_id: DeviceId,
Expand Down
22 changes: 17 additions & 5 deletions src/platform_impl/linux/wayland/seat/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ impl Dispatch<ZwpPointerGesturePinchV1, GlobalData, WinitState> for PointerGestu
_qhandle: &QueueHandle<WinitState>,
) {
let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId));
let (phase, scale_delta, rotation_delta) = match event {
let (phase, pan_delta, scale_delta, rotation_delta) = match event {
Event::Begin { time: _, serial: _, surface, fingers } => {
if fingers != 2 {
// We only support two fingers for now.
Expand All @@ -526,22 +526,34 @@ impl Dispatch<ZwpPointerGesturePinchV1, GlobalData, WinitState> for PointerGestu
None => return,
};

let pan_delta = PhysicalPosition::new(0., 0.);
state.window_id = wayland::make_wid(parent_surface);
state.previous_scale = 1.;

(TouchPhase::Started, 0., 0.)
(TouchPhase::Started, pan_delta, 0., 0.)
},
Event::Update { time: _, dx: _, dy: _, scale, rotation } => {
Event::Update { time: _, dx, dy, scale, rotation } => {
let pan_delta = PhysicalPosition::new(dx as f32, dy as f32);
let scale_delta = scale - state.previous_scale;
state.previous_scale = scale;
(TouchPhase::Moved, scale_delta, -rotation as f32)
(TouchPhase::Moved, pan_delta, scale_delta, -rotation as f32)
},
Event::End { time: _, serial: _, cancelled } => {
let pan_delta = PhysicalPosition::new(0., 0.);
state.previous_scale = 1.;
(if cancelled == 0 { TouchPhase::Ended } else { TouchPhase::Cancelled }, 0., 0.)
(
if cancelled == 0 { TouchPhase::Ended } else { TouchPhase::Cancelled },
pan_delta,
0.,
0.,
)
},
_ => unreachable!("Unknown event {event:?}"),
};
state.events_sink.push_window_event(
WindowEvent::PanGesture { device_id, delta: pan_delta, phase },
state.window_id,
);
state.events_sink.push_window_event(
WindowEvent::PinchGesture { device_id, delta: scale_delta, phase },
state.window_id,
Expand Down

0 comments on commit 8815ac8

Please sign in to comment.