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