Skip to content

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.

feat(gui): claim the viewport when switching into a cold remote Space

RoversXb3b6898d00db
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index f9d8100b..c56e98ed 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -6626,6 +6626,7 @@ impl super::TermWindow {
if !plan.needs_materialize {
self.adopt_workspace_in_this_window(&plan.workspace_name);
+ self.land_remote_open_on_active_pane();
// This workspace may be live only because startup fell back to a
// `$HOME` shell for a refused Project; add the terminal that was
// actually asked for. Added rather than swapped: the fallback
@@ -6713,7 +6714,19 @@ impl super::TermWindow {
// leaves nothing to activate.
Ok(false) => {}
Ok(true) => {
+ let domain_id = Mux::get()
+ .get_domain_by_name(&domain_name)
+ .map(|domain| domain.domain_id());
window.notify(TermWindowNotif::Apply(Box::new(move |term_window| {
+ // Switching into a cold mux-domain Space is as
+ // explicit an open as the Connect button, so it
+ // gets the same one-shot claim. Armed only: the
+ // retried activation releases it when its tab
+ // is on screen, and the paint path consumes it
+ // once that tab's gate is claimable.
+ if let Some(domain_id) = domain_id {
+ term_window.note_remote_open_intent(domain_id);
+ }
if let Some(win) = term_window.window.clone() {
term_window.activate_workspace_thread_impl(
thread_id,
@@ -6990,6 +7003,9 @@ impl super::TermWindow {
if let Err(err) = result {
log::error!("failed to materialize ThinkTerm thread: {err:#}");
+ // Nothing landed, so there is nothing for the first-open claim
+ // to take; leaving it armed would claim the next tab shown.
+ self.remote_open_intent = None;
// The mux-level backstop refuses *inside* `spawn_tab_or_window`,
// which leaves a tab-less window behind; that would make the
// workspace look materialized and stop any retry.
@@ -7019,10 +7035,12 @@ impl super::TermWindow {
if !self.adopt_workspace_in_this_window(&workspace) {
log::error!("materialized ThinkTerm workspace {workspace:?} has no window to adopt");
+ self.remote_open_intent = None;
kill_workspace_windows(&workspaces_to_kill_after_adopt, None);
release(self);
return;
}
+ self.land_remote_open_on_active_pane();
cleanup_orphaned_mux_window(orphan_candidate_window_id);
kill_workspace_windows(&workspaces_to_kill_after_adopt, Some(&workspace));
front_end().set_switching_workspaces(false);
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index 52eda542..dd219fcb 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -1235,6 +1235,46 @@ impl super::TermWindow {
}
}
+ /// Arm the one-shot first-open claim for a remote domain this window is
+ /// about to show, for the paths that attach in place instead of opening
+ /// a window through `connect_domain_into_space`. Not ready yet: the
+ /// activation that follows may still be materializing its tab, and a
+ /// ready intent would claim whichever tab of that domain the window
+ /// showed meanwhile. `land_remote_open_on_active_pane` releases it once
+ /// the activation has put its tab on screen.
+ pub(crate) fn note_remote_open_intent(&mut self, domain_id: mux::domain::DomainId) {
+ if !self.config.remote_mux_auto_claim_on_open {
+ return;
+ }
+ self.remote_open_intent = Some(super::RemoteOpenIntent {
+ domain_id,
+ ready: false,
+ });
+ }
+
+ /// The activation behind `note_remote_open_intent` has landed: the tab
+ /// now on screen is what the user asked for. Release the claim if that
+ /// tab belongs to the armed domain; a tab of some other remote domain
+ /// means the selection changed underneath, and the intent is dropped.
+ pub(crate) fn land_remote_open_on_active_pane(&mut self) {
+ let Some(intent) = self.remote_open_intent else {
+ return;
+ };
+ if intent.ready {
+ return;
+ }
+ let landed = Mux::get()
+ .get_active_tab_for_window(self.mux_window_id)
+ .and_then(|tab| tab.get_active_pane())
+ .filter(|pane| pane.downcast_ref::<ClientPane>().is_some())
+ .map(|pane| pane.domain_id());
+ match landed {
+ Some(domain_id) if domain_id == intent.domain_id => self.finish_remote_open(domain_id),
+ Some(_) => self.remote_open_intent = None,
+ None => {}
+ }
+ }
+
pub(crate) fn finish_remote_open(&mut self, domain_id: mux::domain::DomainId) {
if let Some(intent) = self.remote_open_intent.as_mut() {
if intent.domain_id == domain_id {