reverie_engine_opengl/platform/
windows.rs

1pub use windows::core::Error;
2use windows::Win32::{
3    Foundation::POINT,
4    UI::WindowsAndMessaging::{GetCursorPos, SetCursorPos},
5};
6
7use crate::window::input::cursor::{CursorPosition, DesktopOrigin};
8
9pub fn set_cursor_pos(x: i32, y: i32) -> Result<(), Error> {
10    let result = unsafe { SetCursorPos(x, y) };
11    if let Err(ref err) = result {
12        if err.code().is_ok() {
13            return Ok(());
14        }
15    }
16    result
17}
18
19pub fn get_cursor_pos() -> Result<CursorPosition<DesktopOrigin>, Error> {
20    let mut point = POINT::default();
21    let result = unsafe { GetCursorPos(&mut point) };
22
23    if let Err(err) = result {
24        if err.code().is_err() {
25            return Err(err);
26        }
27    }
28
29    Ok(CursorPosition::new(point.x, point.y))
30}