A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
fix(gui): stop thread windows sharing or stranding a thread
RoversX6384a002c02c
diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rsindex 328bd3d3..b9eec0b6 100644--- a/wezterm-gui/src/frontend.rs+++ b/wezterm-gui/src/frontend.rs@@ -881,6 +881,11 @@ impl GuiFrontEnd {}pub(crate) fn spawn_space_window(&self) {+ self.spawn_space_window_then(|| {});+ }++ /// As `spawn_space_window`, with `opened` to run once the window is up.+ pub(crate) fn spawn_space_window_then(&self, opened: impl FnOnce() + 'static) {// Each Dock "New Window" gets its own Space and its own GUI window, and// must work regardless of whatever else is in flight. We claim a// distinct (unoccupied) Space synchronously so rapid repeated clicks@@ -916,6 +921,7 @@ impl GuiFrontEnd {}.await;+ let is_open = result.is_ok();match result {Ok(()) => front_end().opening_succeeded(),Err(err) => {@@ -925,6 +931,9 @@ impl GuiFrontEnd {}}front_end().set_switching_workspaces(false);+ if is_open {+ opened();+ }}).detach();}diff --git a/wezterm-gui/src/notification_click.rs b/wezterm-gui/src/notification_click.rsindex 63c17ef0..ee03ffbe 100644--- a/wezterm-gui/src/notification_click.rs+++ b/wezterm-gui/src/notification_click.rs@@ -63,7 +63,7 @@ fn this_run() -> &'static str {pub fn install() {wezterm_toast_notification::set_click_handler(|click| {// The system reports the click on a thread of its own.- promise::spawn::spawn_into_main_thread(async move { reveal(click) }).detach();+ promise::spawn::spawn_into_main_thread(async move { reveal(click, true) }).detach();});// The click handler is otherwise set up with this run's first// notification, and a click on one still listed from before is lost.@@ -75,7 +75,8 @@ pub fn install() {}}-fn reveal(click: NotificationClick) {+/// `may_open` says a window that can go to the target may be opened for it.+fn reveal(click: NotificationClick, may_open: bool) {let Some(target) = NotificationTarget::decode(&click.target, this_run()) else {return;};@@ -85,6 +86,7 @@ fn reveal(click: NotificationClick) {};let mux = Mux::get();let windows = front_end.gui_windows();+ let retry = click.clone();let token = click.activation_token;match target {NotificationTarget::Pane(pane_id) => {@@ -115,6 +117,8 @@ fn reveal(click: NotificationClick) {window.focus_with_activation_token(token.as_deref());}})));+ } else if may_open && !windows.is_empty() {+ reveal_from_new_window(retry);}}NotificationTarget::Thread(workspace) => {@@ -141,11 +145,19 @@ fn reveal(click: NotificationClick) {window.focus_with_activation_token(token.as_deref());}})));+ } else if may_open && !windows.is_empty() {+ reveal_from_new_window(retry);}}}}+/// Only threads' own windows are up, and those go nowhere else: the click+/// comes back to a window that can.+fn reveal_from_new_window(click: NotificationClick) {+ crate::frontend::front_end().spawn_space_window_then(move || reveal(click, false));+}+/// The window last in use, which the paths to other threads and Spaces/// start from.fn last_used(windows: &[GuiWin]) -> Option<&GuiWin> {@@ -162,7 +174,6 @@ fn last_used(windows: &[GuiWin]) -> Option<&GuiWin> {.filter(free).find(|gui| Some(gui.mux_window_id) == focused).or_else(|| windows.iter().find(free))- .or_else(|| windows.first())}#[cfg(test)]diff --git a/wezterm-gui/src/termwindow/thread_window.rs b/wezterm-gui/src/termwindow/thread_window.rsindex 7da2f854..5e05d5b9 100644--- a/wezterm-gui/src/termwindow/thread_window.rs+++ b/wezterm-gui/src/termwindow/thread_window.rs@@ -318,7 +318,10 @@ impl TermWindow {let return_to = if self.elsewhere_page.is_some() {None} else {+ // Recorded as soon as it was picked, it may be this very+ // thread, on its way here.workspace_threads::recorded_active_thread_for_space(&self.active_space_id)+ .filter(|active| *active != thread_id)};self.thread_bound_for_own_window = Some(ThreadBoundForOwnWindow {thread_id: thread_id.clone(),@@ -359,9 +362,13 @@ impl TermWindow {workspace_threads::activation_plan_for_thread(thread_id, &live_workspaces).is_some_and(|plan| !plan.needs_materialize)});- match return_to {- Some(return_to) => self.activate_workspace_thread(return_to, window),- None => self.show_thread_elsewhere_page(thread_id.clone()),+ if let Some(return_to) = return_to {+ self.activate_workspace_thread(return_to, window);+ }+ // Another window may have that thread by now, and two cannot+ // share this one.+ if self.mux_window_id == mux_window_id {+ self.show_thread_elsewhere_page(thread_id.clone());}}// The reconcile must leave this one to us: it has a window coming.@@ -1061,6 +1068,17 @@ impl TermWindow {}}+ /// What a page's button does: to the thread's own window or, with that+ /// gone, to the window that took the thread back. Activating comes to+ /// that window, or opens the thread here if none did.+ fn go_to_thread_on_page(&mut self, thread_id: WorkspaceThreadId) {+ if front_end().thread_is_in_own_window(&thread_id) {+ self.focus_thread_window(&thread_id);+ } else if let Some(window) = self.window.clone() {+ self.activate_workspace_thread(thread_id, &window);+ }+ }+/// Hand `assignment` to a window that shows the thread list, from one/// that does not.pub(crate) fn hand_on_assignment(&self, assignment: KeyAssignment) {@@ -1265,7 +1283,13 @@ impl TermWindow {workspace_threads::activation_plan_for_thread(thread_id, &live_workspaces).is_some_and(|plan| !plan.needs_materialize);if still_running {- self.activate_workspace_thread(thread_id.to_string(), &window);+ // Another page got there first. This one stays, and its button+ // goes to that window.+ let taken = workspace_threads::thread_workspace_name(thread_id)+ .is_some_and(|workspace| self.workspace_shown_elsewhere(&workspace));+ if !taken {+ self.activate_workspace_thread(thread_id.to_string(), &window);+ }return;}// It ended in its window: on to another, as when a window's own@@ -1410,7 +1434,7 @@ impl ThreadElsewhereView {fn go_to_window(&self) -> ContentViewResponse {let thread_id = self.thread_id.clone();ContentViewResponse::Run(Box::new(move |term_window| {- term_window.focus_thread_window(&thread_id);+ term_window.go_to_thread_on_page(thread_id);}))}diff --git a/wezterm-gui/src/termwindow/ui/agent_panel.rs b/wezterm-gui/src/termwindow/ui/agent_panel.rsindex 14da1937..8a3fb539 100644--- a/wezterm-gui/src/termwindow/ui/agent_panel.rs+++ b/wezterm-gui/src/termwindow/ui/agent_panel.rs@@ -1786,7 +1786,7 @@ impl TermWindow {/// Whether activating `workspace`'s thread here would hand it to another/// window already showing it: the check `activate_workspace_thread` makes.- fn workspace_shown_elsewhere(&self, workspace: &str) -> bool {+ pub(crate) fn workspace_shown_elsewhere(&self, workspace: &str) -> bool {crate::workspace_threads::window_to_show_in_workspace(workspace).is_some_and(|target| {target != self.mux_window_id&& crate::frontend::front_end()