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
Synchronize remote pane sizes after window adoption
RoversX63a03cc7c22b
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex ae1f0757..35702ed7 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -2236,6 +2236,10 @@ impl TermWindow {// re-applied; the adopt-time application ran before// these panes existed.self.apply_workspace_thread_font_scales();+ // Remote panes are skipped by Tab::resize. A tab can arrive+ // while the connection content view suppresses paint-time+ // pane sync, so impose the actual GUI geometry immediately.+ self.force_sync_active_mux_tab_pane_sizes();self.persist_workspace_layout_after_mutation("tab added");}MuxNotification::PaneOutput(pane_id) => {@@ -2376,16 +2380,14 @@ impl TermWindow {self.sync_content_view_surfaces_with_mux();self.clear_all_overlays();self.current_highlight.take();- self.apply_workspace_thread_font_scales();self.invalidate_fancy_tab_bar();self.invalidate_modal();- let mux = Mux::get();- if let Some(window) = mux.get_window(self.mux_window_id) {- for tab in window.iter() {- tab.resize(self.terminal_size);- }- };+ // Tab::resize updates the local split tree but deliberately skips+ // remote mirror panes. Force the per-pane GUI-sized resize now rather+ // than waiting for a later paint (a connection view may still be up).+ self.resize_mux_tabs_to_current_terminal_size();+ self.apply_workspace_thread_font_scales();self.sync_current_workspace_thread();self.update_title();if let Some(window) = self.window.as_ref() {diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex b76cfdec..8debaf35 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -12,6 +12,7 @@ use crate::termwindow::{GuiWin, MouseCapture, PaneNavAction, PositionedSplit, ScrollHit, TabWheelSurface,TermWindowNotif, UIItem, UIItemType, TMB,};+use crate::utilsprites::RenderMetrics;use ::window::{ContextMenuItem, IntegratedTitleButtonStyle, MouseButtons as WMB, MouseCursor, MouseEvent,MouseEventKind as WMEK, MousePress, WindowDecorations, WindowOps, WindowState,@@ -41,6 +42,61 @@ use wezterm_term::{ClickPosition, LastMouseClick, StableRowIndex};const TAB_WHEEL_SURFACE_LOCK_MS: u64 = 700;const TAB_WHEEL_DIRECTION_LOCK_MS: u64 = 140;+const WINDOW_TAB_FEW_COUNT_WIDTH_FACTOR: f32 = 1.16;+const WINDOW_TAB_MANY_COUNT_WIDTH_FACTOR: f32 = 0.86;+const WINDOW_TAB_MIN_WIDTH_FACTOR: f32 = 0.78;++fn adaptive_window_tab_width(+ preferred: f32,+ minimum: f32,+ viewport: f32,+ tab_count: usize,+ gap: f32,+) -> f32 {+ if tab_count == 0 {+ return preferred.max(1.0);+ }++ // One or two tabs get a little more breathing room. As the row fills, the+ // target contracts smoothly rather than jumping at a single threshold.+ let density_factor = if tab_count <= 2 {+ WINDOW_TAB_FEW_COUNT_WIDTH_FACTOR+ } else {+ (1.10 - (tab_count.saturating_sub(2) as f32 * 0.04)).max(WINDOW_TAB_MANY_COUNT_WIDTH_FACTOR)+ };+ let target = preferred.max(1.0) * density_factor;+ let gaps = gap.max(0.0) * tab_count.saturating_sub(1) as f32;+ let fitting_width = (viewport.max(0.0) - gaps).max(0.0) / tab_count as f32;+ fitting_width.min(target).max(minimum.min(target).max(1.0))+}++#[cfg(test)]+mod adaptive_window_tab_width_tests {+ use super::adaptive_window_tab_width;++ #[test]+ fn few_tabs_are_roomier_and_many_tabs_are_compact() {+ let one = adaptive_window_tab_width(200.0, 150.0, 2400.0, 1, 18.0);+ let four = adaptive_window_tab_width(200.0, 150.0, 2400.0, 4, 18.0);+ let eight = adaptive_window_tab_width(200.0, 150.0, 2400.0, 8, 18.0);+ assert!(one > four);+ assert!(four > eight);+ assert!((one - 232.0).abs() < 0.001);+ assert!((eight - 172.0).abs() < 0.001);+ }++ #[test]+ fn narrow_viewport_uses_minimum_then_scrolls() {+ let width = adaptive_window_tab_width(200.0, 150.0, 300.0, 6, 18.0);+ assert!((width - 150.0).abs() < 0.001);+ }++ #[test]+ fn available_space_can_shrink_tabs_between_target_and_minimum() {+ let width = adaptive_window_tab_width(200.0, 150.0, 700.0, 4, 18.0);+ assert!((width - 161.5).abs() < 0.001);+ }+}/// Overall ceiling on the "Connecting…" phase, as a backstop for the case where/// the TCP connect succeeds but the SSH banner/handshake then stalls (the/// per-connect `connecttimeout` only bounds the TCP connect itself).@@ -82,6 +138,44 @@ impl super::TermWindow {.ceil()}+ pub(super) fn window_tab_count_for_layout(&self) -> usize {+ let window_tab_count = if self.active_content_view_is_remote_thread() {+ 0+ } else {+ Mux::get()+ .get_window(self.mux_window_id)+ .map_or(0, |window| window.len())+ };+ window_tab_count + self.content_view_count()+ }++ pub(super) fn adaptive_window_tab_width_pixels(&self, tab_count: usize) -> f32 {+ let fallback_cell_width = self.render_metrics.cell_size.width.max(1) as f32;+ let cell_width = self+ .fonts+ .title_font_with_size(crate::native_settings::tab_font_size())+ .map(|font| {+ RenderMetrics::with_font_metrics(&font.metrics())+ .cell_size+ .width+ .max(1) as f32+ })+ .unwrap_or(fallback_cell_width);+ let preferred = (self.config.tab_max_width as f32 * cell_width)+ .max(cell_width * 15.0)+ .max(self.ui_f32(176.0))+ .ceil();+ let minimum = (preferred * WINDOW_TAB_MIN_WIDTH_FACTOR).max(self.ui_f32(136.0));+ adaptive_window_tab_width(+ preferred,+ minimum,+ self.window_tab_viewport_width(),+ tab_count,+ self.ui_f32(WINDOW_TAB_GAP as f32),+ )+ .ceil()+ }+fn window_tab_chrome_params(&self) -> WindowTabChromeParams {WindowTabChromeParams {use_fancy_tab_bar: self.config.use_fancy_tab_bar,@@ -186,21 +280,16 @@ impl super::TermWindow {}pub(super) fn max_window_tab_scroll_offset(&self) -> f32 {- let mux = Mux::get();- let Some(window) = mux.get_window(self.mux_window_id) else {- return 0.0;- };- let window_tab_count = if self.active_content_view_is_remote_thread() {- 0- } else {- window.len()- };- let tab_count = window_tab_count + self.content_view_count();+ let tab_count = self.window_tab_count_for_layout();if tab_count <= 1 {return 0.0;}- let tab_width = self.window_tab_width_pixels();+ let tab_width = if self.config.use_fancy_tab_bar {+ self.adaptive_window_tab_width_pixels(tab_count)+ } else {+ self.window_tab_width_pixels()+ };let tab_gap = if self.config.use_fancy_tab_bar {self.ui_px(WINDOW_TAB_GAP) as f32} else {diff --git a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rsindex 207b3b5c..02c95569 100644--- a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs+++ b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs@@ -47,7 +47,8 @@ impl crate::TermWindow {.fonts.title_font_with_size(crate::native_settings::tab_font_size())?;let metrics = RenderMetrics::with_font_metrics(&font.metrics());- let tab_width = self.window_tab_width_pixels().ceil() as usize;+ let tab_count = self.window_tab_count_for_layout();+ let tab_width = self.adaptive_window_tab_width_pixels(tab_count) as usize;let background = chrome.sidebar_bg;let foreground = chrome.text;@@ -889,8 +890,9 @@ impl crate::TermWindow {.saturating_add(tab_width).saturating_sub(button_size + self.ui_px(TAB_CLOSE_RIGHT_GAP));let close_y = row_y + (row_height.saturating_sub(button_size) / 2);- let show_close =+ let close_slot_visible =close_x >= viewport_left && close_x.saturating_add(button_size) <= viewport_right;+ let show_close = close_slot_visible && (active || is_hovered);if show_close {let close_hovered =self.is_pointer_over_ui_rect(close_x, close_y, button_size, button_size);@@ -916,7 +918,7 @@ impl crate::TermWindow {}let text_x = icon_x + icon_size + self.ui_px(WINDOW_TAB_ICON_GAP);- let text_right = if show_close {+ let text_right = if close_slot_visible {close_x.saturating_sub(self.ui_px(WINDOW_TAB_ICON_GAP))} else {tab_left@@ -1103,6 +1105,7 @@ impl crate::TermWindow {}text.push_str(value);}+ let text = self.ellipsize_ui_text(font, &text, width)?;self.paint_ui_title_text(layers, font, &metrics, &text, x, y, width, foreground)}diff --git a/wezterm-gui/src/termwindow/render/tab_bar.rs b/wezterm-gui/src/termwindow/render/tab_bar.rsindex 1ba34fe3..792e16ba 100644--- a/wezterm-gui/src/termwindow/render/tab_bar.rs+++ b/wezterm-gui/src/termwindow/render/tab_bar.rs@@ -1,14 +1,42 @@use crate::quad::TripleLayerQuadAllocator;use crate::termwindow::render::RenderScreenLineParams;use crate::termwindow::theme_aligned_tab_bar_colors_from_palette;-use crate::termwindow::ui::pane_nav_bar_height_for_metrics;-use crate::termwindow::ui::tokens::WINDOW_TAB_TOP_SPACER;+use crate::termwindow::ui::tokens::{TAB_VERTICAL_PADDING, WINDOW_TAB_TOP_SPACER};+use crate::ui::scale_ui_usize;use crate::utilsprites::RenderMetrics;use config::ConfigHandle;use mux::renderable::RenderableDimensions;use wezterm_term::color::ColorAttribute;use window::color::LinearRgba;+fn fancy_tab_bar_pixel_height(cell_height: usize, dpi: usize) -> usize {+ cell_height.max(1)+ + scale_ui_usize(TAB_VERTICAL_PADDING, dpi) * 2+ + scale_ui_usize(WINDOW_TAB_TOP_SPACER, dpi)+}++#[cfg(test)]+mod tests {+ use super::fancy_tab_bar_pixel_height;++ #[test]+ fn fancy_height_scales_with_monitor_dpi() {+ let design_dpi = if cfg!(target_os = "macos") { 144 } else { 96 };+ let base = fancy_tab_bar_pixel_height(20, design_dpi);+ let doubled = fancy_tab_bar_pixel_height(40, design_dpi * 2);+ assert_eq!(doubled, base * 2);+ }++ #[test]+ fn fancy_height_tracks_its_own_font_cell() {+ let dpi = if cfg!(target_os = "macos") { 144 } else { 96 };+ assert_eq!(+ fancy_tab_bar_pixel_height(30, dpi) - fancy_tab_bar_pixel_height(20, dpi),+ 10+ );+ }+}+impl crate::TermWindow {pub fn paint_tab_bar(&mut self, layers: &mut TripleLayerQuadAllocator) -> anyhow::Result<()> {if self.config.use_fancy_tab_bar {@@ -126,11 +154,20 @@ impl crate::TermWindow {pub fn tab_bar_pixel_height_impl(config: &ConfigHandle,- _fontconfig: &wezterm_font::FontConfiguration,+ fontconfig: &wezterm_font::FontConfiguration,render_metrics: &RenderMetrics,) -> anyhow::Result<f32> {if config.use_fancy_tab_bar {- Ok((pane_nav_bar_height_for_metrics(*render_metrics) + WINDOW_TAB_TOP_SPACER) as f32)+ // Fancy tabs use their own UI font. Basing their height on the+ // terminal font made the chrome unexpectedly tall whenever the+ // terminal font was enlarged, even though the tab text stayed at+ // its configured size.+ let font = fontconfig.title_font_with_size(crate::native_settings::tab_font_size())?;+ let tab_metrics = RenderMetrics::with_font_metrics(&font.metrics());+ Ok(fancy_tab_bar_pixel_height(+ tab_metrics.cell_size.height.max(1) as usize,+ fontconfig.get_dpi(),+ ) as f32)} else {Ok(render_metrics.cell_size.height as f32)}diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rsindex 769b08af..419d8fd9 100644--- a/wezterm-gui/src/termwindow/resize.rs+++ b/wezterm-gui/src/termwindow/resize.rs@@ -320,11 +320,7 @@ impl super::TermWindow {Ok(())}- pub fn sync_pane_font_sizes(&self) {- if self.content_view_foreground() {- return;- }-+ fn sync_active_mux_tab_pane_sizes(&self) {for pos in self.get_panes_to_render() {if let Err(err) = self.sync_positioned_pane_font_size(&pos) {log::error!(@@ -336,6 +332,20 @@ impl super::TermWindow {}}+ pub fn sync_pane_font_sizes(&self) {+ if self.content_view_foreground() {+ return;+ }+ self.sync_active_mux_tab_pane_sizes();+ }++ /// Synchronize the newly adopted mux window even if a connection content+ /// view is still foreground. Remote mirror panes are intentionally skipped+ /// by Tab::resize, so attach/switch paths must explicitly size each pane.+ pub(crate) fn force_sync_active_mux_tab_pane_sizes(&self) {+ self.sync_active_mux_tab_pane_sizes();+ }+pub(crate) fn resize_mux_tabs_to_current_terminal_size(&mut self) {let mux = Mux::get();if let Some(window) = mux.get_window(self.mux_window_id) {@@ -344,7 +354,7 @@ impl super::TermWindow {}}self.reapply_collapsed_panes_for_window();- self.sync_pane_font_sizes();+ self.force_sync_active_mux_tab_pane_sizes();}pub fn resize(@@ -519,7 +529,10 @@ impl super::TermWindow {self.resize_mux_tabs_to_current_terminal_size();}} else {- log::trace!("terminal size unchanged; skipping mux tab resize");+ log::trace!("terminal size unchanged; syncing active pane geometry");+ if !self.content_view_foreground() {+ self.sync_pane_font_sizes();+ }}self.resize_overlays();diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rsindex 4f0cbed4..52c7bd39 100644--- a/wezterm-gui/src/termwindow/ui/sidebar.rs+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs@@ -711,7 +711,7 @@ impl crate::TermWindow {let row_text_x = row_icon_x + row_icon_size + self.ui_px(SIDEBAR_ICON_GAP);let row_text_max =(row_x + row_width).saturating_sub(row_text_x + self.ui_px(SIDEBAR_INSET));- let row_label = self.ellipsize_sidebar_text(+ let row_label = self.ellipsize_ui_text(ui_font,if reconnect_in_flight {"Connecting…"@@ -1019,7 +1019,7 @@ impl crate::TermWindow {let space_name = crate::workspace_threads::active_space_name(&self.active_space_id).unwrap_or_else(|| "Default".to_string());let space_title = self.sidebar_space_title(&self.active_space_id, &space_name);- let space_label = self.ellipsize_sidebar_text(+ let space_label = self.ellipsize_ui_text(&ui_font,&space_title,space_text_right.saturating_sub(space_text_x),@@ -1171,7 +1171,7 @@ impl crate::TermWindow {let top_action_text_max_width = top_action_width.saturating_sub(top_action_icon_size + top_action_gap + self.ui_px(SIDEBAR_INSET) * 2);let top_action_label =- self.ellipsize_sidebar_text(&ui_font, "New Thread", top_action_text_max_width)?;+ self.ellipsize_ui_text(&ui_font, "New Thread", top_action_text_max_width)?;let top_action_text_width = self.sidebar_text_width(&ui_font, top_action_label.as_ref())?.ceil()@@ -2500,7 +2500,7 @@ impl crate::TermWindow {return Ok(());}- let text = self.ellipsize_sidebar_text(font, text, width)?;+ let text = self.ellipsize_ui_text(font, text, width)?;if text.is_empty() {return Ok(());}@@ -2509,7 +2509,7 @@ impl crate::TermWindow {Ok(())}- fn ellipsize_sidebar_text<'a>(+ pub(crate) fn ellipsize_ui_text<'a>(&self,font: &Rc<LoadedFont>,text: &'a str,@@ -2683,7 +2683,7 @@ impl crate::TermWindow {/// fits in `budget`. `glyphs` are `(advance_px, cluster)` pairs in visual order,/// where `cluster` is the source byte offset of each glyph. Cutting at the/// *next* glyph's cluster guarantees we never split a multi-byte character or a-/// shaped cluster. Used by `ellipsize_sidebar_text` to truncate in a single+/// shaped cluster. Used by `ellipsize_ui_text` to truncate in a single/// shaping pass instead of re-shaping a growing prefix per grapheme.fn ellipsize_cut_byte(glyphs: &[(f32, usize)], text_len: usize, budget: f32) -> usize {let mut acc = 0.0f32;