mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 06:10:07 -04:00
Reduce cursor warp delay with CGAssociateMouseAndMouseCursorPosition
This commit is contained in:
@@ -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<(), ()> {
|
||||||
unsafe {
|
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
|
||||||
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
|
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
|
||||||
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
|
|
||||||
|
|
||||||
|
unsafe {
|
||||||
// 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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user