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.

Reconnect UI: stop Space-restore hijack; move indicator to sidebar banner

RoversX53f69caf57d9
diff --git a/mux/src/termwiztermtab.rs b/mux/src/termwiztermtab.rs
index 80b06e10..908e6c8a 100644
--- a/mux/src/termwiztermtab.rs
+++ b/mux/src/termwiztermtab.rs
@@ -535,7 +535,14 @@ pub async fn run<
let window_id = match window_id {
Some(id) => id,
None => {
- window_builder = mux.new_empty_window(None, None);
+ // Mark the window as owned by this domain so that the GUI
+ // treats it like other domain-created windows (no saved
+ // workspace-thread restore may adopt it away): this window
+ // hosts things like auth prompts and reconnect progress,
+ // and re-pointing its GUI window elsewhere would leave the
+ // prompt invisible and block the connection forever.
+ window_builder =
+ mux.new_empty_window_for_domain(None, None, Some(domain.domain_id()));
*window_builder
}
};
diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs
index d27bef84..e0fdb202 100644
--- a/wezterm-client/src/client.rs
+++ b/wezterm-client/src/client.rs
@@ -1122,7 +1122,9 @@ impl Client {
// reused across reconnect cycles. It is closed by a successful
// reattach or when we give up; creating one per cycle piles up
// dead "Reconnecting..." tabs while the remote is unhealthy.
- let mut windowed_ui: Option<ConnectionUI> = None;
+ // Paired with the workspace it was hosted in, so a Space switch
+ // that moves it off screen rebuilds it where the user is now.
+ let mut windowed_ui: Option<(ConnectionUI, String)> = None;
'client: loop {
let session_started = std::time::Instant::now();
@@ -1162,7 +1164,7 @@ impl Client {
// back; detect that so we build a fresh one when needed.
if windowed_ui
.as_ref()
- .map_or(false, |ui| !ui.test_alive())
+ .map_or(false, |(ui, _)| !ui.test_alive())
{
windowed_ui = None;
}
@@ -1177,9 +1179,7 @@ impl Client {
loop {
attempt += 1;
- let mut ui = if let Some(ui) = windowed_ui.clone() {
- ui
- } else if attempt <= 2 {
+ let mut ui = if attempt <= 2 && windowed_ui.is_none() {
ConnectionUI::new_headless()
} else {
// Host the reconnect UI (and any auth prompts)
@@ -1195,9 +1195,10 @@ impl Client {
// window would block the reconnect invisibly
// forever. If this domain has no on-screen
// window, fall back to a standalone window.
- let window_id = Mux::try_get().and_then(|mux| {
+ let placement = Mux::try_get().map(|mux| {
let workspace = mux.active_workspace();
- mux.iter_windows_in_workspace(&workspace)
+ let window_id = mux
+ .iter_windows_in_workspace(&workspace)
.into_iter()
.find(|window_id| {
mux.get_window(*window_id).map_or(false, |w| {
@@ -1210,23 +1211,44 @@ impl Client {
)
})
})
- })
+ });
+ (workspace, window_id)
});
- window_tx.send(window_id).ok();
+ window_tx.send(placement).ok();
})
.detach();
- let ui_window_id = window_rx
+ let (active_workspace, ui_window_id) = window_rx
.recv_timeout(Duration::from_secs(2))
.ok()
- .flatten();
-
- let ui = ConnectionUI::with_params(mux::connui::ConnectionUIParams {
- window_id: ui_window_id,
- ..Default::default()
- });
- ui.title("ThinkTerm: Reconnecting...");
- windowed_ui = Some(ui.clone());
- ui
+ .flatten()
+ .unwrap_or_else(|| (String::new(), None));
+
+ // The user may have switched Spaces since the
+ // visible UI was created; a UI hosted in a
+ // background workspace is off screen and its
+ // prompts can never be answered. Rebuild it
+ // where the user is now.
+ if let Some((ui, hosted_ws)) = &windowed_ui {
+ if !active_workspace.is_empty()
+ && hosted_ws != &active_workspace
+ {
+ ui.close();
+ windowed_ui = None;
+ }
+ }
+
+ if let Some((ui, _)) = &windowed_ui {
+ ui.clone()
+ } else {
+ let ui =
+ ConnectionUI::with_params(mux::connui::ConnectionUIParams {
+ window_id: ui_window_id,
+ ..Default::default()
+ });
+ ui.title("ThinkTerm: Reconnecting...");
+ windowed_ui = Some((ui.clone(), active_workspace));
+ ui
+ }
};
if ui
@@ -1282,7 +1304,7 @@ impl Client {
// Whatever ended the loop (cancelled by user, not
// reconnectable), don't leave the reconnect tab behind.
- if let Some(ui) = windowed_ui.take() {
+ if let Some((ui, _)) = windowed_ui.take() {
ui.close();
}
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 11384e8f..be3391e0 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -950,10 +950,6 @@ pub struct TermWindow {
line_quad_cache: RefCell<LfuCache<LineQuadCacheKey, LineQuadCacheValue>>,
last_status_call: Instant,
- /// Whether the last status tick found a lagging client pane (the
- /// "Reconnecting…" badge was drawn); used to repaint once more after
- /// recovery so a stale badge doesn't linger on an idle pane.
- connection_badge_was_visible: bool,
cursor_blink_state: RefCell<ColorEase>,
blink_state: RefCell<ColorEase>,
rapid_blink_state: RefCell<ColorEase>,
@@ -1450,8 +1446,15 @@ impl TermWindow {
let connection_name = Connection::get().unwrap().name();
let (space_owner_id, active_space_id) = claimed_space.unwrap_or_else(|| {
let space_owner_id = crate::workspace_threads::next_space_owner_id();
- let active_space_id =
- crate::workspace_threads::claim_initial_space_for_window(space_owner_id);
+ // Windows created without a saved-thread restore are incidental
+ // (domain-owned windows spawned by the reconcile, e.g. reconnect
+ // or auth prompt windows); claiming a Space for them must not
+ // overwrite the user's last-active-Space record.
+ let active_space_id = if restore_saved_thread {
+ crate::workspace_threads::claim_initial_space_for_window(space_owner_id)
+ } else {
+ crate::workspace_threads::claim_space_for_incidental_window(space_owner_id)
+ };
(space_owner_id, active_space_id)
});
let workspace_layout_structure_fingerprint =
@@ -1544,7 +1547,6 @@ impl TermWindow {
&config,
)),
last_status_call: Instant::now(),
- connection_badge_was_visible: false,
cursor_blink_state: RefCell::new(ColorEase::new(
config.cursor_blink_rate,
config.cursor_blink_ease_in,
@@ -2277,20 +2279,6 @@ impl TermWindow {
TermWindowNotif::EmitStatusUpdate => {
self.emit_status_event();
self.refresh_all_thread_work();
- // Drive the per-pane "Reconnecting…" badge: a lagging
- // session produces no output, so nothing else would
- // repaint it (or clear a stale badge after recovery).
- let lagging = self
- .get_panes_to_render()
- .iter()
- .any(|pos| {
- crate::termwindow::render::pane::client_pane_lag_ms(pos.pane.as_ref())
- .is_some()
- });
- if lagging || self.connection_badge_was_visible {
- window.invalidate();
- }
- self.connection_badge_was_visible = lagging;
}
TermWindowNotif::OpenProjectPath(path) => {
let path = path.to_string_lossy();
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index e189a7af..2b24e258 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -965,68 +965,6 @@ impl crate::TermWindow {
Ok(())
}
- /// GUI-level connection-health badge for mux client panes: while the
- /// server has stopped responding (a reconnect is pending or running),
- /// draw a pill at the pane's top-right, below the nav bar, instead of
- /// writing into the terminal content. The periodic status update keeps
- /// invalidating the window while any pane lags, so the counter is live.
- fn paint_pane_connection_badge(
- &mut self,
- pos: &PositionedPane,
- layers: &mut TripleLayerQuadAllocator,
- nav_height: usize,
- ) -> anyhow::Result<()> {
- let Some(lag_ms) = client_pane_lag_ms(pos.pane.as_ref()) else {
- return Ok(());
- };
-
- let (pane_x, pane_y) = self.pane_content_origin(pos)?;
- let pane_width = pos.width as f32 * self.render_metrics.cell_size.width as f32;
-
- let ui_font = self
- .fonts
- .title_font_with_size(crate::native_settings::pane_header_font_size())
- .context("connection badge font")?;
- let ui_metrics = RenderMetrics::with_font_metrics(&ui_font.metrics());
-
- let text = format!("Reconnecting… {}s", lag_ms / 1000);
- let text_cell_w = ui_metrics.cell_size.width as usize;
- let text_h = ui_metrics.cell_size.height as usize;
- let text_w = wezterm_term::unicode_column_width(&text, None) * text_cell_w;
-
- const PAD_X: usize = 10;
- const PAD_Y: usize = 5;
- const MARGIN: usize = 10;
- let badge_w = (text_w + PAD_X * 2) as f32;
- let badge_h = (text_h + PAD_Y * 2) as f32;
- let badge_x = pane_x + pane_width - badge_w - MARGIN as f32;
- let badge_y = pane_y + nav_height as f32 + MARGIN as f32;
- if badge_x < pane_x {
- // Pane too narrow for the badge; don't overdraw the neighbour.
- return Ok(());
- }
-
- self.fill_rounded_rectangle(
- layers,
- 1,
- euclid::rect(badge_x, badge_y, badge_w, badge_h),
- LinearRgba::with_srgba(0xc2, 0x6a, 0x1d, 0xe8),
- (badge_h / 2.0).min(10.0),
- )
- .context("connection badge background")?;
- self.paint_pane_nav_text(
- layers,
- &ui_font,
- ui_metrics,
- &text,
- (badge_x as usize) + PAD_X,
- (badge_y as usize) + PAD_Y,
- text_w + text_cell_w,
- LinearRgba::with_srgba(0xff, 0xff, 0xff, 0xff),
- )?;
- Ok(())
- }
-
fn paint_pane_box_model(&mut self, pos: &PositionedPane) -> anyhow::Result<()> {
let computed = self.build_pane(pos)?;
let mut ui_items = computed.ui_items();
@@ -1245,8 +1183,6 @@ impl crate::TermWindow {
let pane_nav_height = self
.paint_pane_nav_bar(pos, layers, &palette)
.context("paint_pane_nav_bar")?;
- self.paint_pane_connection_badge(pos, layers, pane_nav_height)
- .context("paint_pane_connection_badge")?;
if self.collapsed_pane_layouts.contains_key(&pos.pane_stack_id) {
return Ok(());
}
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 34dac659..42392be1 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -46,6 +46,7 @@ const SESSION_STATUS_ICON_SIZE: usize = 20;
const SESSION_STATUS_ACTIVE_ICON_SIZE: usize = 26;
const SESSION_STATUS_DONE_COLOR: LinearRgba = LinearRgba::with_components(0.20, 0.78, 0.36, 1.0);
const SESSION_STATUS_OPEN_COLOR: LinearRgba = LinearRgba::with_components(0.12, 0.48, 1.0, 1.0);
+const SPACE_DISCONNECTED_COLOR: LinearRgba = LinearRgba::with_components(0.86, 0.45, 0.12, 1.0);
const SIDEBAR_SECTION_ACTION_SIZE: usize = 48;
const SIDEBAR_SECTION_ACTION_ICON_INSET: usize = 6;
@@ -81,6 +82,10 @@ struct WorkspaceSidebarLayout {
show_sidebar_toolbar: bool,
space_menu_y: usize,
space_menu_height: usize,
+ /// Height of the "Server disconnected" banner row shown below the Space
+ /// menu while a client-domain Space's server is unresponsive; 0 when
+ /// connected (the banner is absent and everything below moves up).
+ connection_banner_height: usize,
top_action_y_offset: usize,
top_action_height: usize,
list_top: usize,
@@ -265,6 +270,32 @@ impl crate::TermWindow {
}
}
+ /// Whether the mux server behind a client-domain Space has stopped
+ /// responding (a reconnect is pending or running). While the Space is
+ /// remote we keep a slow self-driven repaint tick going: a dead
+ /// connection produces no output, so nothing else would repaint the
+ /// indicator when the state flips.
+ fn space_connection_lost(&self, space_id: &str) -> bool {
+ let Some(domain_name) = workspace_threads::client_domain_for_space(space_id) else {
+ return false;
+ };
+ self.update_next_frame_time(Some(
+ std::time::Instant::now() + std::time::Duration::from_secs(1),
+ ));
+ let mux = Mux::get();
+ let Some(domain) = mux.get_domain_by_name(&domain_name) else {
+ return false;
+ };
+ if domain.state() != mux::domain::DomainState::Attached {
+ return false;
+ }
+ let domain_id = domain.domain_id();
+ mux.iter_panes().iter().any(|pane| {
+ pane.domain_id() == domain_id
+ && crate::termwindow::render::pane::client_pane_lag_ms(pane.as_ref()).is_some()
+ })
+ }
+
fn is_workspace_sidebar_thread_selected(
&self,
session: &workspace_threads::WorkspaceThreadView,
@@ -409,6 +440,14 @@ impl crate::TermWindow {
let space_menu_y = y;
let space_menu_height = top_action_height + 6;
y += space_menu_height + SIDEBAR_INSET;
+ let connection_banner_height = if self.space_connection_lost(&self.active_space_id) {
+ ui_cell_height + SIDEBAR_INSET
+ } else {
+ 0
+ };
+ if connection_banner_height > 0 {
+ y += connection_banner_height + SIDEBAR_INSET;
+ }
let list_top = y + top_action_y_offset + top_action_height + SIDEBAR_INSET;
WorkspaceSidebarLayout {
@@ -423,6 +462,7 @@ impl crate::TermWindow {
show_sidebar_toolbar,
space_menu_y,
space_menu_height,
+ connection_banner_height,
top_action_y_offset,
top_action_height,
list_top,
@@ -861,7 +901,52 @@ impl crate::TermWindow {
muted_fg
},
)?;
- let y = space_menu_y + space_menu_height + SIDEBAR_INSET;
+ let mut y = space_menu_y + space_menu_height + SIDEBAR_INSET;
+ if layout.connection_banner_height > 0 {
+ let banner_x = item_x + SIDEBAR_INSET;
+ let banner_width = item_width.saturating_sub(SIDEBAR_INSET * 2);
+ let banner_height = layout.connection_banner_height;
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(
+ banner_x as f32,
+ y as f32,
+ banner_width as f32,
+ banner_height as f32,
+ ),
+ SPACE_DISCONNECTED_COLOR.mul_alpha(0.18),
+ SIDEBAR_ROW_RADIUS,
+ )
+ .context("sidebar connection banner")?;
+ let banner_icon_size = ui_cell_height.min(banner_height.saturating_sub(6));
+ let banner_icon_x = banner_x + SIDEBAR_INSET;
+ let banner_icon_y = y + ((banner_height.saturating_sub(banner_icon_size)) / 2);
+ self.paint_sidebar_icon(
+ layers,
+ SvgIcon::CircleAlert,
+ banner_icon_x,
+ banner_icon_y,
+ banner_icon_size,
+ SPACE_DISCONNECTED_COLOR,
+ )?;
+ let banner_text_x = banner_icon_x + banner_icon_size + SIDEBAR_ICON_GAP;
+ let banner_text_max =
+ (banner_x + banner_width).saturating_sub(banner_text_x + SIDEBAR_INSET);
+ let banner_label =
+ self.ellipsize_sidebar_text(&ui_font, "Server disconnected", banner_text_max)?;
+ self.paint_sidebar_text(
+ layers,
+ &ui_font,
+ ui_metrics,
+ banner_label.as_ref(),
+ banner_text_x,
+ y + ((banner_height.saturating_sub(ui_cell_height)) / 2),
+ banner_text_max,
+ SPACE_DISCONNECTED_COLOR,
+ )?;
+ y += banner_height + SIDEBAR_INSET;
+ }
let top_action_x = item_x + SIDEBAR_INSET;
let top_action_y = y + top_action_y_offset;
let notification_action_size = top_action_height;
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 2e9ca7e4..a9b0331c 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -487,6 +487,30 @@ pub fn claim_space_for_new_window(owner_id: u64) -> SpaceId {
claim_initial_space_for_window(owner_id)
}
+/// Claim a Space for a window the user did not explicitly open (domain-owned
+/// windows spawned by the reconcile, e.g. a reconnect/auth prompt window).
+/// Picks a free Space like [`claim_initial_space_for_window`] but never
+/// records it as the user's last active Space: these windows are incidental
+/// and must not affect which Space the next startup or Dock window restores.
+pub fn claim_space_for_incidental_window(owner_id: u64) -> SpaceId {
+ let occupied = WINDOW_SPACES
+ .lock()
+ .iter()
+ .filter_map(|(owner, space)| (*owner != owner_id).then(|| space.clone()))
+ .collect::<std::collections::HashSet<_>>();
+
+ let mut store = THREAD_STORE.lock();
+ let changed = store.normalize_after_load();
+ let space_id = store.claim_available_space_id(&occupied);
+ if changed {
+ persist_locked(&store);
+ }
+ drop(store);
+
+ WINDOW_SPACES.lock().insert(owner_id, space_id.clone());
+ space_id
+}
+
pub fn release_window_space(owner_id: u64) {
WINDOW_SPACES.lock().remove(&owner_id);
}