Handle window focus lost event

Avoids keys getting stuck when window loses focus (e.g alt+tab)

Closes #602
This commit is contained in:
dbr 2022-03-19 21:03:52 +11:00
parent 5e2ab214d1
commit 9648b40d85
2 changed files with 23 additions and 2 deletions

View File

@ -941,7 +941,14 @@ 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;
}
},
_ => (),
}
}
@ -1052,6 +1059,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;
}
}
_ => (),
}
}
@ -1161,6 +1175,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,7 @@ 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,
pub app_focus_lost: bool,
input_queue_surrogate: sys::ImWchar16,
input_queue_characters: ImVector<sys::ImWchar>,
}