Reduce cursor warp delay with CGAssociateMouseAndMouseCursorPosition

This commit is contained in:
Ruben Bakker 2015-12-29 21:52:18 +02:00
parent 2fb150b345
commit d892ba168b

View file

@ -766,14 +766,16 @@ impl Window {
#[inline] #[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
unsafe { unsafe {
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
// TODO: Check for errors. // TODO: Check for errors.
let _ = CGWarpMouseCursorPosition(CGPoint { x: cursor_x as CGFloat, y: cursor_y as CGFloat }); let _ = CGWarpMouseCursorPosition(CGPoint { x: cursor_x as CGFloat, y: cursor_y as CGFloat });
Ok(()) let _ = CGAssociateMouseAndMouseCursorPosition(true);
} }
Ok(())
} }
} }