Merge pull request #628 from dbr/losingfocus

Handle window focus lost event
This commit is contained in:
dbr/Ben 2022-03-23 12:12:56 +10:30 committed by GitHub
commit fef6509a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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;
}
}
_ => (),
}
}

View File

@ -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<sys::ImWchar>,
}