Skip to content

Commit 36b3493

Browse files
ming08108hacknus
authored andcommitted
Don't clear modifier state on focus change (emilk#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 <emilk#2332>
1 parent 619d7dd commit 36b3493

File tree

2 files changed

+1
-18
lines changed

2 files changed

+1
-18
lines changed

crates/egui-winit/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,6 @@ impl State {
376376
}
377377
WindowEvent::Focused(focused) => {
378378
self.egui_input.focused = *focused;
379-
// We will not be given a KeyboardInput event when the modifiers are released while
380-
// the window does not have focus. Unset all modifier state to be safe.
381-
self.egui_input.modifiers = egui::Modifiers::default();
382379
self.egui_input
383380
.events
384381
.push(egui::Event::WindowFocused(*focused));

crates/egui/src/input_state.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,6 @@ impl InputState {
249249
}
250250
}
251251

252-
let mut modifiers = new.modifiers;
253-
254-
let focused_changed = self.focused != new.focused
255-
|| new
256-
.events
257-
.iter()
258-
.any(|e| matches!(e, Event::WindowFocused(_)));
259-
if focused_changed {
260-
// It is very common for keys to become stuck when we alt-tab, or a save-dialog opens by Ctrl+S.
261-
// Therefore we clear all the modifiers and down keys here to avoid that.
262-
modifiers = Default::default();
263-
keys_down = Default::default();
264-
}
265-
266252
Self {
267253
pointer,
268254
touch_states: self.touch_states,
@@ -278,7 +264,7 @@ impl InputState {
278264
predicted_dt: new.predicted_dt,
279265
stable_dt,
280266
focused: new.focused,
281-
modifiers,
267+
modifiers: new.modifiers,
282268
keys_down,
283269
events: new.events.clone(), // TODO(emilk): remove clone() and use raw.events
284270
raw: new,

0 commit comments

Comments
 (0)