From 26775fa0b621c225753cefb2a3babead3be33f46 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 26 Apr 2020 20:42:45 +0000 Subject: [PATCH] Report mouse motion before click (#1490) * Report mouse motion before click This fixes an issue on macOS where a mouse click would be generated, without ever getting a mouse motion to the position before the click. This leads to the application thinking the mouse click occurred at a position other than the actual mouse location. This happens due to mouse motion above the window not automatically giving focus to the window, unless it is actually clicked, making it possible to move the window without motion events. Fixes #942. * Add additional mouse motion events Co-authored-by: Ryan Goldstein --- CHANGELOG.md | 1 + src/platform_impl/macos/view.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5e9fd9..dc799916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Revert On macOS, fix not sending ReceivedCharacter event for specific keys combinations. - on macOS, fix incorrect ReceivedCharacter events for some key combinations. - **Breaking:** Use `i32` instead of `u32` for position type in `WindowEvent::Moved`. +- On macOS, a mouse motion event is now generated before every mouse click. # 0.21.0 (2020-02-04) diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 839a2bc0..82ee5076 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -869,26 +869,32 @@ fn mouse_click(this: &Object, event: id, button: MouseButton, button_state: Elem } extern "C" fn mouse_down(this: &Object, _sel: Sel, event: id) { + mouse_motion(this, event); mouse_click(this, event, MouseButton::Left, ElementState::Pressed); } extern "C" fn mouse_up(this: &Object, _sel: Sel, event: id) { + mouse_motion(this, event); mouse_click(this, event, MouseButton::Left, ElementState::Released); } extern "C" fn right_mouse_down(this: &Object, _sel: Sel, event: id) { + mouse_motion(this, event); mouse_click(this, event, MouseButton::Right, ElementState::Pressed); } extern "C" fn right_mouse_up(this: &Object, _sel: Sel, event: id) { + mouse_motion(this, event); mouse_click(this, event, MouseButton::Right, ElementState::Released); } extern "C" fn other_mouse_down(this: &Object, _sel: Sel, event: id) { + mouse_motion(this, event); mouse_click(this, event, MouseButton::Middle, ElementState::Pressed); } extern "C" fn other_mouse_up(this: &Object, _sel: Sel, event: id) { + mouse_motion(this, event); mouse_click(this, event, MouseButton::Middle, ElementState::Released); } @@ -986,6 +992,9 @@ extern "C" fn mouse_exited(this: &Object, _sel: Sel, _event: id) { extern "C" fn scroll_wheel(this: &Object, _sel: Sel, event: id) { trace!("Triggered `scrollWheel`"); + + mouse_motion(this, event); + unsafe { let delta = { let (x, y) = (event.scrollingDeltaX(), event.scrollingDeltaY()); @@ -1031,6 +1040,9 @@ extern "C" fn scroll_wheel(this: &Object, _sel: Sel, event: id) { extern "C" fn pressure_change_with_event(this: &Object, _sel: Sel, event: id) { trace!("Triggered `pressureChangeWithEvent`"); + + mouse_motion(this, event); + unsafe { let state_ptr: *mut c_void = *this.get_ivar("winitState"); let state = &mut *(state_ptr as *mut ViewState);