mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 08:18:43 -06:00
update cursor lock code
This commit is contained in:
parent
81f169a89a
commit
f792e331a9
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue