diff options
| -rw-r--r-- | src/android/mod.rs | 4 | ||||
| -rw-r--r-- | src/cocoa/mod.rs | 4 | ||||
| -rw-r--r-- | src/win32/mod.rs | 19 | ||||
| -rw-r--r-- | src/window.rs | 5 | ||||
| -rw-r--r-- | src/x11/window/mod.rs | 4 | 
5 files changed, 36 insertions, 0 deletions
diff --git a/src/android/mod.rs b/src/android/mod.rs index 3c01b4c..7979f09 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -356,6 +356,10 @@ impl Window {      pub fn hidpi_factor(&self) -> f32 {          1.0      } + +    pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { +        unimplemented!(); +    }  }  unsafe impl Send for Window {} diff --git a/src/cocoa/mod.rs b/src/cocoa/mod.rs index 334ec42..ee3b03f 100644 --- a/src/cocoa/mod.rs +++ b/src/cocoa/mod.rs @@ -664,4 +664,8 @@ impl Window {              NSWindow::backingScaleFactor(self.window) as f32          }      } + +    pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { +        unimplemented!(); +    }  } diff --git a/src/win32/mod.rs b/src/win32/mod.rs index 8cb6d39..8ba5ed5 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -255,6 +255,25 @@ impl Window {      pub fn hidpi_factor(&self) -> f32 {          1.0      } + +    pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { +        let mut point = winapi::POINT { +            x: x, +            y: y, +        }; + +        unsafe { +            if user32::ClientToScreen(self.window.0, &mut point) == 0 { +                return Err(()); +            } + +            if user32::SetCursorPos(point.x, point.y) == 0 { +                return Err(()); +            } +        } + +        Ok(()) +    }  }  pub struct PollEventsIterator<'a> { diff --git a/src/window.rs b/src/window.rs index 1bab245..bd5fc14 100644 --- a/src/window.rs +++ b/src/window.rs @@ -409,6 +409,11 @@ impl Window {      pub fn hidpi_factor(&self) -> f32 {          self.window.hidpi_factor()      } + +    /// Changes the position of the cursor in window coordinates. +    pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { +        self.window.set_cursor_position(x, y) +    }  }  impl gl_common::GlFunctionsSource for Window { diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 404324a..7845d07 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -785,4 +785,8 @@ impl Window {      pub fn hidpi_factor(&self) -> f32 {          1.0      } + +    pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { +        unimplemented!(); +    }  }  | 
