diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-12-29 21:21:17 +0100 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-12-29 21:21:17 +0100 |
commit | c1a98a200ba2303617bbe9eb70161b3c575a1999 (patch) | |
tree | d8ba684362aa7d64b02d9a0292a148e395b86dcd /src | |
parent | 0a598d79803d456933619ef0fe385a38c9284ff6 (diff) | |
parent | d892ba168b178d5adac2db777b3dfc912543d40b (diff) | |
download | glutin-c1a98a200ba2303617bbe9eb70161b3c575a1999.tar.gz glutin-c1a98a200ba2303617bbe9eb70161b3c575a1999.zip |
Merge pull request #684 from AnthIste/0.4.4-cocoa-api
Implement set_cursor_position on OSX with Cocoa
Diffstat (limited to 'src')
-rw-r--r-- | src/api/cocoa/mod.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index eae344c..a720a51 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -34,7 +34,7 @@ use core_foundation::base::TCFType; use core_foundation::string::CFString; use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName}; -use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh}; +use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh, CGWarpMouseCursorPosition}; use std::ffi::CStr; use std::collections::VecDeque; @@ -371,7 +371,7 @@ impl Window { let count: NSUInteger = msg_send![screens, count]; let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber")); let mut matching_screen: Option<id> = None; - for i in (0..count) { + for i in 0..count { let screen = msg_send![screens, objectAtIndex:i as NSUInteger]; let device_description = NSScreen::deviceDescription(screen); let value: id = msg_send![device_description, objectForKey:*key]; @@ -765,8 +765,17 @@ impl Window { } #[inline] - pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { - unimplemented!(); + 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 { + // TODO: Check for errors. + let _ = CGWarpMouseCursorPosition(CGPoint { x: cursor_x as CGFloat, y: cursor_y as CGFloat }); + let _ = CGAssociateMouseAndMouseCursorPosition(true); + } + + Ok(()) } } |