diff --git a/imgui-winit-support/src/lib.rs b/imgui-winit-support/src/lib.rs index ef3847c..7460588 100644 --- a/imgui-winit-support/src/lib.rs +++ b/imgui-winit-support/src/lib.rs @@ -967,6 +967,13 @@ impl WinitPlatform { _ => (), } } + WindowEvent::Focused(newly_focused) => { + if !newly_focused { + // Set focus-lost to avoid stuck keys (like 'alt' + // when alt-tabbing) + io.app_focus_lost = true; + } + } _ => (), } } @@ -1077,6 +1084,13 @@ impl WinitPlatform { _ => (), } } + WindowEvent::Focused(newly_focused) => { + if !newly_focused { + // Set focus-lost to avoid stuck keys (like 'alt' + // when alt-tabbing) + io.app_focus_lost = true; + } + } _ => (), } } @@ -1186,6 +1200,13 @@ impl WinitPlatform { _ => (), } } + WindowEvent::Focused(newly_focused) => { + if !newly_focused { + // Set focus-lost to avoid stuck keys (like 'alt' + // when alt-tabbing) + io.app_focus_lost = true; + } + } _ => (), } } diff --git a/imgui/src/io.rs b/imgui/src/io.rs index 2362c31..50f8975 100644 --- a/imgui/src/io.rs +++ b/imgui/src/io.rs @@ -339,7 +339,11 @@ pub struct Io { nav_inputs_down_duration: [f32; NavInput::COUNT + NavInput::INTERNAL_COUNT], nav_inputs_down_duration_prev: [f32; NavInput::COUNT + NavInput::INTERNAL_COUNT], pen_pressure: f32, - app_focus_lost: bool, + + /// Clear buttons state when focus is lost (this is useful so + /// e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger + /// the Alt menu toggle) + pub app_focus_lost: bool, input_queue_surrogate: sys::ImWchar16, input_queue_characters: ImVector, }