Change set_cursor_position to return Result<(), String> (#562)
* Change set_cursor_position to return Result<(), String> This is now consistent with `grab_cursor`, and enables `window.set_cursor_position(x, y)?` in functions that return `Result<_, Box<Error>>`. * Adjust error handling of unimplemented cusor opertions in wayland * The final nitpick * Actually one more
This commit is contained in:
parent
fb7528c239
commit
8f394f117b
10 changed files with 40 additions and 31 deletions
|
|
@ -1025,17 +1025,18 @@ impl Window2 {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_cursor_position(&self, cursor_position: LogicalPosition) -> Result<(), ()> {
|
||||
pub fn set_cursor_position(&self, cursor_position: LogicalPosition) -> Result<(), String> {
|
||||
let window_position = self.get_inner_position()
|
||||
.expect("`get_inner_position` failed");
|
||||
.ok_or("`get_inner_position` failed".to_owned())?;
|
||||
let point = appkit::CGPoint {
|
||||
x: (cursor_position.x + window_position.x) as CGFloat,
|
||||
y: (cursor_position.y + window_position.y) as CGFloat,
|
||||
};
|
||||
CGDisplay::warp_mouse_cursor_position(point)
|
||||
.expect("`CGWarpMouseCursorPosition` failed");
|
||||
.map_err(|e| format!("`CGWarpMouseCursorPosition` failed: {:?}", e))?;
|
||||
CGDisplay::associate_mouse_and_mouse_cursor_position(true)
|
||||
.expect("`CGAssociateMouseAndMouseCursorPosition` failed");
|
||||
.map_err(|e| format!("`CGAssociateMouseAndMouseCursorPosition` failed: {:?}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue