From f792e331a98d6da44bbaeb3102c4098496ffdc82 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 14 Jul 2023 01:40:11 +0200 Subject: [PATCH] update cursor lock code --- kubi/src/cursor_lock.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kubi/src/cursor_lock.rs b/kubi/src/cursor_lock.rs index 7118166..19487d1 100644 --- a/kubi/src/cursor_lock.rs +++ b/kubi/src/cursor_lock.rs @@ -7,17 +7,20 @@ pub struct CursorLock(pub bool); pub fn update_cursor_lock_state( lock: UniqueView, - display: NonSendSync> + renderer: NonSendSync> ) { - 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); } }