diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 339526865..ff115bf4a 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -419,14 +419,18 @@ impl Mux { .unwrap_or_else(|| DEFAULT_WORKSPACE.to_string()) } + pub fn set_active_workspace_for_client(&self, ident: &Arc, workspace: &str) { + let mut clients = self.clients.borrow_mut(); + if let Some(info) = clients.get_mut(&ident) { + info.active_workspace.replace(workspace.to_string()); + self.notify(MuxNotification::ActiveWorkspaceChanged(ident.clone())); + } + } + /// Assigns the active workspace name for the current identity pub fn set_active_workspace(&self, workspace: &str) { if let Some(ident) = self.identity.borrow().clone() { - let mut clients = self.clients.borrow_mut(); - if let Some(info) = clients.get_mut(&ident) { - info.active_workspace.replace(workspace.to_string()); - self.notify(MuxNotification::ActiveWorkspaceChanged(ident)); - } + self.set_active_workspace_for_client(&ident, workspace); } } diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 1d3bb11e6..6e9d8e75d 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -62,8 +62,23 @@ impl GuiFrontEnd { let mux = Mux::get().expect("mux started and running on main thread"); let workspace = mux.active_workspace_for_client(&client_id); if mux.is_workspace_empty(&workspace) { - log::trace!("Mux workspace is empty, terminate gui"); - Connection::get().unwrap().terminate_message_loop(); + // We don't want to silently kill off things that might + // be running in other workspaces, so let's pick one + // and activate it + let workspaces = mux.iter_workspaces(); + if let Some(workspace) = workspaces.get(0).map(|s| s.to_string()) { + let activity = mux::activity::Activity::new(); + let client_id = client_id.clone(); + promise::spawn::spawn(async move { + let mux = Mux::get().expect("mux started and running on main thread"); + mux.set_active_workspace_for_client(&client_id, &workspace); + switch_workspace(&workspace); + drop(activity); + }).detach(); + } else { + log::trace!("Mux workspace is empty, terminate gui"); + Connection::get().unwrap().terminate_message_loop(); + } } } }