Don't clear modifier state on focus change (#4157)

I believe that the underlying issue that caused the stuck modifier keys
was resolved in the 0.29 winit keyboard refactor.

This probably needs to tested on other desktop platforms however since I
am only able to test this on windows 11.

* Closes <https://github.com/emilk/egui/issues/2332>
This commit is contained in:
ming08108 2024-03-20 07:06:45 -05:00 committed by GitHub
parent 1b34289608
commit 8d47ab8bb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 18 deletions

View File

@ -376,9 +376,6 @@ impl State {
}
WindowEvent::Focused(focused) => {
self.egui_input.focused = *focused;
// We will not be given a KeyboardInput event when the modifiers are released while
// the window does not have focus. Unset all modifier state to be safe.
self.egui_input.modifiers = egui::Modifiers::default();
self.egui_input
.events
.push(egui::Event::WindowFocused(*focused));

View File

@ -249,20 +249,6 @@ impl InputState {
}
}
let mut modifiers = new.modifiers;
let focused_changed = self.focused != new.focused
|| new
.events
.iter()
.any(|e| matches!(e, Event::WindowFocused(_)));
if focused_changed {
// It is very common for keys to become stuck when we alt-tab, or a save-dialog opens by Ctrl+S.
// Therefore we clear all the modifiers and down keys here to avoid that.
modifiers = Default::default();
keys_down = Default::default();
}
Self {
pointer,
touch_states: self.touch_states,
@ -278,7 +264,7 @@ impl InputState {
predicted_dt: new.predicted_dt,
stable_dt,
focused: new.focused,
modifiers,
modifiers: new.modifiers,
keys_down,
events: new.events.clone(), // TODO(emilk): remove clone() and use raw.events
raw: new,