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.

wezterm-gui: keep claimable terminals visible during handoff

RoversX140aecbe65d9
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 83c5620f..5641034e 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -9727,7 +9727,7 @@ impl TermWindow {
}
}
AdjustPaneSize(direction, amount) => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
let mux = Mux::get();
@@ -9746,7 +9746,7 @@ impl TermWindow {
}
}
ActivatePaneByIndex(index) => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
let mux = Mux::get();
@@ -9766,7 +9766,7 @@ impl TermWindow {
}
}
ActivatePaneDirection(direction) => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
let mux = Mux::get();
@@ -9783,7 +9783,7 @@ impl TermWindow {
}
}
TogglePaneZoomState => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
let mux = Mux::get();
@@ -9805,7 +9805,7 @@ impl TermWindow {
self.sync_active_tab_geometry_now();
}
SetPaneZoomState(zoomed) => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
let mux = Mux::get();
@@ -9949,7 +9949,7 @@ impl TermWindow {
// NOP here; handled by the overlay directly
}
RotatePanes(direction) => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
let mux = Mux::get();
@@ -9966,7 +9966,7 @@ impl TermWindow {
self.persist_workspace_layout_after_mutation("panes rotated");
}
SplitPane(split) => {
- if self.frontend_surface_blocked() {
+ if self.frontend_layout_locked() {
return Ok(PerformAssignmentResult::Handled);
}
log::trace!("SplitPane {:?}", split);
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index 7fd9e9b3..88221371 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -1865,14 +1865,19 @@ impl super::TermWindow {
};
let takeover_gesture = matches!(event.kind, WMEK::Press(_)) || wheel_has_motion;
+ // The gesture that takes the terminal is not also terminal input:
+ // the badge asks for a click to take control, and that click stops
+ // here. Tested ahead of the blocked surface, which no longer covers
+ // a claimable terminal -- the badge leaves it in view.
+ if terminal_surface && takeover_gesture && self.frontend_takeover_claimable() {
+ self.frontend_handoff_consumed_press = matches!(event.kind, WMEK::Press(_));
+ self.claim_frontend_viewport_for_interaction();
+ context.invalidate();
+ return;
+ }
if terminal_surface && self.frontend_surface_blocked() {
- if takeover_gesture && self.frontend_takeover_claimable() {
- self.frontend_handoff_consumed_press = matches!(event.kind, WMEK::Press(_));
- self.claim_frontend_viewport_for_interaction();
- context.invalidate();
- }
- // The opaque handoff surface consumes the triggering gesture and
- // all pointer traffic while blocked; nothing leaks to the pane.
+ // The opaque handoff surface consumes all pointer traffic while
+ // blocked; nothing leaks to the pane.
return;
}
if terminal_surface && takeover_gesture {
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index 3e60233e..fa6da3de 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -683,7 +683,62 @@ impl crate::TermWindow {
Ok(true)
}
- /// In A mode a follower keeps the canonical PTY grid. If its window is
+ /// A terminal another device holds is drawn as that device sees it; the
+ /// badge in the corner says so, and that a click or a scroll takes it.
+ /// Replaces the opaque card: the picture stays, only the input is gated.
+ fn paint_frontend_takeover_badge(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ ) -> anyhow::Result<()> {
+ let gate = self.frontend_terminal_gate();
+ if !gate.is_claimable() {
+ return Ok(());
+ }
+ let Some((title, hint)) = gate.overlay_message() else {
+ return Ok(());
+ };
+ let text = format!("{title} \u{2014} {hint}");
+ let area = self.content_view_area();
+ let palette = self.chrome();
+ let font_size =
+ crate::native_settings::home_font_size(&crate::native_settings::load_shared());
+ let font = self.fonts.title_font_with_size(font_size)?;
+ let metrics = crate::utilsprites::RenderMetrics::with_font_metrics(&font.metrics());
+ let gl_state = self.render_state.as_ref().unwrap();
+ let ctx = DrawContext::new(gl_state, self.dimensions, &metrics);
+ let line_height = metrics.cell_size.height as f32;
+ let pad_x = line_height * 0.6;
+ let pad_y = line_height * 0.25;
+ let max_text = (area.size.width - pad_x * 4.0).max(0.0);
+ let text_width = ctx.measure_text_width(&font, &text).min(max_text);
+ if text_width <= 0.0 || area.size.height < line_height * 3.0 {
+ return Ok(());
+ }
+ let width = text_width + pad_x * 2.0;
+ let height = line_height + pad_y * 2.0;
+ let x = area.max_x() - width - pad_x;
+ let y = area.max_y() - height - pad_y;
+ self.filled_rectangle(
+ layers,
+ 0,
+ euclid::rect(x, y, width, height),
+ palette.window_bg.mul_alpha(0.92),
+ )
+ .context("takeover badge background")?;
+ ctx.draw_text_on_layer(
+ layers,
+ 2,
+ &font,
+ x + pad_x,
+ y + pad_y,
+ &text,
+ palette.text,
+ text_width,
+ )?;
+ Ok(())
+ }
+
+ /// A follower keeps the owner's canonical PTY grid. If its window is
/// larger, mark the renderer-only remainder with a faint cell grid rather
/// than stretching or reflowing terminal data that belongs to the owner.
fn paint_frontend_shared_unused_grid(
@@ -693,9 +748,7 @@ impl crate::TermWindow {
let Some(state) = self.active_remote_frontend_viewport_state() else {
return Ok(());
};
- if state.access.mode != codec::FrontendAccessMode::TmuxLatest
- || self.owns_frontend_viewport()
- {
+ if self.owns_frontend_viewport() {
return Ok(());
}
let area = self.content_view_area();
@@ -3887,6 +3940,8 @@ impl crate::TermWindow {
}
self.paint_frontend_shared_unused_grid(&mut layers)
.context("paint shared unused grid")?;
+ self.paint_frontend_takeover_badge(&mut layers)
+ .context("paint takeover badge")?;
}
if paint_terminal_world && !frontend_blocked {
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index f2033de0..ec0c84a4 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -286,10 +286,38 @@ impl super::TermWindow {
}
}
+ /// Whether the terminal is painted over: while connecting, syncing or
+ /// offline there is nothing worth showing. A terminal another device
+ /// holds is not blocked here: it is drawn as that device sees it, with
+ /// a badge saying a click takes it, so the picture never disappears.
pub(crate) fn frontend_surface_blocked(&self) -> bool {
+ let gate = self.frontend_terminal_gate();
+ gate.obscures_terminal() && !gate.is_claimable()
+ }
+
+ /// Whether layout changes (splits, zoom, pane moves) are this GUI's to
+ /// make: not while the surface is blocked, and not for a terminal
+ /// another device holds until it is taken.
+ pub(crate) fn frontend_layout_locked(&self) -> bool {
self.frontend_terminal_gate().obscures_terminal()
}
+ /// Whether a takeover of `tab` hides the terminal until the resized
+ /// screen has arrived. Tabs of this machine's session server were last
+ /// sized by this GUI or by nothing, so they keep showing the old
+ /// picture while the rows for the new size arrive, as a resize does.
+ /// A tab another device sized is masked: its picture would reflow
+ /// visibly from that device's shape to this one.
+ fn takeover_obscures(&self, tab: &Arc<mux::tab::Tab>) -> bool {
+ !tab
+ .get_active_pane()
+ .and_then(|pane| {
+ pane.downcast_ref::<ClientPane>()
+ .map(|client| crate::local_sessions::is_host_domain_id(client.domain_id()))
+ })
+ .unwrap_or(false)
+ }
+
pub(crate) fn frontend_takeover_claimable(&self) -> bool {
self.frontend_terminal_gate().is_claimable()
}
@@ -606,6 +634,12 @@ impl super::TermWindow {
/// panes became ready; nothing else paints an idle terminal, so the
/// overlay used to stay until the mouse moved or the shell printed.
fn arm_frontend_geometry_settle_timer(&mut self, tab_id: mux::tab::TabId, epoch: u64) {
+ // The window first: flagging the confirmation before knowing there
+ // is one to notify would latch it armed with no timer behind it,
+ // and this function refuses to arm a second time.
+ let Some(window) = self.window.as_ref().cloned() else {
+ return;
+ };
let Some(pending) = self.frontend_geometry_confirmations.get_mut(&tab_id) else {
return;
};
@@ -613,9 +647,6 @@ impl super::TermWindow {
return;
}
pending.settle_timer_armed = true;
- let Some(window) = self.window.as_ref().cloned() else {
- return;
- };
promise::spawn::spawn(async move {
smol::Timer::after(FRONTEND_GEOMETRY_SETTLE + Duration::from_millis(20)).await;
window.notify(TermWindowNotif::Apply(Box::new(move |term_window| {
@@ -1164,7 +1195,8 @@ impl super::TermWindow {
// An explicit user takeover re-arms the remote publish path too.
self.forget_rejected_local_viewport(tab_id);
- let Some(epoch) = self.begin_frontend_geometry_epoch(tab_id, true) else {
+ let obscure = self.takeover_obscures(&tab);
+ let Some(epoch) = self.begin_frontend_geometry_epoch(tab_id, obscure) else {
return;
};
let Some((domain, viewport, adopted)) = self.prepare_client_frontend_geometry(&tab) else {
@@ -1602,7 +1634,8 @@ impl super::TermWindow {
}
let takeover = action == FrontendGeometryAction::Set { takeover: true };
let claim = action == FrontendGeometryAction::Claim;
- let Some(epoch) = self.begin_frontend_geometry_epoch(tab_id, takeover) else {
+ let obscure = takeover && self.takeover_obscures(&tab);
+ let Some(epoch) = self.begin_frontend_geometry_epoch(tab_id, obscure) else {
mux::zoom_trace!("gui.sync.skip tab={tab_id} reason=epoch_denied");
return;
};