diff --git a/src/frontend/software/mod.rs b/src/frontend/software/mod.rs index 30b057e1f..78cfe0ef2 100644 --- a/src/frontend/software/mod.rs +++ b/src/frontend/software/mod.rs @@ -43,6 +43,15 @@ impl FrontEnd for SoftwareFrontEnd { } fn run_forever(&self) -> Fallible<()> { + self.connection + .schedule_timer(std::time::Duration::from_millis(200), move || { + let mux = Mux::get().unwrap(); + mux.prune_dead_windows(); + if mux.is_empty() { + Connection::get().unwrap().terminate_message_loop(); + } + }); + self.connection.run_message_loop() } diff --git a/src/frontend/software/termwindow.rs b/src/frontend/software/termwindow.rs index 1e80e3201..020950814 100644 --- a/src/frontend/software/termwindow.rs +++ b/src/frontend/software/termwindow.rs @@ -59,14 +59,22 @@ impl WindowCallbacks for TermWindow { } fn can_close(&mut self) -> bool { - // self.host.close_current_tab(); + // can_close triggers the current tab to be closed. + // If we have no tabs left then we can close the whole window. + // If we're in a weird state, then we allow the window to close too. + let mux = Mux::get().unwrap(); + let tab = match mux.get_active_tab_for_window(self.mux_window_id) { + Some(tab) => tab, + None => return true, + }; + mux.remove_tab(tab.tab_id()); + if let Some(mut win) = mux.get_window_mut(self.mux_window_id) { + win.remove_by_id(tab.tab_id()); + return win.is_empty(); + }; true } - fn destroy(&mut self) { - Connection::get().unwrap().terminate_message_loop(); - } - fn as_any(&mut self) -> &mut dyn Any { self }