Skip to content

Commit

Permalink
Add smart magnify gesture support for macOS (#2554)
Browse files Browse the repository at this point in the history
* Add smart magnification gesture

* Deliver position of smart magnification event

* Document smart magnification event

* Revert "Deliver position of smart magnification event"

This reverts commit ac0e61a.

* Remove mention of touchpad from smart magnification event

* Update change log

* Mention minimum macOS version supporting smart magnification

* Improve doc
  • Loading branch information
jim-ec authored Jan 21, 2023
1 parent a867032 commit d448d3e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- **Breaking:** Split the `platform::unix` module into `platform::x11` and `platform::wayland`. The extension types are similarly renamed.
- **Breaking:**: Removed deprecated method `platform::unix::WindowExtUnix::is_ready`.
- Removed `parking_lot` dependency.
- **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`.
- **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`. Also add support for touchpad smart-magnification gesture with a new event `WindowEvent::SmartMagnify`.
- **Breaking:** On web, the `WindowBuilderExtWebSys::with_prevent_default` setting (enabled by default), now additionally prevents scrolling of the webpage in mobile browsers, previously it only disabled scrolling on desktop.
- On Wayland, `wayland-csd-adwaita` now uses `ab_glyph` instead of `crossfont` to render the title for decorations.
- On Wayland, a new `wayland-csd-adwaita-crossfont` feature was added to use `crossfont` instead of `ab_glyph` for decorations.
Expand Down
3 changes: 3 additions & 0 deletions examples/touchpad_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ fn main() {
println!("Zoomed out {}", delta);
}
}
WindowEvent::SmartMagnify { .. } => {
println!("Smart zoom");
}
WindowEvent::TouchpadRotate { delta, .. } => {
if delta > 0.0 {
println!("Rotated counterclockwise {}", delta);
Expand Down
23 changes: 23 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,25 @@ pub enum WindowEvent<'a> {
phase: TouchPhase,
},

/// Smart magnification event.
///
/// On a Mac, smart magnification is triggered by a double tap with two fingers
/// on the trackpad and is commonly used to zoom on a certain object
/// (e.g. a paragraph of a PDF) or (sort of like a toggle) to reset any zoom.
/// The gesture is also supported in Safari, Pages, etc.
///
/// The event is general enough that its generating gesture is allowed to vary
/// across platforms. It could also be generated by another device.
///
/// Unfortunatly, neither [Windows](https://support.microsoft.com/en-us/windows/touch-gestures-for-windows-a9d28305-4818-a5df-4e2b-e5590f850741)
/// nor [Wayland](https://wayland.freedesktop.org/libinput/doc/latest/gestures.html)
/// support this gesture or any other gesture with the same effect.
///
/// ## Platform-specific
///
/// - Only available on **macOS 10.8** and later.
SmartMagnify { device_id: DeviceId },

/// Touchpad rotation event with two-finger rotation gesture.
///
/// Positive delta values indicate rotation counterclockwise and
Expand Down Expand Up @@ -594,6 +613,9 @@ impl Clone for WindowEvent<'static> {
delta: *delta,
phase: *phase,
},
SmartMagnify { device_id } => SmartMagnify {
device_id: *device_id,
},
TouchpadRotate {
device_id,
delta,
Expand Down Expand Up @@ -700,6 +722,7 @@ impl<'a> WindowEvent<'a> {
delta,
phase,
}),
SmartMagnify { device_id } => Some(SmartMagnify { device_id }),
TouchpadRotate {
device_id,
delta,
Expand Down
14 changes: 14 additions & 0 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,20 @@ declare_class!(
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}

#[sel(smartMagnifyWithEvent:)]
fn smart_magnify_with_event(&self, _event: &NSEvent) {
trace_scope!("smartMagnifyWithEvent:");

let window_event = Event::WindowEvent {
window_id: self.window_id(),
event: WindowEvent::SmartMagnify {
device_id: DEVICE_ID,
},
};

AppState::queue_event(EventWrapper::StaticEvent(window_event));
}

#[sel(rotateWithEvent:)]
fn rotate_with_event(&self, event: &NSEvent) {
trace_scope!("rotateWithEvent:");
Expand Down

0 comments on commit d448d3e

Please sign in to comment.