Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Handle Swipe events to support navigation buttons on some mice (#23332)
Szymon Piechaczekd2828e872281
diff --git a/crates/gpui/src/platform/mac/events.rs b/crates/gpui/src/platform/mac/events.rsindex 56256aeffde..4d2fc12dc15 100644--- a/crates/gpui/src/platform/mac/events.rs+++ b/crates/gpui/src/platform/mac/events.rs@@ -158,6 +158,33 @@ impl PlatformInput {})})}+ // Some mice (like Logitech MX Master) send navigation buttons as swipe events+ NSEventType::NSEventTypeSwipe => {+ let navigation_direction = match native_event.phase() {+ NSEventPhase::NSEventPhaseEnded => match native_event.deltaX() {+ x if x > 0.0 => Some(NavigationDirection::Back),+ x if x < 0.0 => Some(NavigationDirection::Forward),+ _ => return None,+ },+ _ => return None,+ };++ match navigation_direction {+ Some(direction) => window_height.map(|window_height| {+ Self::MouseDown(MouseDownEvent {+ button: MouseButton::Navigate(direction),+ position: point(+ px(native_event.locationInWindow().x as f32),+ window_height - px(native_event.locationInWindow().y as f32),+ ),+ modifiers: read_modifiers(native_event),+ click_count: 1,+ first_mouse: false,+ })+ }),+ _ => None,+ }+ }NSEventType::NSScrollWheel => window_height.map(|window_height| {let phase = match native_event.phase() {NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rsindex dc715a071b5..35b1f598b34 100644--- a/crates/gpui/src/platform/mac/window.rs+++ b/crates/gpui/src/platform/mac/window.rs@@ -148,6 +148,10 @@ unsafe fn build_classes() {sel!(scrollWheel:),handle_view_event as extern "C" fn(&Object, Sel, id),);+ decl.add_method(+ sel!(swipeWithEvent:),+ handle_view_event as extern "C" fn(&Object, Sel, id),+ );decl.add_method(sel!(flagsChanged:),handle_view_event as extern "C" fn(&Object, Sel, id),