Force ungrab on Key::ToggleCursor

Former-commit-id: 222f5693363662d25cb065fdc104cd079e2c395d
This commit is contained in:
timokoesters 2019-05-09 10:55:32 +02:00
parent 0e46b00a0c
commit e8cf815143
2 changed files with 13 additions and 8 deletions

View File

@ -201,6 +201,7 @@ pub struct Hud {
show: Show, show: Show,
to_focus: Option<Option<widget::Id>>, to_focus: Option<Option<widget::Id>>,
settings: Settings, settings: Settings,
force_ungrab: bool,
} }
impl Hud { impl Hud {
@ -236,6 +237,7 @@ impl Hud {
}, },
to_focus: None, to_focus: None,
settings, settings,
force_ungrab: false,
} }
} }
@ -520,6 +522,13 @@ impl Hud {
self.show.toggle_help(); self.show.toggle_help();
true true
} }
Key::ToggleCursor => {
self.force_ungrab = !self.force_ungrab;
if self.force_ungrab {
global_state.window.grab_cursor(false);
}
true
}
_ => false, _ => false,
}, },
WinEvent::KeyDown(key) | WinEvent::KeyUp(key) => match key { WinEvent::KeyDown(key) | WinEvent::KeyUp(key) => match key {
@ -534,8 +543,10 @@ impl Hud {
_ => false, _ => false,
}; };
// Handle cursor grab // Handle cursor grab
if let Some(state) = self.show.want_grab.take() { if !self.force_ungrab {
global_state.window.grab_cursor(state); if let Some(state) = self.show.want_grab.take() {
global_state.window.grab_cursor(state);
}
} }
handled handled

View File

@ -127,12 +127,6 @@ impl PlayState for SessionState {
Event::Close => { Event::Close => {
return PlayStateResult::Shutdown; return PlayStateResult::Shutdown;
} }
// Toggle cursor grabbing
Event::KeyDown(Key::ToggleCursor) => {
global_state
.window
.grab_cursor(!global_state.window.is_cursor_grabbed());
}
// Movement Key Pressed // Movement Key Pressed
Event::KeyDown(Key::MoveForward) => self.key_state.up = true, Event::KeyDown(Key::MoveForward) => self.key_state.up = true,
Event::KeyDown(Key::MoveBack) => self.key_state.down = true, Event::KeyDown(Key::MoveBack) => self.key_state.down = true,