mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 12:50:04 -04:00
Add smart magnify gesture support for macOS (#2554)
* Add smart magnification gesture
* Deliver position of smart magnification event
* Document smart magnification event
* Revert "Deliver position of smart magnification event"
This reverts commit ac0e61a9a4.
* Remove mention of touchpad from smart magnification event
* Update change log
* Mention minimum macOS version supporting smart magnification
* Improve doc
This commit is contained in:
23
src/event.rs
23
src/event.rs
@@ -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
|
||||
@@ -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,
|
||||
@@ -700,6 +722,7 @@ impl<'a> WindowEvent<'a> {
|
||||
delta,
|
||||
phase,
|
||||
}),
|
||||
SmartMagnify { device_id } => Some(SmartMagnify { device_id }),
|
||||
TouchpadRotate {
|
||||
device_id,
|
||||
delta,
|
||||
|
||||
@@ -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:");
|
||||
|
||||
Reference in New Issue
Block a user