diff --git a/wezterm-gui/src/gui/overlay/confirm_close_pane.rs b/wezterm-gui/src/gui/overlay/confirm_close_pane.rs index 583132a1a..b2b34526a 100644 --- a/wezterm-gui/src/gui/overlay/confirm_close_pane.rs +++ b/wezterm-gui/src/gui/overlay/confirm_close_pane.rs @@ -191,3 +191,16 @@ pub fn confirm_close_window( Ok(()) } + +pub fn confirm_quit_program(mut term: TermWizTerminal) -> anyhow::Result<()> { + if run_confirmation_app("🛑 Really Quit WezTerm?", &mut term)? { + promise::spawn::spawn_into_main_thread(async move { + use ::window::{Connection, ConnectionOps}; + let con = Connection::get().expect("call on gui thread"); + con.terminate_message_loop(); + }) + .detach(); + } + + Ok(()) +} diff --git a/wezterm-gui/src/gui/overlay/mod.rs b/wezterm-gui/src/gui/overlay/mod.rs index 2be5c77a5..4ebeb12a2 100644 --- a/wezterm-gui/src/gui/overlay/mod.rs +++ b/wezterm-gui/src/gui/overlay/mod.rs @@ -14,6 +14,7 @@ mod tabnavigator; pub use confirm_close_pane::confirm_close_pane; pub use confirm_close_pane::confirm_close_tab; pub use confirm_close_pane::confirm_close_window; +pub use confirm_close_pane::confirm_quit_program; pub use copy::CopyOverlay; pub use launcher::launcher; pub use search::SearchOverlay; diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs index beca7028a..1cddd7bbb 100644 --- a/wezterm-gui/src/gui/termwindow.rs +++ b/wezterm-gui/src/gui/termwindow.rs @@ -3,8 +3,8 @@ use super::quad::*; use super::renderstate::*; use super::utilsprites::RenderMetrics; use crate::gui::overlay::{ - confirm_close_pane, confirm_close_tab, confirm_close_window, launcher, start_overlay, - start_overlay_pane, tab_navigator, CopyOverlay, SearchOverlay, + confirm_close_pane, confirm_close_tab, confirm_close_window, confirm_quit_program, launcher, + start_overlay, start_overlay_pane, tab_navigator, CopyOverlay, SearchOverlay, }; use crate::gui::scrollbar::*; use crate::gui::selection::*; @@ -1972,8 +1972,16 @@ impl TermWindow { con.hide_application(); } QuitApplication => { - let con = Connection::get().expect("call on gui thread"); - con.terminate_message_loop(); + let mux = Mux::get().unwrap(); + let tab = match mux.get_active_tab_for_window(self.mux_window_id) { + Some(tab) => tab, + None => anyhow::bail!("no active tab!?"), + }; + + let (overlay, future) = + start_overlay(self, &tab, move |_tab_id, term| confirm_quit_program(term)); + self.assign_overlay(tab.tab_id(), overlay); + promise::spawn::spawn(future).detach(); } SelectTextAtMouseCursor(mode) => self.select_text_at_mouse_cursor(*mode, pane), ExtendSelectionToMouseCursor(mode) => {