mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48: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(
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue