Release the cursor on unfocus
This commit is contained in:
parent
d8dfe7b4d1
commit
c91d6a851e
1 changed files with 9 additions and 3 deletions
12
src/main.rs
12
src/main.rs
|
@ -2,6 +2,7 @@ mod aabb;
|
|||
mod camera;
|
||||
mod chunk;
|
||||
mod geometry;
|
||||
mod npc;
|
||||
mod quad;
|
||||
mod render_context;
|
||||
mod state;
|
||||
|
@ -79,13 +80,18 @@ fn main() {
|
|||
button,
|
||||
..
|
||||
} => {
|
||||
if *button == MouseButton::Left && *mouse_state == ElementState::Pressed {
|
||||
if !state.mouse_grabbed && *button == MouseButton::Left && *mouse_state == ElementState::Pressed {
|
||||
let _ = window.set_cursor_grab(true);
|
||||
window.set_cursor_visible(false);
|
||||
state.mouse_grabbed = true;
|
||||
} else {
|
||||
state.window_event(event);
|
||||
}
|
||||
|
||||
state.window_event(event);
|
||||
}
|
||||
WindowEvent::Focused(false) => {
|
||||
let _ = window.set_cursor_grab(false);
|
||||
window.set_cursor_visible(true);
|
||||
state.mouse_grabbed = false;
|
||||
}
|
||||
event => { state.window_event(event); }
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue