Added method to InputState to clear pressed keys, mods, and mouse. Call method on window focus loss.
This commit is contained in:
1 parent
9d33a7704c
commit
966363a859
2 files changed
+12
No files matched your search
@@ -258,6 +258,10 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
self.state.window.is_focused = focused;
|
||||
if focused {
|
||||
self.state.window.request_redraw();
|
||||
} else {
|
||||
// Clear inputs on lost focus to avoid "stuck" keys on Wayland
|
||||
// systems.
|
||||
self.state.input.clear_pressed();
|
||||
}
|
||||
}
|
||||
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
||||
|
||||
@@ -77,6 +77,14 @@ impl InputState {
|
||||
pub fn set_mouse_pos(&mut self, pos: LogicalPoint<f32>) {
|
||||
self.cursor_pos = pos;
|
||||
}
|
||||
|
||||
/// Clears all pressed keys, buttons, and modifier states. Used when the
|
||||
/// application loses focus to avoid keys being "stuck" on/pressed.
|
||||
pub fn clear_pressed(&mut self) {
|
||||
self.keys_pressed.clear();
|
||||
self.mouse_pressed.clear();
|
||||
self.key_modifiers = ModifiersState::empty();
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to convert the provided string `s` to a [KeyCode].
|
||||
|
||||
Reference in new issue
Block a user