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.

Add pane-stack (level-2 tab) support over mux; fix resize/resync storm

RoversXad2cddd466d9
diff --git a/codec/src/lib.rs b/codec/src/lib.rs
index 1c00dec6..16709508 100644
--- a/codec/src/lib.rs
+++ b/codec/src/lib.rs
@@ -441,7 +441,8 @@ macro_rules! pdu {
/// The overall version of the codec.
/// This must be bumped when backwards incompatible changes
/// are made to the types and protocol.
-pub const CODEC_VERSION: usize = 46;
+/// 47: PaneStackEntry gained pane_stack_id; stack operation PDUs.
+pub const CODEC_VERSION: usize = 47;
// Defines the Pdu enum.
// Each struct has an explicit identifying number.
@@ -502,6 +503,8 @@ pdu! {
GetPaneDirection: 60,
GetPaneDirectionResponse: 61,
AdjustPaneSize: 62,
+ SpawnPaneInStack: 63,
+ ActivatePaneInStack: 64,
}
impl Pdu {
@@ -517,7 +520,9 @@ impl Pdu {
| Self::Resize(_)
| Self::SetClipboard(_)
| Self::SetPaneZoomed(_)
- | Self::SpawnV2(_) => true,
+ | Self::SpawnV2(_)
+ | Self::SpawnPaneInStack(_)
+ | Self::ActivatePaneInStack(_) => true,
_ => false,
}
}
@@ -661,6 +666,23 @@ pub struct SplitPane {
pub move_pane_id: Option<PaneId>,
}
+/// Spawn a new pane as a level-2 tab in the pane stack that contains
+/// `pane_id`. Responds with SpawnResponse describing the new pane.
+#[derive(Deserialize, Serialize, PartialEq, Debug)]
+pub struct SpawnPaneInStack {
+ pub pane_id: PaneId,
+ pub command: Option<CommandBuilder>,
+ pub command_dir: Option<String>,
+ pub domain: config::keyassignment::SpawnTabDomain,
+}
+
+/// Make `pane_id` the visible pane of the stack that contains it.
+/// Responds with UnitResponse.
+#[derive(Deserialize, Serialize, PartialEq, Debug)]
+pub struct ActivatePaneInStack {
+ pub pane_id: PaneId,
+}
+
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct MovePaneToNewTab {
pub pane_id: PaneId,
diff --git a/mux/src/domain.rs b/mux/src/domain.rs
index ccc4f366..c7c49439 100644
--- a/mux/src/domain.rs
+++ b/mux/src/domain.rs
@@ -140,6 +140,21 @@ pub trait Domain: Downcast + Send + Sync {
command_dir: Option<String>,
) -> anyhow::Result<Arc<dyn Pane>>;
+ /// Spawn a pane destined for the pane stack containing `base_pane_id`
+ /// (a level-2 tab). The default just spawns a detached pane and leaves
+ /// the stack insertion to the caller (Mux::spawn_pane_in_stack); domains
+ /// that proxy to a remote mux (ClientDomain) override this so the remote
+ /// side performs the stack insertion too.
+ async fn spawn_pane_in_stack(
+ &self,
+ _base_pane_id: PaneId,
+ size: TerminalSize,
+ command: Option<CommandBuilder>,
+ command_dir: Option<String>,
+ ) -> anyhow::Result<Arc<dyn Pane>> {
+ self.spawn_pane(size, command, command_dir).await
+ }
+
/// The mux will call this method on the domain of the pane that
/// is being moved to give the domain a chance to handle the movement.
/// If this method returns Ok(None), then the mux will handle the
diff --git a/mux/src/lib.rs b/mux/src/lib.rs
index 138b20cb..50e1e911 100644
--- a/mux/src/lib.rs
+++ b/mux/src/lib.rs
@@ -1376,7 +1376,7 @@ impl Mux {
);
let pane = domain
- .spawn_pane(size, command.clone(), cwd.clone())
+ .spawn_pane_in_stack(pane_id, size, command.clone(), cwd.clone())
.await
.with_context(|| {
format!(
@@ -1627,7 +1627,7 @@ mod tests {
#[test]
fn window_ui_surfaces_are_distinct_prune_anchors() {
let mux = Mux::new(None);
- let window = Window::new(Some("test-workspace".to_string()), None);
+ let window = Window::new(Some("test-workspace".to_string()), None, None);
let window_id = window.window_id();
mux.windows.write().insert(window_id, window);
@@ -1651,7 +1651,7 @@ mod tests {
#[test]
fn existing_window_spawn_context_allows_empty_window() {
let mux = Mux::new(None);
- let window = Window::new(Some("test-workspace".to_string()), None);
+ let window = Window::new(Some("test-workspace".to_string()), None, None);
let window_id = window.window_id();
mux.windows.write().insert(window_id, window);
diff --git a/mux/src/tab.rs b/mux/src/tab.rs
index 54c7f900..d83db473 100644
--- a/mux/src/tab.rs
+++ b/mux/src/tab.rs
@@ -20,6 +20,13 @@ pub type Cursor = bintree::Cursor<PaneStack, SplitDirectionAndSize>;
static TAB_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0);
static PANE_STACK_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0);
+
+/// Allocate a fresh local pane-stack id. Used by mux clients to mint stable
+/// local ids for stacks arriving from a remote server (whose ids live in a
+/// different id space and must not collide with locally-created stacks).
+pub fn alloc_pane_stack_id() -> PaneStackId {
+ PANE_STACK_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)
+}
pub type TabId = usize;
#[derive(Default)]
@@ -59,8 +66,22 @@ impl PaneStack {
}
fn from_panes(panes: Vec<Arc<dyn Pane>>, active: usize) -> Self {
+ Self::from_panes_with_id(panes, active, None)
+ }
+
+ /// Like `from_panes`, but reuses a previously-assigned stack id when one
+ /// is known (rebuilding a tab from a remote pane tree). Keeping the id
+ /// stable across rebuilds is what lets GUI state keyed by stack id
+ /// (collapse layouts, level-2 tab bar scroll) survive resyncs.
+ fn from_panes_with_id(
+ panes: Vec<Arc<dyn Pane>>,
+ active: usize,
+ id: Option<PaneStackId>,
+ ) -> Self {
Self {
- id: PANE_STACK_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed),
+ id: id.unwrap_or_else(|| {
+ PANE_STACK_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)
+ }),
active: active.min(panes.len().saturating_sub(1)),
panes,
}
@@ -458,6 +479,7 @@ fn pane_tree(
PaneNode::Stack(PaneStackEntry {
active: stack.active_index(),
panes: entries,
+ pane_stack_id: Some(stack.id()),
})
}
}
@@ -482,6 +504,7 @@ where
},
bintree::Tree::Leaf(entry) => {
let active_index = entry.active.min(entry.panes.len().saturating_sub(1));
+ let stack_id = entry.pane_stack_id;
let mut panes = vec![];
for pane_entry in entry.panes {
@@ -500,7 +523,11 @@ where
if panes.is_empty() {
Tree::Empty
} else {
- Tree::Leaf(PaneStack::from_panes(panes, active_index))
+ Tree::Leaf(PaneStack::from_panes_with_id(
+ panes,
+ active_index,
+ stack_id,
+ ))
}
}
}
@@ -2994,6 +3021,7 @@ impl PaneNode {
PaneNode::Leaf(e) => bintree::Tree::Leaf(PaneStackEntry {
active: 0,
panes: vec![e],
+ pane_stack_id: None,
}),
PaneNode::Stack(stack) => bintree::Tree::Leaf(stack),
}
@@ -3035,6 +3063,12 @@ impl PaneNode {
pub struct PaneStackEntry {
pub active: usize,
pub panes: Vec<PaneEntry>,
+ /// Stable identity of the stack on the side that owns it (the mux
+ /// server). Clients translate this to a stable local id so that GUI
+ /// state keyed by stack id survives resyncs. Optional for backwards
+ /// compatibility with older layout snapshots.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub pane_stack_id: Option<usize>,
}
/// This type is used directly by the codec, take care to bump
@@ -3528,6 +3562,7 @@ mod test {
left: Box::new(PaneNode::Stack(PaneStackEntry {
active: 1,
panes: vec![pane_entry(200, size, false), pane_entry(201, size, true)],
+ pane_stack_id: None,
})),
right: Box::new(PaneNode::Leaf(pane_entry(202, size, false))),
node: SplitDirectionAndSize {
@@ -3571,6 +3606,7 @@ mod test {
let root = PaneNode::Stack(PaneStackEntry {
active: 1,
panes: vec![pane_entry(200, size, true), pane_entry(201, size, false)],
+ pane_stack_id: None,
});
tab.sync_with_pane_tree(size, root, |entry| FakePane::new(entry.pane_id, entry.size));
@@ -3588,6 +3624,43 @@ mod test {
assert!(tabs[1].is_active);
}
+ #[test]
+ fn sync_with_pane_tree_keeps_stack_id_stable_across_resyncs() {
+ let size = test_size();
+ let tab = Tab::new(&size);
+
+ let make_root = || PaneNode::Stack(PaneStackEntry {
+ active: 0,
+ panes: vec![pane_entry(200, size, true), pane_entry(201, size, false)],
+ pane_stack_id: Some(7),
+ });
+
+ tab.sync_with_pane_tree(size, make_root(), |entry| {
+ FakePane::new(entry.pane_id, entry.size)
+ });
+ let first_id = tab.pane_stack_id(200).expect("stack id after first sync");
+ assert_eq!(first_id, 7, "sync honors the id carried by the entry");
+
+ // A resync with the same wire id must keep the same local id, so
+ // GUI state keyed by pane_stack_id survives.
+ tab.sync_with_pane_tree(size, make_root(), |entry| {
+ FakePane::new(entry.pane_id, entry.size)
+ });
+ let second_id = tab.pane_stack_id(200).expect("stack id after resync");
+ assert_eq!(first_id, second_id);
+
+ // Entries without an id (older snapshots) still mint fresh ids.
+ let unnamed = PaneNode::Stack(PaneStackEntry {
+ active: 0,
+ panes: vec![pane_entry(200, size, true), pane_entry(201, size, false)],
+ pane_stack_id: None,
+ });
+ tab.sync_with_pane_tree(size, unnamed, |entry| {
+ FakePane::new(entry.pane_id, entry.size)
+ });
+ assert!(tab.pane_stack_id(200).is_some());
+ }
+
fn is_send_and_sync<T: Send + Sync>() -> bool {
true
}
diff --git a/mux/src/window.rs b/mux/src/window.rs
index 141b8536..c802381a 100644
--- a/mux/src/window.rs
+++ b/mux/src/window.rs
@@ -304,7 +304,7 @@ mod tests {
#[test]
fn ui_surfaces_keep_empty_window_alive_individually() {
- let mut window = Window::new(Some("test-workspace".to_string()), None);
+ let mut window = Window::new(Some("test-workspace".to_string()), None, None);
assert!(window.is_empty());
assert!(window.add_ui_surface("remote-thread:a".to_string()));
diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs
index c84eff00..fa295c35 100644
--- a/wezterm-client/src/client.rs
+++ b/wezterm-client/src/client.rs
@@ -1344,6 +1344,8 @@ impl Client {
rpc!(list_panes, ListPanes = (), ListPanesResponse);
rpc!(spawn_v2, SpawnV2, SpawnResponse);
rpc!(split_pane, SplitPane, SpawnResponse);
+ rpc!(spawn_pane_in_stack, SpawnPaneInStack, SpawnResponse);
+ rpc!(activate_pane_in_stack, ActivatePaneInStack, UnitResponse);
rpc!(
move_pane_to_new_tab,
MovePaneToNewTab,
diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs
index 3a847d9d..89d899d4 100644
--- a/wezterm-client/src/domain.rs
+++ b/wezterm-client/src/domain.rs
@@ -25,6 +25,11 @@ pub struct ClientInner {
remote_to_local_window: Mutex<HashMap<WindowId, WindowId>>,
remote_to_local_tab: Mutex<HashMap<TabId, TabId>>,
remote_to_local_pane: Mutex<HashMap<PaneId, PaneId>>,
+ /// Remote pane-stack id -> stable local pane-stack id. Remote and local
+ /// stack ids live in different id spaces; translating (rather than
+ /// adopting) avoids collisions with locally-created stacks while keeping
+ /// each remote stack's local id stable across resyncs.
+ remote_to_local_stack: Mutex<HashMap<usize, usize>>,
pub focused_remote_pane_id: Mutex<Option<PaneId>>,
}
@@ -147,6 +152,30 @@ impl ClientInner {
pane_map.remove(&remote_pane_id);
}
+ /// Rewrite the stack ids in a remote pane tree from the server's id
+ /// space into stable local ids (allocating on first sight). Keeping the
+ /// local id stable across resyncs is what lets stack-keyed GUI state
+ /// survive `sync_with_pane_tree` rebuilds.
+ pub fn translate_remote_stack_ids(&self, node: &mut mux::tab::PaneNode) {
+ use mux::tab::PaneNode;
+ match node {
+ PaneNode::Split { left, right, .. } => {
+ self.translate_remote_stack_ids(left);
+ self.translate_remote_stack_ids(right);
+ }
+ PaneNode::Stack(entry) => {
+ if let Some(remote_id) = entry.pane_stack_id {
+ let mut map = self.remote_to_local_stack.lock().unwrap();
+ let local_id = *map
+ .entry(remote_id)
+ .or_insert_with(mux::tab::alloc_pane_stack_id);
+ entry.pane_stack_id = Some(local_id);
+ }
+ }
+ PaneNode::Leaf(_) | PaneNode::Empty => {}
+ }
+ }
+
pub fn remove_old_tab_mapping(&self, remote_tab_id: TabId) {
let mut tab_map = self.remote_to_local_tab.lock().unwrap();
let old = tab_map.remove(&remote_tab_id);
@@ -245,6 +274,7 @@ impl ClientInner {
remote_to_local_window: Mutex::new(HashMap::new()),
remote_to_local_tab: Mutex::new(HashMap::new()),
remote_to_local_pane: Mutex::new(HashMap::new()),
+ remote_to_local_stack: Mutex::new(HashMap::new()),
focused_remote_pane_id: Mutex::new(None),
}
}
@@ -537,7 +567,12 @@ impl ClientDomain {
.copied()
.collect();
- for (tabroot, tab_title) in panes.tabs.into_iter().zip(panes.tab_titles.iter()) {
+ for (mut tabroot, tab_title) in panes.tabs.into_iter().zip(panes.tab_titles.iter()) {
+ // Translate remote stack ids into stable local ids BEFORE the
+ // tree rebuild, so that GUI state keyed by pane_stack_id
+ // (collapse layouts, level-2 tab bar scroll) survives resyncs.
+ inner.translate_remote_stack_ids(&mut tabroot);
+
let root_size = match tabroot.root_size() {
Some(size) => size,
None => continue,
@@ -764,6 +799,52 @@ impl Domain for ClientDomain {
anyhow::bail!("spawn_pane not implemented for ClientDomain")
}
+ /// Level-2 tab in a remote pane's stack: ask the server to spawn the
+ /// pane and insert it into ITS stack, then mirror it locally as a
+ /// ClientPane. The caller (Mux::spawn_pane_in_stack) performs the local
+ /// stack insertion; the next resync converges both sides via the stable
+ /// translated stack id.
+ async fn spawn_pane_in_stack(
+ &self,
+ base_pane_id: PaneId,
+ _size: TerminalSize,
+ command: Option<CommandBuilder>,
+ command_dir: Option<String>,
+ ) -> anyhow::Result<Arc<dyn Pane>> {
+ let inner = self
+ .inner()
+ .ok_or_else(|| anyhow!("domain is not attached"))?;
+
+ let mux = Mux::get();
+ let local_pane = mux
+ .get_pane(base_pane_id)
+ .ok_or_else(|| anyhow!("pane_id {} is invalid", base_pane_id))?;
+ let pane = local_pane
+ .downcast_ref::<ClientPane>()
+ .ok_or_else(|| anyhow!("pane_id {} is not a ClientPane", base_pane_id))?;
+
+ let result = inner
+ .client
+ .spawn_pane_in_stack(codec::SpawnPaneInStack {
+ pane_id: pane.remote_pane_id,
+ command,
+ command_dir,
+ domain: SpawnTabDomain::CurrentPaneDomain,
+ })
+ .await?;
+
+ let pane: Arc<dyn Pane> = Arc::new(ClientPane::new(
+ &inner,
+ result.tab_id,
+ result.pane_id,
+ result.size,
+ "thinkterm",
+ ));
+ mux.add_pane(&pane)?;
+
+ Ok(pane)
+ }
+
/// Forward the request to the remote; we need to translate the local ids
/// to those that match the remote for the request, resync the changed
/// structure, and then translate the results back to local
diff --git a/wezterm-client/src/pane/clientpane.rs b/wezterm-client/src/pane/clientpane.rs
index aad21a54..7e18f823 100644
--- a/wezterm-client/src/pane/clientpane.rs
+++ b/wezterm-client/src/pane/clientpane.rs
@@ -240,6 +240,27 @@ impl ClientPane {
self.remote_pane_id
}
+ /// Ask the server to make this pane the visible (active) pane of the
+ /// stack that contains it, mirroring a local level-2 tab switch. Without
+ /// this, the next resync would flip the local stack back to the server's
+ /// stale active pane.
+ pub fn activate_in_stack_on_server(&self) {
+ let client = Arc::clone(&self.client);
+ let remote_pane_id = self.remote_pane_id;
+ promise::spawn::spawn(async move {
+ if let Err(err) = client
+ .client
+ .activate_pane_in_stack(codec::ActivatePaneInStack {
+ pane_id: remote_pane_id,
+ })
+ .await
+ {
+ log::error!("remote stack activation failed: {err:#}");
+ }
+ })
+ .detach();
+ }
+
/// Arrange to suppress the next Pane::kill call.
/// This is a bit of a hack that we use when closing a window;
/// our Domain::local_window_is_closing impl calls this for each
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index d23e1565..bd35c4cc 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -3975,8 +3975,9 @@ impl TermWindow {
};
// In a mux-domain Space the project path lives on the remote server;
- // a local folder picker is meaningless there, so prompt for the path
- // as text instead.
+ // a local folder picker is meaningless there. Offer the remote
+ // directories we actually know about (live pane cwds via OSC7 and
+ // previously-added project paths) plus free-form entry.
if let Some(domain_name) =
crate::workspace_threads::client_domain_for_space(&self.active_space_id)
{
@@ -3984,8 +3985,41 @@ impl TermWindow {
let Some(tab) = mux.get_active_tab_for_window(self.mux_window_id) else {
return;
};
- let description =
+
+ let mut candidates: Vec<String> = Vec::new();
+ if let Some(domain) = mux.get_domain_by_name(&domain_name) {
+ let domain_id = domain.domain_id();
+ for pane in mux.iter_panes() {
+ if pane.domain_id() != domain_id {
+ continue;
+ }
+ if let Some(url) = pane
+ .get_current_working_dir(mux::pane::CachePolicy::AllowStale)
+ {
+ let path = url.path().to_string();
+ if !path.is_empty() && !candidates.contains(&path) {
+ candidates.push(path);
+ }
+ }
+ }
+ }
+ for path in crate::workspace_threads::project_paths_for_space(&self.active_space_id)
+ {
+ if !candidates.contains(&path) {
+ candidates.push(path);
+ }
+ }
+
+ let mut description =
format!("Add a project on {domain_name}: enter a remote directory path");
+ if !candidates.is_empty() {
+ description.push_str("\nKnown remote directories:");
+ for (idx, path) in candidates.iter().enumerate() {
+ description.push_str(&format!("\n {}. {}", idx + 1, path));
+ }
+ description.push_str("\nType a number to pick one, or type a path.");
+ }
+
let (overlay, future) = start_overlay(self, &tab, move |_tab_id, term| {
let line = crate::overlay::prompt::read_line_prompt_overlay(
term,
@@ -3993,7 +4027,13 @@ impl TermWindow {
"path> ",
Some("~/"),
)?;
- if let Some(path) = line.map(|s| s.trim().to_string()).filter(|s| !s.is_empty()) {
+ if let Some(input) = line.map(|s| s.trim().to_string()).filter(|s| !s.is_empty())
+ {
+ let path = input
+ .parse::<usize>()
+ .ok()
+ .and_then(|n| candidates.get(n.checked_sub(1)?).cloned())
+ .unwrap_or(input);
window.notify(TermWindowNotif::OpenProjectPath(PathBuf::from(path)));
}
Ok(())
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index c3714b12..a8620e85 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -255,10 +255,7 @@ impl super::TermWindow {
return 0.0;
}
- let nav_height = self.pane_nav_bar_height_for_pane(&pos.pane, self.render_metrics);
- if nav_height == 0 {
- return 0.0;
- }
+ let nav_height = pane_nav_bar_height_for_metrics(self.render_metrics);
let icon_size = nav_height.saturating_sub(PANE_NAV_INSET * 2).clamp(20, 24);
let button_size = nav_height
.saturating_sub(TAB_VERTICAL_PADDING * 2)
@@ -438,12 +435,8 @@ impl super::TermWindow {
let x = event.coords.x as f32;
let y = event.coords.y as f32;
+ let nav_height = pane_nav_bar_height_for_metrics(self.render_metrics) as f32;
for pos in tab.iter_panes_ignoring_zoom() {
- let nav_height =
- self.pane_nav_bar_height_for_pane(&pos.pane, self.render_metrics) as f32;
- if nav_height <= 0.0 {
- continue;
- }
let content_pane_x =
padding_left + border.left.get() as f32 + pos.left as f32 * cell_width;
let pane_x = if pos.left == 0 && self.workspace_sidebar_width() > 0 {
@@ -3942,6 +3935,16 @@ impl super::TermWindow {
}
if let Err(err) = mux.activate_pane_in_stack(target_pane_id) {
log::error!("pane nav activate failed: {err:#}");
+ } else if let Some(pane) = mux.get_pane(target_pane_id) {
+ // For a remote mux pane, mirror the activation on the
+ // server so its notion of the stack's visible pane
+ // matches ours; otherwise the next resync would flip
+ // the local stack back to the server's stale value.
+ if let Some(client_pane) =
+ pane.downcast_ref::<wezterm_client::pane::ClientPane>()
+ {
+ client_pane.activate_in_stack_on_server();
+ }
}
}
PaneNavAction::Close(target_pane_id) => {
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index bcd90755..45147ff8 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -38,12 +38,14 @@ use window::color::LinearRgba;
use window::MouseEventKind as WMEK;
impl crate::TermWindow {
+ /// Draw height of the nav bar for this pane. Always the metric height:
+ /// for remote mux panes it overlays the content (no rows are stolen from
+ /// the viewport; see pane_nav_bar_height_for_pane in resize.rs).
fn pane_nav_bar_height(&self, pos: &PositionedPane) -> usize {
- self.pane_nav_bar_height_for_pane(&pos.pane, self.render_metrics)
- .min(
- pos.pixel_height
- .saturating_sub(self.render_metrics.cell_size.height.max(1) as usize),
- )
+ pane_nav_bar_height_for_metrics(self.render_metrics).min(
+ pos.pixel_height
+ .saturating_sub(self.render_metrics.cell_size.height.max(1) as usize),
+ )
}
fn pane_content_origin(&self, pos: &PositionedPane) -> anyhow::Result<(f32, f32)> {
@@ -81,8 +83,7 @@ impl crate::TermWindow {
};
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_for_pane(&pos.pane, self.render_metrics) as f32);
+ height = height.max(pane_nav_bar_height_for_metrics(self.render_metrics) as f32);
}
Ok(euclid::rect(
@@ -198,13 +199,10 @@ impl crate::TermWindow {
let strip_left = pane_rect.origin.x.max(0.0) as usize;
let strip_right = pane_rect.max_x().max(0.0) as usize;
let strip_height = pane_rect.size.height.max(1.0) as usize;
- let chrome_height = self
- .pane_nav_bar_height_for_pane(&pos.pane, self.render_metrics)
- .min(strip_height);
- if chrome_height == 0 {
- // Remote mux panes have no nav bar; don't paint one.
- return Ok(0);
- }
+ // Draw height is always the metric height: for remote mux panes the
+ // bar overlays the content (it steals no viewport rows), for local
+ // panes the viewport was already shrunk to make room.
+ let chrome_height = pane_nav_bar_height_for_metrics(self.render_metrics).min(strip_height);
let icon_size = chrome_height
.saturating_sub(PANE_NAV_INSET * 2)
.clamp(20, 24);
@@ -822,7 +820,12 @@ impl crate::TermWindow {
}
}
- Ok(nav_height)
+ // Return the CONTENT OFFSET, not the drawn height: remote mux panes
+ // steal no viewport rows (the bar overlays the content), so their
+ // cells start at the pane's top edge.
+ Ok(self
+ .pane_nav_bar_height_for_pane(&pos.pane, self.render_metrics)
+ .min(nav_height))
}
fn paint_pane_nav_icon_button(
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index bce8ac89..c29b400d 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -263,11 +263,14 @@ impl super::TermWindow {
}
}
- /// Per-pane navigation bar height. Panes that belong to a mux client
- /// domain (remote wezterm mux) get NO nav bar: the mux protocol sizes a
- /// leaf tab from its pane, so stealing nav-bar rows from a ClientPane
- /// echoes back from the server as a smaller tab and produces a feedback
- /// loop that shrinks the window a few rows per round-trip.
+ /// Rows (in pixels) the per-pane navigation bar STEALS from the pane's
+ /// terminal viewport. Panes that belong to a mux client domain (remote
+ /// wezterm mux) steal nothing: the mux protocol sizes a leaf tab from
+ /// its pane, so shrinking a ClientPane's viewport echoes back from the
+ /// server as a smaller tab and produces a feedback loop that shrinks
+ /// the window a few rows per round-trip. For those panes the nav bar is
+ /// drawn as an overlay on top of the content instead (see render/pane.rs
+ /// which uses the plain metric height for drawing).
pub(crate) fn pane_nav_bar_height_for_pane(
&self,
pane: &std::sync::Arc<dyn mux::pane::Pane>,
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 14334ecb..bdc20b6b 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -3313,6 +3313,26 @@ pub fn is_mux_domain_project_id(project_id: &str) -> bool {
remote_host_id_for_project_id(project_id).starts_with(MUX_DOMAIN_HOST_PREFIX)
}
+/// Paths of existing projects in a Space (excluding the mux domain's own
+/// `wezterm-mux://` sentinel). Used to offer previously-added remote paths
+/// as picker candidates.
+pub fn project_paths_for_space(space_id: &str) -> Vec<String> {
+ let store = THREAD_STORE.lock();
+ store
+ .projects
+ .iter()
+ .filter(|p| p.space_id == space_id)
+ .filter_map(|p| {
+ let path = p.path.to_string_lossy();
+ if path.starts_with("wezterm-mux://") {
+ None
+ } else {
+ Some(path.to_string())
+ }
+ })
+ .collect()
+}
+
/// The mux client domain a Space is dedicated to, if any. Every thread in
/// such a Space targets the remote server: new panes spawn into this domain
/// and project paths refer to the remote filesystem.
diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs
index 5c8e2957..056eaf75 100644
--- a/wezterm-mux-server-impl/src/sessionhandler.rs
+++ b/wezterm-mux-server-impl/src/sessionhandler.rs
@@ -725,6 +725,27 @@ impl SessionHandler {
.detach();
}
+ Pdu::SpawnPaneInStack(request) => {
+ let client_id = self.client_id.clone();
+ spawn_into_main_thread(async move {
+ schedule_spawn_pane_in_stack(request, send_response, client_id);
+ })
+ .detach();
+ }
+
+ Pdu::ActivatePaneInStack(request) => {
+ let client_id = self.client_id.clone();
+ spawn_into_main_thread(async move {
+ let mux = Mux::get();
+ let _identity = mux.with_identity(client_id);
+ send_response(
+ mux.activate_pane_in_stack(request.pane_id)
+ .map(|()| Pdu::UnitResponse(UnitResponse {})),
+ );
+ })
+ .detach();
+ }
+
Pdu::MovePaneToNewTab(request) => {
let client_id = self.client_id.clone();
spawn_into_main_thread(async move {
@@ -1040,6 +1061,62 @@ where
.detach();
}
+fn schedule_spawn_pane_in_stack<SND>(
+ request: SpawnPaneInStack,
+ send_response: SND,
+ client_id: Option<Arc<ClientId>>,
+) where
+ SND: Fn(anyhow::Result<Pdu>) + 'static,
+{
+ promise::spawn::spawn(async move {
+ send_response(spawn_pane_in_stack(request, client_id).await)
+ })
+ .detach();
+}
+
+async fn spawn_pane_in_stack(
+ request: SpawnPaneInStack,
+ client_id: Option<Arc<ClientId>>,
+) -> anyhow::Result<Pdu> {
+ let mux = Mux::get();
+ let _identity = mux.with_identity(client_id);
+
+ let (_pane_domain_id, window_id, tab_id) = mux
+ .resolve_pane_id(request.pane_id)
+ .ok_or_else(|| anyhow!("pane_id {} invalid", request.pane_id))?;
+
+ // The new pane joins the stack occupying the same rect as the base
+ // pane, so it inherits the base pane's current size.
+ let base = mux
+ .get_pane(request.pane_id)
+ .ok_or_else(|| anyhow!("pane_id {} invalid", request.pane_id))?;
+ let dims = base.get_dimensions();
+ let size = ::wezterm_term::TerminalSize {
+ rows: dims.viewport_rows,
+ cols: dims.cols,
+ pixel_width: dims.pixel_width,
+ pixel_height: dims.pixel_height,
+ dpi: dims.dpi,
+ };
+
+ let pane = mux
+ .spawn_pane_in_stack(
+ request.pane_id,
+ request.domain,
+ request.command,
+ request.command_dir,
+ size,
+ )
+ .await?;
+
+ Ok::<Pdu, anyhow::Error>(Pdu::SpawnResponse(SpawnResponse {
+ pane_id: pane.pane_id(),
+ tab_id,
+ window_id,
+ size,
+ }))
+}
+
async fn split_pane(split: SplitPane, client_id: Option<Arc<ClientId>>) -> anyhow::Result<Pdu> {
let mux = Mux::get();
let _identity = mux.with_identity(client_id);