update cursor lock code

This commit is contained in:
griffi-gh 2023-07-14 01:40:11 +02:00
parent 81f169a89a
commit f792e331a9

View file

@ -7,17 +7,20 @@ pub struct CursorLock(pub bool);
pub fn update_cursor_lock_state(
lock: UniqueView<CursorLock>,
display: NonSendSync<UniqueView<Renderer>>
renderer: NonSendSync<UniqueView<Renderer>>
) {
if cfg!(target_os = "android") {
return
}
#[cfg(not(target_os = "android"))]
if lock.is_inserted_or_modified() {
display.window.set_cursor_grab(match lock.0 {
true => CursorGrabMode::Confined,
false => CursorGrabMode::None,
}).expect("Failed to change cursor grab state");
display.window.set_cursor_visible(!lock.0);
let window = &renderer.window;
if lock.0 {
window.set_cursor_grab(CursorGrabMode::Confined)
.or_else(|_| window.set_cursor_grab(CursorGrabMode::Locked))
.expect("Failed to lock the cursor");
} else {
window.set_cursor_grab(CursorGrabMode::None)
.expect("Failed to unlock the cursor");
}
renderer.window.set_cursor_visible(!lock.0);
}
}