Fix windows hanging on main window close
This commit is contained in:
parent
7cba06f04e
commit
fdebf81bef
1 changed files with 12 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue