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.

Make split-tree and GUI pane sizing agree

RoversX35d526df3be5
diff --git a/mux/src/lib.rs b/mux/src/lib.rs
index cbdc728e..bb39e961 100644
--- a/mux/src/lib.rs
+++ b/mux/src/lib.rs
@@ -2058,6 +2058,7 @@ impl Mux {
fn remove_pane_internal(&self, pane_id: PaneId) {
log::debug!("removing pane {}", pane_id);
self.palette_advisories.lock().remove_pane(pane_id);
+ crate::pane::set_frontend_cell_metrics(pane_id, None);
let mut changed = false;
if let Some(pane) = self.panes.write().remove(&pane_id).clone() {
log::debug!("killing pane {}", pane_id);
diff --git a/mux/src/pane.rs b/mux/src/pane.rs
index edf19cb2..ebf82520 100644
--- a/mux/src/pane.rs
+++ b/mux/src/pane.rs
@@ -28,6 +28,73 @@ pub fn alloc_pane_id() -> PaneId {
PANE_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)
}
+/// The cell geometry a frontend sizes this pane's PTY with.
+///
+/// The split tree thinks in root-font cells and knows nothing of per-pane
+/// font scale or per-pane chrome (the pane nav bar), while the GUI sizes
+/// PTYs through both. With two writers using different arithmetic, every
+/// split-tree resize and every GUI sync would set a *different* size on the
+/// same PTY — during a divider drag that alternates the TUI between two
+/// widths at frame rate. A GUI therefore registers, per pane, the metrics
+/// it sizes with, and `PaneStack::resize` converts the tree's pixel rect
+/// through them so both writers land on the identical size. Headless mux
+/// has no entries and keeps the raw cell behavior.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct FrontendCellMetrics {
+ pub cell_width: usize,
+ pub cell_height: usize,
+ /// Vertical chrome drawn inside the pane's rect (the pane nav bar), px.
+ pub chrome_height: usize,
+ pub dpi: u32,
+}
+
+lazy_static::lazy_static! {
+ static ref FRONTEND_CELL_METRICS: parking_lot::RwLock<HashMap<PaneId, FrontendCellMetrics>> =
+ parking_lot::RwLock::new(HashMap::new());
+}
+
+pub fn set_frontend_cell_metrics(pane_id: PaneId, metrics: Option<FrontendCellMetrics>) {
+ let mut map = FRONTEND_CELL_METRICS.write();
+ match metrics {
+ Some(m) => {
+ map.insert(pane_id, m);
+ }
+ None => {
+ map.remove(&pane_id);
+ }
+ }
+}
+
+pub fn frontend_cell_metrics(pane_id: PaneId) -> Option<FrontendCellMetrics> {
+ FRONTEND_CELL_METRICS.read().get(&pane_id).copied()
+}
+
+/// Convert a split-tree pixel rect into the size the registered frontend
+/// would compute for it. Mirrors the GUI's `terminal_size_for_positioned_pane`
+/// exactly: chrome is clamped so one terminal row always survives, and the
+/// pixel size is re-derived from whole cells.
+pub fn apply_frontend_cell_metrics(pane_id: PaneId, size: TerminalSize) -> TerminalSize {
+ let Some(m) = frontend_cell_metrics(pane_id) else {
+ return size;
+ };
+ let cell_width = m.cell_width.max(1);
+ let cell_height = m.cell_height.max(1);
+ let chrome = m
+ .chrome_height
+ .min(size.pixel_height.saturating_sub(cell_height));
+ let pixel_width = size.pixel_width.max(cell_width);
+ let pixel_height = size.pixel_height.saturating_sub(chrome).max(cell_height);
+ let cols = (pixel_width / cell_width).max(1);
+ let rows = (pixel_height / cell_height).max(1);
+ TerminalSize {
+ rows,
+ cols,
+ pixel_width: cols * cell_width,
+ pixel_height: rows * cell_height,
+ dpi: m.dpi,
+ }
+}
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PerformAssignmentResult {
/// Continue search for handler
diff --git a/mux/src/tab.rs b/mux/src/tab.rs
index cab0ddd5..03557e59 100644
--- a/mux/src/tab.rs
+++ b/mux/src/tab.rs
@@ -146,6 +146,20 @@ impl PaneStack {
if pane.is_remote_mirror() {
continue;
}
+ // Local panes get the same treatment through the frontend's
+ // registered cell metrics: convert the tree's pixel rect with
+ // the pane's own font scale and chrome so this write agrees
+ // with the GUI's, instead of fighting it (no entry = raw size).
+ let size = crate::pane::apply_frontend_cell_metrics(pane.pane_id(), size);
+ log::debug!(
+ target: "sizetrace",
+ "stack resize pane {} -> {}x{} ({}x{}px)",
+ pane.pane_id(),
+ size.cols,
+ size.rows,
+ size.pixel_width,
+ size.pixel_height,
+ );
pane.resize(size)?;
}
Ok(())
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index 5a18558f..0b62d88d 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -1959,6 +1959,22 @@ impl super::TermWindow {
let target_size = self.terminal_size_for_positioned_pane(pos, render_metrics);
let dims = pos.pane.get_dimensions();
+ // Register the metrics behind target_size so mux-side split-tree
+ // resizes (cascade during divider drags) compute this same size for
+ // the pane instead of the raw root-cell size — the two writers must
+ // agree or the PTY ping-pongs between their answers every frame.
+ if pos.pane.downcast_ref::<ClientPane>().is_none() {
+ mux::pane::set_frontend_cell_metrics(
+ pane_id,
+ Some(mux::pane::FrontendCellMetrics {
+ cell_width: render_metrics.cell_size.width.max(1) as usize,
+ cell_height: render_metrics.cell_size.height.max(1) as usize,
+ chrome_height: self.pane_nav_bar_height(),
+ dpi: self.dimensions.dpi as u32,
+ }),
+ );
+ }
+
if dims.cols != target_size.cols
|| dims.viewport_rows != target_size.rows
|| dims.pixel_width != target_size.pixel_width
@@ -1968,6 +1984,19 @@ impl super::TermWindow {
if let Some(client) = pos.pane.downcast_ref::<ClientPane>() {
client.adopt_frontend_geometry(target_size);
} else {
+ log::debug!(
+ target: "sizetrace",
+ "gui sync pane {} {}x{} -> {}x{} (scale {} pos {}x{}px nav {})",
+ pane_id,
+ dims.cols,
+ dims.viewport_rows,
+ target_size.cols,
+ target_size.rows,
+ font_scale,
+ pos.pixel_width,
+ pos.pixel_height,
+ self.pane_nav_bar_height(),
+ );
pos.pane.resize(target_size)?;
}
}