From 0986fae06665d8fb0e1866f57c2efabdc7abf4d3 Mon Sep 17 00:00:00 2001 From: z4122 <412213484@qq.com> Date: Fri, 30 Apr 2021 17:30:09 +0800 Subject: [PATCH] Add accept_first_mouse for macOS (#1882) * feat: add accept_first_mouse for macOS * Update the changelog Co-authored-by: Artur Kovacs --- CHANGELOG.md | 1 + src/platform_impl/macos/view.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bda66817..ae9c7df5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - On macOS, emit `RedrawRequested` events immediately while the window is being resized. - Implement `Default`, `Hash`, and `Eq` for `LogicalPosition`, `PhysicalPosition`, `LogicalSize`, and `PhysicalSize`. - On macOS, initialize the Menu Bar with minimal defaults. +- On macOS, change the default behavior for first click when the window was unfocused. Now the window becomes focused and then emits a `MouseInput` event on a "first mouse click". # 0.24.0 (2020-12-09) diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index aa7109f8..5da5b536 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -255,6 +255,10 @@ lazy_static! { sel!(frameDidChange:), frame_did_change as extern "C" fn(&Object, Sel, id), ); + decl.add_method( + sel!(acceptsFirstMouse:), + accepts_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL, + ); decl.add_ivar::<*mut c_void>("winitState"); decl.add_ivar::("markedText"); let protocol = Protocol::get("NSTextInputClient").unwrap(); @@ -1078,3 +1082,7 @@ extern "C" fn pressure_change_with_event(this: &Object, _sel: Sel, event: id) { extern "C" fn wants_key_down_for_event(_this: &Object, _sel: Sel, _event: id) -> BOOL { YES } + +extern "C" fn accepts_first_mouse(_this: &Object, _sel: Sel, _event: id) -> BOOL { + YES +}