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
fix(gui): let panes along the bottom take the room under the last row
RoversXf3ce93e1069a
diff --git a/mux/src/pane.rs b/mux/src/pane.rsindex a93744ec..25f33bc0 100644--- a/mux/src/pane.rs+++ b/mux/src/pane.rs@@ -67,6 +67,10 @@ pub struct FrontendCellMetrics {pub cell_height: usize,/// Vertical chrome drawn inside the pane's rect (the pane nav bar), px.pub chrome_height: usize,+ /// Room under the tree the frontend lets a pane along its bottom edge+ /// run its terminal on into, px: what is left of the window under the+ /// tree's last row. The tree knows which panes those are.+ pub extra_height: usize,pub dpi: u32,}@@ -93,9 +97,14 @@ pub fn frontend_cell_metrics(pane_id: PaneId) -> Option<FrontendCellMetrics> {/// 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 {+/// exactly: chrome is clamped so one terminal row always survives, the room+/// under the tree is added for a pane `along_bottom` of it, and the pixel+/// size is re-derived from whole cells.+pub fn apply_frontend_cell_metrics(+ pane_id: PaneId,+ size: TerminalSize,+ along_bottom: bool,+) -> TerminalSize {let Some(m) = frontend_cell_metrics(pane_id) else {return size;};@@ -105,7 +114,10 @@ pub fn apply_frontend_cell_metrics(pane_id: PaneId, size: TerminalSize) -> Termi.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 room_below = if along_bottom { m.extra_height } else { 0 };+ let pixel_height = (size.pixel_height + room_below)+ .saturating_sub(chrome)+ .max(cell_height);let cols = (pixel_width / cell_width).max(1);let rows = (pixel_height / cell_height).max(1);TerminalSize {@@ -1447,4 +1459,37 @@ mod test {_ => unreachable!(),}}++ #[test]+ fn the_room_under_a_pane_adds_up_with_its_own_remainder_to_another_row() {+ let pane_id = PaneId::MAX - 7;+ let metrics = FrontendCellMetrics {+ cell_width: 10,+ cell_height: 32,+ chrome_height: 78,+ extra_height: 0,+ dpi: 96,+ };+ let rect = TerminalSize {+ rows: 39,+ cols: 80,+ pixel_width: 800,+ pixel_height: 39 * 32,+ dpi: 96,+ };+ set_frontend_cell_metrics(pane_id, Some(metrics));+ // The nav bar takes 78 of the rect's 1248: 36 rows and 18 over.+ assert_eq!(apply_frontend_cell_metrics(pane_id, rect, true).rows, 36);+ set_frontend_cell_metrics(+ pane_id,+ Some(FrontendCellMetrics {+ extra_height: 16,+ ..metrics+ }),+ );+ // With the 16 under the tree, 37 -- for a pane along its bottom.+ assert_eq!(apply_frontend_cell_metrics(pane_id, rect, true).rows, 37);+ assert_eq!(apply_frontend_cell_metrics(pane_id, rect, false).rows, 36);+ set_frontend_cell_metrics(pane_id, None);+ }}diff --git a/mux/src/tab.rs b/mux/src/tab.rsindex 06d00428..3043fb4d 100644--- a/mux/src/tab.rs+++ b/mux/src/tab.rs@@ -152,7 +152,9 @@ impl PaneStack {self.active = self.panes.len().saturating_sub(1);}- fn resize(&self, size: TerminalSize) -> anyhow::Result<()> {+ /// `along_bottom`: whether the stack runs along the tree's bottom edge,+ /// where a frontend may let its panes take the room under the tree.+ fn resize(&self, size: TerminalSize, along_bottom: bool) -> anyhow::Result<()> {for pane in &self.panes {// Remote mirror panes are sized by the GUI layer, which// subtracts per-pane chrome (the pane nav bar) from the cell@@ -165,7 +167,7 @@ impl PaneStack {// 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);+ let size = crate::pane::apply_frontend_cell_metrics(pane.pane_id(), size, along_bottom);log::debug!(target: "sizetrace","stack resize pane {} -> {}x{} ({}x{}px)",@@ -619,32 +621,30 @@ fn adjust_y_size(tree: &mut Tree, mut y_adjust: isize, cell_dimensions: &Termina}return;}+ // The lower side first, a row each in turn: its panes run on+ // into the window's room under the tree, which a row given+ // or taken anywhere else would take from or give to them,+ // so that they would lose a row as the window grew and get+ // one back as it went on.SplitDirection::Vertical if y_adjust > 0 => {- adjust_y_size(&mut *left, 1, cell_dimensions);- data.first.rows += 1;- data.first.pixel_height =- data.first.rows.saturating_mul(cell_dimensions.pixel_height);+ adjust_y_size(&mut *right, 1, cell_dimensions);+ data.second.rows += 1;+ data.second.pixel_height = data+ .second+ .rows+ .saturating_mul(cell_dimensions.pixel_height);y_adjust -= 1;if y_adjust > 0 {- adjust_y_size(&mut *right, 1, cell_dimensions);- data.second.rows += 1;- data.second.pixel_height = data- .second- .rows- .saturating_mul(cell_dimensions.pixel_height);+ adjust_y_size(&mut *left, 1, cell_dimensions);+ data.first.rows += 1;+ data.first.pixel_height =+ data.first.rows.saturating_mul(cell_dimensions.pixel_height);y_adjust -= 1;}}SplitDirection::Vertical => {// y_adjust is negative- if data.first.rows > 1 {- adjust_y_size(&mut *left, -1, cell_dimensions);- data.first.rows -= 1;- data.first.pixel_height =- data.first.rows.saturating_mul(cell_dimensions.pixel_height);- y_adjust += 1;- }- if y_adjust < 0 && data.second.rows > 1 {+ if data.second.rows > 1 {adjust_y_size(&mut *right, -1, cell_dimensions);data.second.rows -= 1;data.second.pixel_height = data@@ -653,6 +653,13 @@ fn adjust_y_size(tree: &mut Tree, mut y_adjust: isize, cell_dimensions: &Termina.saturating_mul(cell_dimensions.pixel_height);y_adjust += 1;}+ if y_adjust < 0 && data.first.rows > 1 {+ adjust_y_size(&mut *left, -1, cell_dimensions);+ data.first.rows -= 1;+ data.first.pixel_height =+ data.first.rows.saturating_mul(cell_dimensions.pixel_height);+ y_adjust += 1;+ }}}}@@ -663,7 +670,12 @@ fn adjust_y_size(tree: &mut Tree, mut y_adjust: isize, cell_dimensions: &Termina}}-fn apply_sizes_from_splits(tree: &Tree, size: &TerminalSize) -> anyhow::Result<()> {+/// `along_bottom`: whether `tree` runs along the bottom edge of the whole.+fn apply_sizes_from_splits(+ tree: &Tree,+ size: &TerminalSize,+ along_bottom: bool,+) -> anyhow::Result<()> {match tree {Tree::Empty => return Ok(()),Tree::Node { data: None, .. } => return Ok(()),@@ -672,16 +684,27 @@ fn apply_sizes_from_splits(tree: &Tree, size: &TerminalSize) -> anyhow::Result<(right,data: Some(data),} => {- apply_sizes_from_splits(&*left, &data.first)?;- apply_sizes_from_splits(&*right, &data.second)?;+ // Of two sides stacked one over the other, the upper stops short.+ let stacked = data.direction == SplitDirection::Vertical;+ apply_sizes_from_splits(&*left, &data.first, along_bottom && !stacked)?;+ apply_sizes_from_splits(&*right, &data.second, along_bottom)?;}Tree::Leaf(stack) => {- stack.resize(*size)?;+ stack.resize(*size, along_bottom)?;}}Ok(())}+/// Whether the leaf `cursor` is at runs along the tree's bottom edge: below+/// the divider of every split above it that stacks its two sides.+fn runs_along_bottom(cursor: &Cursor) -> bool {+ cursor.path_to_root().all(|(branch, split)| match split {+ Some(split) if split.direction == SplitDirection::Vertical => branch == PathBranch::IsRight,+ _ => true,+ })+}+/// If `old` and `new` share the same split topology (node/leaf shape and/// split directions), copy old's node sizes into new and return true./// sync_with_pane_tree uses this to keep locally-held cell geometry@@ -1172,9 +1195,10 @@ impl Tab {/// Apply the new size of the tab to the panes contained within./// The delta between the current and the new size is computed,/// and is distributed between the splits. For small resizes- /// this algorithm biases towards adjusting the left/top nodes- /// first. For large resizes this tends to proportionally adjust- /// the relative sizes of the elements in a split.+ /// this algorithm biases towards adjusting the left nodes first,+ /// and the lower ones of a vertical split (see `adjust_y_size`).+ /// For large resizes this tends to proportionally adjust the+ /// relative sizes of the elements in a split.pub fn resize(&self, size: TerminalSize) -> bool {self.inner.lock().resize(size)}@@ -1660,7 +1684,7 @@ impl TabInner {// split sizes down to them and say so, the way a real resize// would, so the GUI adopts and publishes the new frames.if let Some(root) = self.pane.as_ref() {- if let Err(err) = apply_sizes_from_splits(root, &self.size) {+ if let Err(err) = apply_sizes_from_splits(root, &self.size, true) {log::error!("failed to resize panes after topology change: {err:#}");}}@@ -2015,7 +2039,9 @@ impl TabInner {Err(c) => {self.pane.replace(c.tree());let size = self.size;- if let Err(err) = apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size) {+ if let Err(err) =+ apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size, true)+ {log::error!("failed to resize panes after rotation: {err:#}");}break;@@ -2045,7 +2071,9 @@ impl TabInner {Err(c) => {self.pane.replace(c.tree());let size = self.size;- if let Err(err) = apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size) {+ if let Err(err) =+ apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size, true)+ {log::error!("failed to resize panes after rotation: {err:#}");}break;@@ -2205,6 +2233,12 @@ impl TabInner {}fn resize(&mut self, size: TerminalSize) -> bool {+ self.resize_tree(size, true)+ }++ /// `resize`, for a tree that runs along the bottom edge of the whole+ /// only if `along_bottom`: one about to have a pane put under it.+ fn resize_tree(&mut self, size: TerminalSize, along_bottom: bool) -> bool {if size.rows == 0 || size.cols == 0 {// Ignore "impossible" resize requestsreturn false;@@ -2287,7 +2321,9 @@ impl TabInner {self.size = size;// And then resize the individual panes to match- if let Err(err) = apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size) {+ if let Err(err) =+ apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size, along_bottom)+ {log::error!("failed to resize panes after split adjustment: {err:#}");}}@@ -2806,8 +2842,9 @@ impl TabInner {if cursor.is_leaf() {// Apply our size to the tty+ let along_bottom = runs_along_bottom(&cursor);if let Some(stack) = cursor.leaf_mut() {- if let Err(err) = stack.resize(pane_size) {+ if let Err(err) = stack.resize(pane_size, along_bottom) {log::error!("failed to resize pane stack: {err:#}");}}@@ -3127,8 +3164,9 @@ impl TabInner {dpi: cell_dims.dpi,};+ let along_bottom = runs_along_bottom(&cursor);if let Some(stack) = cursor.leaf_mut() {- if let Err(err) = stack.resize(size) {+ if let Err(err) = stack.resize(size, along_bottom) {log::error!("failed to resize pane stack after removal: {err:#}");}} else {@@ -3136,8 +3174,9 @@ impl TabInner {}} else if !dead_panes.is_empty() {// Apply our revised size to the tty+ let along_bottom = runs_along_bottom(&cursor);if let Some(stack) = cursor.leaf_mut() {- if let Err(err) = stack.resize(pane_size) {+ if let Err(err) = stack.resize(pane_size, along_bottom) {log::error!("failed to resize pane stack after removal: {err:#}");}}@@ -3787,7 +3826,7 @@ impl TabInner {// Advise the panes of their new sizeslet size = self.size;- if let Err(err) = apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size) {+ if let Err(err) = apply_sizes_from_splits(self.pane.as_mut().unwrap(), &size, true) {log::error!("failed to resize panes after moving active pane: {err:#}");}}@@ -3935,14 +3974,20 @@ impl TabInner {false};+ // A split that puts the new pane under the rest takes the rest+ // off the tree's bottom edge, before they are resized to make+ // room for it.+ let goes_below =+ request.direction == SplitDirection::Vertical && request.target_is_second;+if needs_resize {// Pre-emptively resize the tab contents down to// match the target size; it's easier to reuse// existing resize logic that wayif request.target_is_second {- self.resize(split_info.first.clone());+ self.resize_tree(split_info.first.clone(), !goes_below);} else {- self.resize(split_info.second.clone());+ self.resize_tree(split_info.second.clone(), true);}}@@ -3985,6 +4030,11 @@ impl TabInner {}};+ // The pane split, and so both halves when they stand side by+ // side; stacked, only the lower.+ let along_bottom = runs_along_bottom(&cursor);+ let first_along_bottom =+ along_bottom && split_info.direction != SplitDirection::Vertical;let existing_stack = cursor.leaf_mut().unwrap().clone();let new_stack = PaneStack::new(pane);@@ -3994,8 +4044,8 @@ impl TabInner {(new_stack, existing_stack)};- stack1.resize(split_info.first)?;- stack2.resize(split_info.second)?;+ stack1.resize(split_info.first, first_along_bottom)?;+ stack2.resize(split_info.second, along_bottom)?;*cursor.leaf_mut().unwrap() = stack1;diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 536c7e1a..9f286445 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -6652,6 +6652,7 @@ impl TermWindow {{self.set_window_size(size, window)?;} else if tab_size != self.terminal_size {+ self.refresh_pane_tree_slack(&tab);tab.resize(self.terminal_size);}self.stage_workspace_thread_font_scales();diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rsindex 2c8a7d27..0b8af93b 100644--- a/wezterm-gui/src/termwindow/render/pane.rs+++ b/wezterm-gui/src/termwindow/render/pane.rs@@ -493,8 +493,14 @@ impl crate::TermWindow {let (_, pane_y) = self.pane_content_origin(pos)?;let (pane_x, pane_width) = self.pane_chrome_span(pos)?;let mut height = (pos.height as f32 * self.render_metrics.cell_size.height as f32).max(1.0);- if self.collapsed_pane_layouts.contains_key(&pos.pane_stack_id) && pos.top > 0 {- height = height.max(self.pane_nav_bar_height() as f32);+ if self.collapsed_pane_layouts.contains_key(&pos.pane_stack_id) {+ if pos.top > 0 {+ height = height.max(self.pane_nav_bar_height() as f32);+ }+ } else {+ // Along the tree's bottom edge, the room under it its rows go on+ // into.+ height += self.pane_bottom_slack(pos, self.terminal_size.rows) as f32;}// The frame starts at the nav bar, lifted for panes along the top.let lift = self.pane_nav_lift(pos);diff --git a/wezterm-gui/src/termwindow/render/split.rs b/wezterm-gui/src/termwindow/render/split.rsindex 6a7e95c8..d0f9db09 100644--- a/wezterm-gui/src/termwindow/render/split.rs+++ b/wezterm-gui/src/termwindow/render/split.rs@@ -29,6 +29,13 @@ impl crate::TermWindow {let width = self.render_metrics.underline_height as f32;let mut top = pos_y - (cell_height / 2.0);let mut bottom = top + (1. + split.size as f32) * cell_height;+ // Along the tree's bottom edge the panes' rows go on into the+ // room under it (`pane_tree_slack`), past the half cell the line+ // reaches: it goes as far as they do.+ if split.top + split.size >= self.terminal_size.rows {+ let tree_bottom = pos_y + split.size as f32 * cell_height;+ bottom = bottom.max(tree_bottom + self.pane_tree_slack() as f32);+ }// Between the top panes the line reaches up beside their lifted// nav bars (see `pane_nav_lift`), straight through the terminal// bar under them; along the bottom it stops short of the bar.diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rsindex 24319950..c12abbdb 100644--- a/wezterm-gui/src/termwindow/resize.rs+++ b/wezterm-gui/src/termwindow/resize.rs@@ -1796,6 +1796,7 @@ impl super::TermWindow {}if active_pane.downcast_ref::<ClientPane>().is_none() {+ self.refresh_pane_tree_slack(&tab);tab.resize(self.terminal_size);self.reapply_collapsed_panes_for_tab(tab_id);self.force_sync_active_mux_tab_pane_sizes();@@ -2482,6 +2483,66 @@ impl super::TermWindow {})}+ /// The window's room under the pane tree that no whole row of it fills:+ /// what dividing the height between the paddings into rows left over,+ /// less than a row. Blank under the last row otherwise, it is given to+ /// the panes along the tree's bottom edge, where it adds up with what+ /// their own nav bar left of their rect to one more row as often as not.+ pub(crate) fn pane_tree_slack(&self) -> usize {+ let cell_height = self.render_metrics.cell_size.height.max(1) as usize;+ // As `resize_layout_for_dimensions` divides the window into rows.+ let v_context = DimensionContext {+ dpi: self.dimensions.dpi as f32,+ pixel_max: self.terminal_size.pixel_height as f32,+ pixel_cell: cell_height as f32,+ };+ let padding = self.config.window_padding.top.evaluate_as_pixels(v_context) as usize+ + self.config.window_padding.bottom.evaluate_as_pixels(v_context) as usize;+ let border = self.get_os_border();+ let (top, bottom) = self.pane_area_layout_insets();+ let room = self+ .dimensions+ .pixel_height+ .saturating_sub(padding + (border.top + border.bottom).get() as usize)+ .saturating_sub((top + bottom) as usize);+ room.saturating_sub(self.terminal_size.pixel_height)+ .min(cell_height - 1)+ }++ /// The room under the tree a pane may take: `pane_tree_slack` for one+ /// along the bottom edge of a tree `tree_rows` rows high, none else.+ pub(crate) fn pane_bottom_slack(&self, pos: &PositionedPane, tree_rows: usize) -> usize {+ if pos.top + pos.height >= tree_rows {+ self.pane_tree_slack()+ } else {+ 0+ }+ }++ /// Before `tab`'s tree is resized to `self.terminal_size`: bring the+ /// room under it registered for its panes up to date. The mux gives it+ /// to the ones along the bottom edge as it sizes them from the tree;+ /// left as it was, a pane would be sized one way there and another by+ /// the sync after it, every time the window's height crosses a row.+ pub(crate) fn refresh_pane_tree_slack(&self, tab: &Arc<mux::tab::Tab>) {+ let extra_height = self.pane_tree_slack();+ for positioned in tab.iter_panes_ignoring_zoom() {+ let members = self+ .positioned_panes_for_stack(tab, &positioned)+ .unwrap_or_else(|| vec![positioned]);+ for pos in members {+ let pane_id = pos.pane.pane_id();+ let Some(mut metrics) = mux::pane::frontend_cell_metrics(pane_id) else {+ continue;+ };+ if metrics.extra_height != extra_height {+ metrics.extra_height = extra_height;+ mux::pane::set_frontend_cell_metrics(pane_id, Some(metrics));+ }+ }+ }+ }+pub(crate) fn terminal_size_for_positioned_pane(&self,pos: &PositionedPane,@@ -2493,8 +2554,9 @@ impl super::TermWindow {.pane_nav_bar_height().min(pos.pixel_height.saturating_sub(cell_height));let pixel_width = pos.pixel_width.max(cell_width);- let pixel_height = pos- .pixel_height+ // Along the tree's bottom edge, the room under it too.+ let slack = self.pane_bottom_slack(pos, self.terminal_size.rows);+ let pixel_height = (pos.pixel_height + slack).saturating_sub(pane_nav_height).max(cell_height);let cols = (pixel_width / cell_width).max(1);@@ -2545,6 +2607,9 @@ impl super::TermWindow {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(),+ // For every pane: the mux knows which run along the+ // tree's bottom edge, as the tree changes too.+ extra_height: self.pane_tree_slack(),dpi: self.dimensions.dpi as u32,}),);@@ -2657,6 +2722,7 @@ impl super::TermWindow {}Some(true) => {}}+ self.refresh_pane_tree_slack(&tab);tab.resize(self.terminal_size);self.reapply_collapsed_panes_for_tab(tab.tab_id());self.force_sync_active_mux_tab_pane_sizes();@@ -2693,6 +2759,7 @@ impl super::TermWindow {tab.get_size(),self.terminal_size);+ self.refresh_pane_tree_slack(&tab);if !tab.resize(self.terminal_size) {return;}