Fix windows hanging on main window close

This commit is contained in:
Speedy_Lex 2025-04-11 18:55:43 +02:00 committed by BitSyndicate
parent 7cba06f04e
commit fdebf81bef
Signed by: bitsyndicate
GPG key ID: 443E4198D6BBA6DE

View file

@ -62,12 +62,15 @@ pub struct TerminalState {
pub struct App<'window> {
windows: ahash::AHashMap<WindowId, WindowContext<'window>>,
// Number of windows that have been dropped but *NOT* destroyed yet
windows_in_limbo: usize,
}
impl Default for App<'_> {
fn default() -> Self {
Self {
windows: ahash::AHashMap::new(),
windows_in_limbo: 0,
}
}
}
@ -253,8 +256,13 @@ impl App<'_> {
}
fn handle_close_requested(&mut self, window_id: WindowId) {
if self.windows.remove(&window_id).is_some() {
if let Some(window) = self.windows.remove(&window_id) {
debug!("Window {:?} closed", window_id);
self.windows_in_limbo += 1;
if window.is_main_window() {
self.windows_in_limbo += self.windows.len();
self.windows.clear();
}
} else {
warn!("Tried to close non-existent window {:?}", window_id);
}
@ -488,9 +496,9 @@ impl App<'_> {
}
fn handle_destroyed(&mut self, event_loop: &ActiveEventLoop) {
if self.windows.is_empty() || !self.windows.iter().any(|(_, ctx)| ctx.is_main_window()) {
self.windows.clear();
debug!("All main windows are closed. Exiting event loop.");
self.windows_in_limbo -= 1;
if self.windows_in_limbo == 0 && self.windows.is_empty() {
debug!("All windows are closed. Exiting event loop.");
event_loop.exit();
}
}