From 36b34934e2d366017d9474c946e8b30658650358 Mon Sep 17 00:00:00 2001 From: ming08108 Date: Wed, 20 Mar 2024 07:06:45 -0500 Subject: [PATCH] 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 --- crates/egui-winit/src/lib.rs | 3 --- crates/egui/src/input_state.rs | 16 +--------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index c02fd8d275a..b6d02cdf12c 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -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)); diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 8809cdb8d1f..2a196c86528 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -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,