From ed761bef7d78ec0f9424460d98d1193796a7ae74 Mon Sep 17 00:00:00 2001 From: Tristam MacDonald Date: Sat, 15 Jul 2017 18:02:32 -0700 Subject: [PATCH 1/3] Also hide the cursor when grabbed --- src/platform/macos/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index cbd66056b6..62f0720a05 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -523,6 +523,7 @@ impl Window { Ok(()) }, CursorState::Grab => { + let _: () = unsafe { msg_send![cls, hide] }; let _: i32 = unsafe { CGAssociateMouseAndMouseCursorPosition(false) }; Ok(()) } From 6820e2a8266e125ad6e2b7e694c4b218b0dfbebf Mon Sep 17 00:00:00 2001 From: Tristam MacDonald Date: Sat, 15 Jul 2017 18:32:18 -0700 Subject: [PATCH 2/3] Implement raw mouse motion for Mac --- src/platform/macos/events_loop.rs | 35 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 52130bbe61..37ee535e54 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -1,12 +1,13 @@ use {ControlFlow, EventsLoopClosed}; use cocoa::{self, appkit, foundation}; use cocoa::appkit::{NSApplication, NSEvent, NSView, NSWindow}; -use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, ModifiersState, KeyboardInput}; +use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput}; use std::collections::VecDeque; use std::sync::{Arc, Mutex, Weak}; use super::window::Window; use std; use super::DeviceId; +use AxisId; pub struct EventsLoop { @@ -468,11 +469,33 @@ impl EventsLoop { let view_rect = NSView::frame(*window.view); let scale_factor = window.hidpi_factor(); - let x = (scale_factor * view_point.x as f32) as f64; - let y = (scale_factor * (view_rect.size.height - view_point.y) as f32) as f64; - let window_event = WindowEvent::MouseMoved { device_id: DEVICE_ID, position: (x, y) }; - let event = Event::WindowEvent { window_id: ::WindowId(window.id()), event: window_event }; - Some(event) + let mut events = std::collections::VecDeque::new(); + + { + let x = (scale_factor * view_point.x as f32) as f64; + let y = (scale_factor * (view_rect.size.height - view_point.y) as f32) as f64; + let window_event = WindowEvent::MouseMoved { device_id: DEVICE_ID, position: (x, y) }; + let event = Event::WindowEvent { window_id: ::WindowId(window.id()), event: window_event }; + events.push_back(event); + } + + let delta_x = (scale_factor * ns_event.deltaX() as f32) as f64; + if delta_x != 0.0 { + let motion_event = DeviceEvent::Motion { axis: AxisId(0), value: delta_x }; + let event = Event::DeviceEvent{ device_id: DEVICE_ID, event: motion_event }; + events.push_back(event); + } + + let delta_y = (scale_factor * ns_event.deltaY() as f32) as f64; + if delta_y != 0.0 { + let motion_event = DeviceEvent::Motion { axis: AxisId(1), value: delta_y }; + let event = Event::DeviceEvent{ device_id: DEVICE_ID, event: motion_event }; + events.push_back(event); + } + + let event = events.pop_front(); + self.shared.pending_events.lock().unwrap().extend(events.into_iter()); + event }, appkit::NSScrollWheel => { From 15c4641758898a0a3ba1ac9132ec41c4f2f4b142 Mon Sep 17 00:00:00 2001 From: Tristam MacDonald Date: Sat, 29 Jul 2017 07:56:08 -0700 Subject: [PATCH 3/3] Unwrap axis id in raw mouse motion on Mac --- src/platform/macos/events_loop.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 37ee535e54..8973ab5e25 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -7,7 +7,6 @@ use std::sync::{Arc, Mutex, Weak}; use super::window::Window; use std; use super::DeviceId; -use AxisId; pub struct EventsLoop { @@ -481,14 +480,14 @@ impl EventsLoop { let delta_x = (scale_factor * ns_event.deltaX() as f32) as f64; if delta_x != 0.0 { - let motion_event = DeviceEvent::Motion { axis: AxisId(0), value: delta_x }; + let motion_event = DeviceEvent::Motion { axis: 0, value: delta_x }; let event = Event::DeviceEvent{ device_id: DEVICE_ID, event: motion_event }; events.push_back(event); } let delta_y = (scale_factor * ns_event.deltaY() as f32) as f64; if delta_y != 0.0 { - let motion_event = DeviceEvent::Motion { axis: AxisId(1), value: delta_y }; + let motion_event = DeviceEvent::Motion { axis: 1, value: delta_y }; let event = Event::DeviceEvent{ device_id: DEVICE_ID, event: motion_event }; events.push_back(event); }