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 hover-reveal for the collapsed workspace sidebar

RoversX2aa3eb4a2a72
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index 1251f59a..951e40f6 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -239,6 +239,8 @@ pub(crate) struct NativeChromeSettings {
/// home_font_size.
pub(crate) right_sidebar_font_size: Option<f64>,
pub(crate) workspace_sidebar_width: Option<usize>,
+ /// Hover-reveal of the collapsed left sidebar; `None` means enabled.
+ pub(crate) workspace_sidebar_hover_reveal: Option<bool>,
pub(crate) right_sidebar_width: Option<usize>,
pub(crate) right_sidebar_file_preview_width: Option<usize>,
pub(crate) right_sidebar_note_pane_width: Option<usize>,
@@ -637,6 +639,16 @@ pub(crate) fn save_workspace_sidebar_width(width: usize) -> anyhow::Result<()> {
save(&settings)
}
+/// Hover-reveal of the collapsed left sidebar. On unless explicitly turned
+/// off, so `None` reads as enabled. `load_shared` rather than `load`: this is
+/// asked once per mouse event and once per frame, and `load` deep-clones.
+pub(crate) fn workspace_sidebar_hover_reveal_enabled() -> bool {
+ load_shared()
+ .chrome
+ .workspace_sidebar_hover_reveal
+ .unwrap_or(true)
+}
+
pub(crate) fn right_sidebar_width() -> Option<usize> {
load().chrome.right_sidebar_width
}
diff --git a/wezterm-gui/src/quad.rs b/wezterm-gui/src/quad.rs
index 19e5aacc..bd916106 100644
--- a/wezterm-gui/src/quad.rs
+++ b/wezterm-gui/src/quad.rs
@@ -147,10 +147,7 @@ impl QuadPositionTransform {
let source_height = source.bottom() - source.top();
let target_width = target.width();
let target_height = target.bottom() - target.top();
- if !(source_width > 0.0
- && source_height > 0.0
- && target_width > 0.0
- && target_height > 0.0)
+ if !(source_width > 0.0 && source_height > 0.0 && target_width > 0.0 && target_height > 0.0)
{
return None;
}
@@ -158,10 +155,7 @@ impl QuadPositionTransform {
let scale_y = target_height / source_height;
let offset_x = target.left() - source.left() * scale_x;
let offset_y = target.top() - source.top() * scale_y;
- (scale_x.is_finite()
- && scale_y.is_finite()
- && offset_x.is_finite()
- && offset_y.is_finite())
+ (scale_x.is_finite() && scale_y.is_finite() && offset_x.is_finite() && offset_y.is_finite())
.then_some(Self {
scale_x,
scale_y,
@@ -170,13 +164,7 @@ impl QuadPositionTransform {
})
}
- fn map_position(
- self,
- left: f32,
- top: f32,
- right: f32,
- bottom: f32,
- ) -> (f32, f32, f32, f32) {
+ fn map_position(self, left: f32, top: f32, right: f32, bottom: f32) -> (f32, f32, f32, f32) {
(
left * self.scale_x + self.offset_x,
top * self.scale_y + self.offset_y,
@@ -190,9 +178,7 @@ impl<'a> QuadTrait for QuadImpl<'a> {
fn set_texture_discrete(&mut self, x1: f32, x2: f32, y1: f32, y2: f32) {
match self {
Self::Vert(q) => q.set_texture_discrete(x1, x2, y1, y2),
- Self::Boxed(q) | Self::TransformedBoxed(q, _) => {
- q.set_texture_discrete(x1, x2, y1, y2)
- }
+ Self::Boxed(q) | Self::TransformedBoxed(q, _) => q.set_texture_discrete(x1, x2, y1, y2),
Self::Tee(gpu, heap) => {
gpu.set_texture_discrete(x1, x2, y1, y2);
heap.set_texture_discrete(x1, x2, y1, y2);
@@ -281,8 +267,7 @@ impl<'a> QuadTrait for QuadImpl<'a> {
Self::Vert(q) => q.set_position(left, top, right, bottom),
Self::Boxed(q) => q.set_position(left, top, right, bottom),
Self::TransformedBoxed(q, transform) => {
- let (left, top, right, bottom) =
- transform.map_position(left, top, right, bottom);
+ let (left, top, right, bottom) = transform.map_position(left, top, right, bottom);
q.set_position(left, top, right, bottom);
}
Self::Tee(gpu, heap) => {
@@ -634,7 +619,6 @@ impl BoxedQuad {
}
Some(clipped)
}
-
}
fn lerp(start: f32, end: f32, amount: f32) -> f32 {
@@ -651,7 +635,7 @@ fn bilerp_color(corners: [[f32; 4]; 4], x: f32, y: f32) -> [f32; 4] {
lerp_color(top, bottom, y)
}
-#[derive(Default)]
+#[derive(Default, Clone)]
pub struct HeapQuadAllocator {
// Quads are stored inline: a cached surface with hundreds of thousands of
// quads would otherwise be that many separate 96-byte allocations, which
@@ -834,10 +818,7 @@ impl HeapQuadAllocator {
}
pub fn quad_count(&self) -> usize {
- self.layers()
- .iter()
- .map(|(_, quads)| quads.len())
- .sum()
+ self.layers().iter().map(|(_, quads)| quads.len()).sum()
}
/// Position, texture coordinates and per-corner colors are transformed
@@ -964,6 +945,39 @@ impl HeapQuadAllocator {
Ok(())
}
+ /// Replay every recorded quad into ONE sub-layer of `other`, shifted
+ /// horizontally and cropped to `clip`.
+ ///
+ /// The sub-layer a quad was recorded in decides only *when* it is drawn:
+ /// each layer's three buffers are submitted 0, 1, 2 whatever order they
+ /// were filled in (see `render/draw.rs`). A surface that has to float
+ /// over the terminal therefore cannot keep its own sub-layers -- the
+ /// terminal's glyphs live in sub-buffer 2 and would draw straight through
+ /// a panel background recorded in sub-buffer 0. Collapsing the recording
+ /// into the last sub-buffer, in recorded order, keeps the surface's own
+ /// back-to-front order and puts all of it above anything drawn earlier:
+ /// the same arrangement the context menu gets by painting its panel into
+ /// sub-layer 2 by hand.
+ pub fn apply_to_single_layer(
+ &self,
+ other: &mut TripleLayerQuadAllocator,
+ layer_num: usize,
+ offset_x: f32,
+ clip: QuadClipRect,
+ ) -> anyhow::Result<()> {
+ let started = std::time::Instant::now();
+ for (_recorded_layer, quads) in self.layers() {
+ for quad in quads {
+ let Some(clipped) = quad.translated_clipped(offset_x, 0.0, clip) else {
+ continue;
+ };
+ other.extend_with(layer_num, &clipped.to_vertices());
+ }
+ }
+ metrics::histogram!("quad_buffer_single_layer_apply").record(started.elapsed());
+ Ok(())
+ }
+
fn set_position_transform(&mut self, transform: Option<QuadPositionTransform>) {
self.position_transform = transform;
}
@@ -1207,6 +1221,56 @@ fn heap_position_transform_maps_new_and_cached_quads_in_one_pass() {
assert_eq!(heap.layer1[0].position, (50.0, 25.0, 90.0, 45.0));
}
+#[cfg(test)]
+#[test]
+fn single_layer_replay_flattens_three_sub_layers_in_recorded_order() {
+ let mut heap = HeapQuadAllocator::default();
+ {
+ let mut layers = TripleLayerQuadAllocator::Heap(&mut heap);
+ for (layer_num, x) in [(0usize, 0.0f32), (1, 100.0), (2, 200.0)] {
+ let mut quad = layers.allocate(layer_num).unwrap();
+ quad.set_position(x, 0.0, x + 50.0, 50.0);
+ }
+ }
+
+ let mut target_heap = HeapQuadAllocator::default();
+ {
+ let mut target = TripleLayerQuadAllocator::Heap(&mut target_heap);
+ let clip = QuadClipRect::from_top_left_pixels(-500.0, -500.0, 500.0, 500.0, &TEST_ORIGIN);
+ heap.apply_to_single_layer(&mut target, 2, -10.0, clip)
+ .unwrap();
+ }
+
+ assert!(target_heap.layer0.is_empty());
+ assert!(target_heap.layer1.is_empty());
+ assert_eq!(target_heap.layer2.len(), 3);
+ // Recorded order 0 -> 1 -> 2 survives as draw order, shifted by -10.
+ assert_eq!(target_heap.layer2[0].position, (-10.0, 0.0, 40.0, 50.0));
+ assert_eq!(target_heap.layer2[1].position, (90.0, 0.0, 140.0, 50.0));
+ assert_eq!(target_heap.layer2[2].position, (190.0, 0.0, 240.0, 50.0));
+}
+
+#[cfg(test)]
+#[test]
+fn single_layer_replay_drops_quads_the_shift_pushes_out_of_the_clip() {
+ let mut heap = HeapQuadAllocator::default();
+ {
+ let mut layers = TripleLayerQuadAllocator::Heap(&mut heap);
+ let mut quad = layers.allocate(0).unwrap();
+ quad.set_position(0.0, 0.0, 50.0, 50.0);
+ }
+
+ let mut target_heap = HeapQuadAllocator::default();
+ {
+ let mut target = TripleLayerQuadAllocator::Heap(&mut target_heap);
+ let clip = QuadClipRect::from_top_left_pixels(0.0, 0.0, 500.0, 500.0, &TEST_ORIGIN);
+ // Shifted fully left of the clip: nothing lands.
+ heap.apply_to_single_layer(&mut target, 2, -100.0, clip)
+ .unwrap();
+ }
+ assert_eq!(target_heap.quad_count(), 0);
+}
+
#[cfg(test)]
#[test]
fn boxed_quad_clip_rejects_outside_and_preserves_inside() {
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 8b112596..9f2016d6 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -164,6 +164,7 @@ pub(crate) mod remote_walk;
pub mod render;
pub mod resize;
mod selection;
+mod sidebar_hover;
mod space_swipe;
pub mod spawn;
pub mod ssh_hosts_view;
@@ -1450,6 +1451,11 @@ pub struct TermWindow {
/// epoch reaches the normal local render-surface confirmation point.
frontend_recovery_geometry: HashMap<TabId, FrontendRecoveryGeometry>,
frontend_geometry_resync_after_epoch: HashSet<TabId>,
+ /// The last locally-published viewport the mux rejected, per tab. Blocks
+ /// republishing an identical viewport against an identical tab shape,
+ /// which would otherwise loop: reject → lease revoked → notification →
+ /// republish → reject. See `resize::RejectedLocalViewport`.
+ rejected_local_viewports: HashMap<TabId, resize::RejectedLocalViewport>,
/// Latest-only full-viewport streams for native divider drags. A stream
/// owns the matching ClientPane preview epoch until its final target is
/// confirmed or explicitly rolled back.
@@ -1502,7 +1508,8 @@ pub struct TermWindow {
/// dropped for cards that stop asking for a preview, and invalidated
/// wholesale when the glyph atlas is repacked -- the quads hold atlas
/// coordinates.
- preview_quad_cache: RefCell<HashMap<TabId, crate::termwindow::render::paint::CachedPreviewQuads>>,
+ preview_quad_cache:
+ RefCell<HashMap<TabId, crate::termwindow::render::paint::CachedPreviewQuads>>,
/// The one card rebuild currently sliced across frames, if any.
preview_rebuild_partial:
RefCell<Option<crate::termwindow::render::paint::PreviewRebuildPartial>>,
@@ -1656,6 +1663,15 @@ pub struct TermWindow {
/// no other; a paint that bailed out before the list leaves it `None`.
workspace_sidebar_list_quads: Option<(HeapQuadMark, HeapQuadMark)>,
workspace_sidebar_scrollbar_visible_until: Option<Instant>,
+ /// Presentation-only hover reveal of the collapsed sidebar. This never
+ /// touches `workspace_sidebar_collapsed` or `workspace_sidebar_width`:
+ /// the terminal must not reflow for a hover.
+ workspace_sidebar_hover: sidebar_hover::SidebarHoverReveal,
+ /// A native (AppKit) context menu is open. The fallback menu tracks
+ /// itself in `context_menu`; the native path otherwise leaves no trace,
+ /// and the hover machine must not retreat the panel a menu is anchored
+ /// to.
+ native_context_menu_open: bool,
/// Last notification state painted by this GUI window. Comparing identities
/// and statuses (rather than just the count) lets the bell pulse when one
/// notification replaces another without changing the total.
@@ -2163,6 +2179,7 @@ impl TermWindow {
if self.focused.is_none() {
self.workspace_sidebar_swipe.cancel_immediately();
+ self.workspace_sidebar_hover.cancel_immediately();
self.clear_workspace_space_swipe_frame_transition();
self.right_sidebar_note.native_text_input_snapshot_key = None;
window.set_native_text_input_snapshot(None);
@@ -2404,6 +2421,7 @@ impl TermWindow {
frontend_geometry_confirmations: HashMap::new(),
frontend_recovery_geometry: HashMap::new(),
frontend_geometry_resync_after_epoch: HashSet::new(),
+ rejected_local_viewports: HashMap::new(),
remote_divider_resize_streams: HashMap::new(),
next_frontend_geometry_epoch: 1,
frontend_viewport_report_pending: Arc::new(AtomicBool::new(false)),
@@ -2576,6 +2594,8 @@ impl TermWindow {
workspace_space_swipe_pending_commit: None,
workspace_space_swipe_needs_settle_start: false,
workspace_sidebar_scrollbar_visible_until: None,
+ workspace_sidebar_hover: sidebar_hover::SidebarHoverReveal::default(),
+ native_context_menu_open: false,
workspace_notification_snapshot: None,
workspace_notification_pulse_started_at: None,
right_sidebar_width: ui::right_sidebar_width_for_metrics(&render_metrics, dpi as usize),
@@ -2891,6 +2911,9 @@ impl TermWindow {
Ok(true)
}
WindowEvent::PerformKeyAssignment(action) => {
+ // A native context menu delivers its selection this way;
+ // whichever way the menu ended, it is over now.
+ self.native_context_menu_open = false;
if let Some(pane) = self.get_active_pane_or_overlay() {
self.perform_key_assignment(&pane, &action)?;
window.invalidate();
@@ -2898,11 +2921,13 @@ impl TermWindow {
Ok(true)
}
WindowEvent::PerformContextMenuAction(action_id) => {
+ self.native_context_menu_open = false;
self.perform_context_menu_application_action(action_id);
window.invalidate();
Ok(true)
}
WindowEvent::ContextMenuDismissed => {
+ self.native_context_menu_open = false;
self.context_menu_was_dismissed();
window.invalidate();
Ok(true)
@@ -2941,6 +2966,10 @@ impl TermWindow {
self.workspace_sidebar_swipe.cancel_immediately();
self.clear_workspace_space_swipe_frame_transition();
}
+ // Land a travelling hover reveal rather than deleting it: a
+ // settled overlay survives a resize cleanly, a mid-flight one
+ // would jump.
+ self.workspace_sidebar_hover.settle_immediately();
self.resize(dimensions, window_state, window, live_resizing);
Ok(true)
}
@@ -4831,7 +4860,9 @@ impl TermWindow {
fn begin_content_view_fade_to(&mut self, closing: bool, destination: Option<RectF>) {
let now = Instant::now();
- let ghost = closing.then(|| self.content_view_last_frame.take()).flatten();
+ let ghost = closing
+ .then(|| self.content_view_last_frame.take())
+ .flatten();
if closing && ghost.is_none() {
// Nothing was ever composited for this view -- it opened and
// closed inside a single frame. There is no picture to take away.
@@ -4880,7 +4911,11 @@ impl TermWindow {
now,
chrome_from,
to,
- if closing { CHROME_RETURN_DELAY } else { Duration::ZERO },
+ if closing {
+ CHROME_RETURN_DELAY
+ } else {
+ Duration::ZERO
+ },
CONTENT_VIEW_CHROME_TRAVEL.mul_f32(span(chrome_from)),
crate::ui::anim::Easing::OutCubic,
),
@@ -5070,9 +5105,7 @@ impl TermWindow {
// by whatever share the padding held, non-uniformly, because the
// card it landed in had never accounted for it.
let content = self.terminal_content_rect();
- let host_preview_aspect = if content.size.height > 0.0
- && content.size.width > 0.0
- {
+ let host_preview_aspect = if content.size.height > 0.0 && content.size.width > 0.0 {
content.size.width / content.size.height
} else if self.terminal_size.pixel_height > 0 {
self.terminal_size.pixel_width as f32 / self.terminal_size.pixel_height as f32
@@ -7417,9 +7450,7 @@ impl TermWindow {
// call -- it returns None when it cannot.
!pos.is_active
&& pos.width <= threshold
- && !self
- .collapsed_pane_layouts
- .contains_key(&pos.pane_stack_id)
+ && !self.collapsed_pane_layouts.contains_key(&pos.pane_stack_id)
})
.map(|pos| pos.index)
.collect();
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index e2c5ce56..5947ae60 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -789,6 +789,89 @@ impl super::TermWindow {
}
}
+ /// Feed the pointer to the hover-reveal machine. Called for every
+ /// pointer event, before any dispatch, and never consumes one.
+ fn update_workspace_sidebar_hover(&mut self, context: &dyn WindowOps) {
+ let input = self.workspace_sidebar_hover_input();
+ if self
+ .workspace_sidebar_hover
+ .step(input, std::time::Instant::now())
+ != crate::termwindow::sidebar_hover::HoverFrame::None
+ {
+ // Deadlines are registered by the paint pass, not here:
+ // `update_next_frame_time` writes into `has_animation`, which
+ // `paint_impl` clears on entry. Asking for a frame is enough --
+ // that frame's advance registers the wakeup.
+ context.invalidate();
+ }
+ }
+
+ pub(crate) fn workspace_sidebar_hover_input(
+ &self,
+ ) -> crate::termwindow::sidebar_hover::HoverInput {
+ use crate::termwindow::sidebar_hover::{HoverInput, PointerZone};
+ let eligible = crate::native_settings::workspace_sidebar_hover_reveal_enabled()
+ && self.workspace_sidebar_collapsed
+ && !self.content_view_foreground()
+ && !self.content_view_transition_running()
+ && !self.frontend_surface_blocked()
+ && self.modal.borrow().is_none()
+ && self.context_menu.is_none()
+ && !self.native_context_menu_open
+ && self.inline_tab_rename.is_none();
+ // Panel is checked before the hot zone on purpose: once revealed,
+ // the strip is inside the panel.
+ let pointer = match &self.current_mouse_event {
+ None => PointerZone::Away,
+ Some(event) => {
+ let x = event.coords.x;
+ let y = event.coords.y;
+ let in_panel = self.workspace_sidebar_rect().is_some_and(|rect| {
+ x >= rect.x as isize
+ && x < rect.x.saturating_add(rect.width) as isize
+ && y >= rect.y as isize
+ && y < rect.y.saturating_add(rect.height) as isize
+ });
+ let zone = self
+ .workspace_sidebar_hover_hot_zone()
+ .and_then(|(zx, zy, zw, zh)| {
+ if y < zy as isize || y >= zy.saturating_add(zh) as isize || x < zx as isize
+ {
+ return None;
+ }
+ if x < zx.saturating_add(zw) as isize {
+ return Some(PointerZone::HotZone);
+ }
+ // The sticky band shares the strip's vertical extent
+ // and only widens it: close enough to keep a running
+ // dwell alive, not close enough to start one.
+ let sticky = self
+ .ui_px(crate::termwindow::ui::tokens::SIDEBAR_HOVER_STICKY_ZONE_WIDTH);
+ (x < zx.saturating_add(sticky) as isize).then_some(PointerZone::NearHotZone)
+ });
+ if in_panel {
+ PointerZone::Panel
+ } else {
+ zone.unwrap_or(PointerZone::Away)
+ }
+ }
+ };
+ let pinned = !self.current_mouse_buttons.is_empty()
+ || self.current_mouse_capture.is_some()
+ || self.dragging.is_some()
+ || self.sidebar_row_drag.is_some()
+ || self.right_sidebar_file_drag.is_some()
+ || self.pane_tab_drag.is_some()
+ // A Space swipe on the revealed panel pins it open: retreating
+ // mid-gesture would slide the ground out from under the pages.
+ || self.workspace_sidebar_swipe.is_active();
+ HoverInput {
+ eligible,
+ pointer,
+ pinned,
+ }
+ }
+
fn mouse_wheel_workspace_sidebar(
&mut self,
event: &MouseEvent,
@@ -891,8 +974,14 @@ impl super::TermWindow {
return None;
}
+ // Docked, or hover-revealed and fully arrived: a panel still sliding
+ // out must not host a second animation.
+ let panel_ready_for_swipe = !self.workspace_sidebar_collapsed
+ || self
+ .workspace_sidebar_hover
+ .is_fully_presented(Instant::now());
let can_begin_without_space_lookup = inside_sidebar
- && !self.workspace_sidebar_collapsed
+ && panel_ready_for_swipe
&& self.context_menu.is_none()
&& self.modal.borrow().is_none()
&& self.inline_tab_rename.is_none()
@@ -993,7 +1082,7 @@ impl super::TermWindow {
now: Instant,
context: &dyn WindowOps,
) -> bool {
- let width = self.workspace_sidebar_width() as f32;
+ let width = self.workspace_sidebar_presented_width() as f32;
let finish = self.workspace_sidebar_swipe.finish(now, width);
match finish {
SidebarSpaceSwipeFinish::Switch(target) => {
@@ -1052,7 +1141,7 @@ impl super::TermWindow {
let Some((target, direction)) = self.workspace_space_swipe_pending_commit.take() else {
return;
};
- let width = self.workspace_sidebar_width() as f32;
+ let width = self.workspace_sidebar_presented_width() as f32;
let now = Instant::now();
let source_is_current = self
.workspace_sidebar_swipe
@@ -1594,6 +1683,7 @@ impl super::TermWindow {
}
self.current_mouse_event.replace(event.clone());
+ self.update_workspace_sidebar_hover(context);
if self.consume_context_menu_suppressed_release(&event) {
self.release_pointer_ownership(&event);
@@ -2031,6 +2121,8 @@ impl super::TermWindow {
&& event.coords.y as usize <= self.dimensions.pixel_height
});
self.current_mouse_event = None;
+ // The machine reads `Away` now: cancels an Arming, starts a grace.
+ self.update_workspace_sidebar_hover(context);
self.update_title();
if !preserve_cursor {
context.set_cursor(Some(MouseCursor::Arrow));
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index 1072a380..a79803ed 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -1,7 +1,9 @@
-use crate::quad::{HeapQuadAllocator, QuadClipRect, QuadTrait, TripleLayerQuadAllocator};
+use crate::quad::{
+ HeapQuadAllocator, HeapQuadMark, QuadClipRect, QuadTrait, TripleLayerQuadAllocator,
+};
use crate::termwindow::content_view::{ContentViewTypography, TerminalPreviewRequest};
use crate::termwindow::render::{LineToEleShapeCacheKey, RenderScreenLineParams};
-use crate::termwindow::{RenderFrame, TermWindowNotif};
+use crate::termwindow::{RenderFrame, TermWindowNotif, UIItem, UIItemType};
use crate::ui::{DrawContext, UiPalette};
use ::window::bitmaps::atlas::OutOfTextureSpace;
use ::window::color::LinearRgba;
@@ -17,10 +19,10 @@ use std::hash::{Hash, Hasher};
use std::rc::Rc;
use std::sync::Arc;
use std::time::{Duration, Instant};
-use window::Dimensions;
use wezterm_font::ClearShapeCache;
use wezterm_term::color::ColorAttribute;
use wezterm_term::TerminalSize;
+use window::Dimensions;
const TERMINAL_PREVIEW_EXTENT_BUCKET_DESIGN_PX: f32 = 8.0;
/// Coarse on purpose: every distinct bucket becomes a `FontConfiguration`
@@ -432,7 +434,8 @@ impl crate::TermWindow {
self.filled_rectangle(layers, 0, area, palette.window_bg)
.context("frontend handoff opaque background")?;
- let font_size = crate::native_settings::home_font_size(&crate::native_settings::load_shared());
+ let font_size =
+ crate::native_settings::home_font_size(&crate::native_settings::load_shared());
let title_font = self.fonts.title_font_with_size(font_size + 2.0)?;
let hint_font = self.fonts.title_font_with_size(font_size)?;
let metrics = crate::utilsprites::RenderMetrics::with_font_metrics(&title_font.metrics());
@@ -797,8 +800,12 @@ impl crate::TermWindow {
// the animation, which then only advances when some terminal happens
// to emit output. Measured: 150-210ms between transition frames, with
// the main thread idle the whole time.
- let owes_frames_regardless_of_focus =
- self.content_view_fade.is_some() || self.active_content_view_index().is_some();
+ let owes_frames_regardless_of_focus = self.content_view_fade.is_some()
+ || self.active_content_view_index().is_some()
+ // A dwell or grace deadline registered while the window is
+ // unfocused would otherwise be dropped, stranding a half-slid
+ // panel until some terminal happens to emit output.
+ || self.workspace_sidebar_hover.needs_frames();
if self.focused.is_some() || owes_frames_regardless_of_focus {
if let Some(next_due) = *self.has_animation.borrow() {
// "The next frame the display will give me" is the common
@@ -1314,9 +1321,10 @@ impl crate::TermWindow {
}
};
- let defer_preview_captures = self.content_view_fade.as_ref().is_some_and(|fade| {
- fade.flight.is_none()
- });
+ let defer_preview_captures = self
+ .content_view_fade
+ .as_ref()
+ .is_some_and(|fade| fade.flight.is_none());
let (next_frame, previews) = {
let gl_state = self.render_state.as_ref().unwrap();
let ctx = DrawContext::new(gl_state, dimensions, &render_metrics);
@@ -1600,9 +1608,7 @@ impl crate::TermWindow {
// texture for each one would churn.
let wanted_w = (preview.area.size.width.ceil() as u32).max(1);
let wanted_h = (preview.area.size.height.ceil() as u32).max(1);
- let tex = match prior_texture
- .filter(|t| t.width == wanted_w && t.height == wanted_h)
- {
+ let tex = match prior_texture.filter(|t| t.width == wanted_w && t.height == wanted_h) {
Some(prior) => Ok(prior),
None => self.create_card_texture(preview.area),
};
@@ -1614,12 +1620,14 @@ impl crate::TermWindow {
heap.extract_vertices(&mut frame_verts);
(base, (frame_verts.len() - base) / 4)
};
- self.pending_card_renders.borrow_mut().push(PendingCardRender {
- texture: Rc::clone(&tex),
- first_vertex,
- quad_count,
- area: preview.area,
- });
+ self.pending_card_renders
+ .borrow_mut()
+ .push(PendingCardRender {
+ texture: Rc::clone(&tex),
+ first_vertex,
+ quad_count,
+ area: preview.area,
+ });
self.card_composites.borrow_mut().push(CardComposite {
texture: Rc::clone(&tex),
dest: preview.area,
@@ -1708,12 +1716,14 @@ impl crate::TermWindow {
cached.texture = Some(Rc::clone(&texture));
(base, (frame_verts.len() - base) / 4)
};
- self.pending_card_renders.borrow_mut().push(PendingCardRender {
- texture,
- first_vertex,
- quad_count,
- area: recorded_area,
- });
+ self.pending_card_renders
+ .borrow_mut()
+ .push(PendingCardRender {
+ texture,
+ first_vertex,
+ quad_count,
+ area: recorded_area,
+ });
}
let Some(texture) = self
.preview_quad_cache
@@ -1770,7 +1780,8 @@ impl crate::TermWindow {
let maximum_scale = (global_scale * 0.84).max(minimum_scale);
let desired_scale = (global_scale * f64::from(width_ratio.min(height_ratio)))
.clamp(minimum_scale, maximum_scale);
- let mut quantized_scale = quantize_terminal_preview_scale_down(desired_scale, minimum_scale);
+ let mut quantized_scale =
+ quantize_terminal_preview_scale_down(desired_scale, minimum_scale);
// Mid-drag, keep the scale this grid was last drawn at. The search
// in the render path would otherwise walk a new bucket every few
// pixels of card width, and every bucket is a `FontConfiguration`.
@@ -2083,8 +2094,7 @@ impl crate::TermWindow {
// macro meant the transform was never applied in the build users
// run -- panes were drawn at their authored size and whatever did
// not fit was clipped away.
- let transformed =
- layers.set_heap_position_transform(Some((source_rect, target_rect)));
+ let transformed = layers.set_heap_position_transform(Some((source_rect, target_rect)));
debug_assert!(transformed);
// In the same pane-relative space as `source_rect`.
let source_visible_top =
@@ -2642,6 +2652,274 @@ impl crate::TermWindow {
Ok(())
}
+ /// Step the hover-reveal machine from the frame loop, so a motionless
+ /// pointer still reveals at dwell expiry and a departed one still
+ /// retreats at grace expiry.
+ fn advance_workspace_sidebar_hover(&mut self, now: Instant) {
+ let input = self.workspace_sidebar_hover_input();
+ match self.workspace_sidebar_hover.step(input, now) {
+ crate::termwindow::sidebar_hover::HoverFrame::None => {}
+ // Unnamed interval, as with the Space swipe below: the backend
+ // paces repaints to min(max_fps, this display's rate).
+ crate::termwindow::sidebar_hover::HoverFrame::Now => {
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ }
+ // One wakeup at the deadline, as the sidebar scrollbar does.
+ crate::termwindow::sidebar_hover::HoverFrame::At(due) => {
+ self.update_next_frame_time(Some(due));
+ }
+ }
+ }
+
+ /// Record the hover-revealed sidebar off-screen, holding back its hit
+ /// targets until after the tab bar has laid out its own.
+ ///
+ /// Returns the recording, how far the panel still has to travel
+ /// (0 = arrived) and the items to register once it is safe to.
+ fn record_workspace_sidebar_hover_overlay(
+ &mut self,
+ now: Instant,
+ ) -> anyhow::Result<Option<(HeapQuadAllocator, f32, Vec<UIItem>)>> {
+ if !self.workspace_sidebar_collapsed {
+ return Ok(None);
+ }
+ let Some(progress) = self.workspace_sidebar_hover.progress(now) else {
+ return Ok(None);
+ };
+ let ui_items_before = self.ui_items.len();
+ let mut sidebar_frame = HeapQuadAllocator::default();
+ let result = {
+ let mut sidebar_layers = TripleLayerQuadAllocator::Heap(&mut sidebar_frame);
+ self.paint_workspace_sidebar(&mut sidebar_layers)
+ };
+ // The marks describe `sidebar_frame`, which the swipe composite below
+ // may still split; nobody downstream of this fn may.
+ let live_list = self.workspace_sidebar_list_quads;
+ self.workspace_sidebar_list_quads = None;
+ result.context("record hover-revealed workspace sidebar")?;
+ let mut items: Vec<UIItem> = self.ui_items.drain(ui_items_before..).collect();
+ if !self.workspace_sidebar_hover.is_fully_presented(now) {
+ // While the panel is moving, no target inside it is where the
+ // user thinks it is. One inert item (its handler only sets the
+ // arrow cursor) keeps the revealed strip from handing clicks to
+ // the terminal underneath, and keeps the row-drag target lookup's
+ // x-extent truthful.
+ items.clear();
+ if let Some(rect) = self.workspace_sidebar_rect() {
+ let revealed = (rect.width as f32 * progress).round() as usize;
+ if revealed > 0 {
+ items.push(UIItem {
+ x: rect.x,
+ y: 0,
+ width: revealed,
+ height: rect.y + rect.height,
+ item_type: UIItemType::WorkspaceSidebarBackground,
+ });
+ }
+ }
+ }
+ let quads = self
+ .composite_space_swipe_into_hover_overlay(sidebar_frame, live_list, now)
+ .context("composite space swipe into hover overlay")?;
+ Ok(Some((quads, 1.0 - progress, items)))
+ }
+
+ /// While a Space swipe runs on the hover-revealed panel, its page slide
+ /// has to happen inside the recording: the overlay replaces the live
+ /// sidebar paint entirely, so this mirrors the docked compositing branch
+ /// of `paint_pass`, writing into a heap instead of the GPU stream. When
+ /// no swipe is in flight the recording passes through untouched.
+ fn composite_space_swipe_into_hover_overlay(
+ &mut self,
+ sidebar_frame: HeapQuadAllocator,
+ live_list: Option<(HeapQuadMark, HeapQuadMark)>,
+ now: Instant,
+ ) -> anyhow::Result<HeapQuadAllocator> {
+ let render_space_push = self.workspace_space_swipe_push_active
+ && self.workspace_space_swipe_source_frame.is_some();
+ let render_space_track = !render_space_push
+ && !self.workspace_space_swipe_push_active
+ && self.workspace_space_swipe_target_frame.is_some();
+ let capture_space_source =
+ self.workspace_space_swipe_capture_source && !render_space_push && !render_space_track;
+
+ if capture_space_source {
+ // MayBegin captured the panel at rest: keep a copy as the
+ // outgoing page and present the original untouched.
+ self.workspace_space_swipe_source_frame = Some(crate::termwindow::CapturedSidebar {
+ quads: sidebar_frame.clone(),
+ list: live_list,
+ });
+ self.workspace_space_swipe_capture_source = false;
+ #[cfg(target_os = "macos")]
+ if self.workspace_space_swipe_pending_commit.is_some() {
+ if let Some(window) = self.window.clone() {
+ window.notify(TermWindowNotif::Apply(Box::new(|term_window| {
+ term_window.complete_workspace_space_swipe_switch();
+ })));
+ }
+ }
+ return Ok(sidebar_frame);
+ }
+ if !(render_space_push || render_space_track) {
+ return Ok(sidebar_frame);
+ }
+
+ if self.workspace_space_swipe_needs_settle_start {
+ let gesture_extent = self.workspace_sidebar_presented_width() as f32;
+ let opening = if self.workspace_space_swipe_tracked {
+ crate::termwindow::space_swipe::SettleOpening::WhereTheFingerLeftIt
+ } else {
+ crate::termwindow::space_swipe::SettleOpening::AtRest
+ };
+ self.workspace_sidebar_swipe.resolve_switch(
+ true,
+ Instant::now(),
+ gesture_extent,
+ opening,
+ );
+ self.workspace_space_swipe_needs_settle_start = false;
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ }
+
+ let mut composite = HeapQuadAllocator::default();
+ let mut composited_tracking_frame = false;
+ {
+ let mut composite_layers = TripleLayerQuadAllocator::Heap(&mut composite);
+ if let Some(rect) = self.workspace_sidebar_rect() {
+ // Same rebase and page arithmetic as the docked branch; see
+ // the comments there.
+ let sidebar_clip = crate::quad::QuadClipRect::from_top_left_pixels(
+ rect.x as f32,
+ rect.y as f32,
+ rect.x.saturating_add(rect.width) as f32,
+ rect.y.saturating_add(rect.height) as f32,
+ &self.dimensions,
+ );
+ let page_right = (sidebar_clip.right() - 1.0).max(sidebar_clip.left());
+ let page_width = page_right - sidebar_clip.left();
+ let page_clip = sidebar_clip.with_horizontal(sidebar_clip.left(), page_right);
+ let offsets = self
+ .workspace_space_swipe_push_offsets(now, page_width)
+ .filter(|_| page_width > 0.0);
+ let offscreen = if render_space_push {
+ self.workspace_space_swipe_source_frame.as_ref()
+ } else {
+ self.workspace_space_swipe_target_frame
+ .as_ref()
+ .map(|(_, captured)| captured)
+ };
+ let offscreen_span = offscreen.and_then(|captured| captured.list);
+
+ match (offsets, live_list, offscreen_span) {
+ (Some((source_offset, target_offset)), Some(live), Some(other)) => {
+ let (live_offset, offscreen_offset) = if render_space_push {
+ (target_offset, source_offset)
+ } else {
+ (source_offset, target_offset)
+ };
+ sidebar_frame
+ .apply_before(&mut composite_layers, &live.0)
+ .context("hover swipe sidebar chrome above the list")?;
+ if let Some(captured) = offscreen {
+ captured
+ .quads
+ .apply_between(
+ &mut composite_layers,
+ &other.0,
+ &other.1,
+ offscreen_offset,
+ page_clip,
+ )
+ .context("hover swipe offscreen sidebar page")?;
+ }
+ sidebar_frame
+ .apply_between(
+ &mut composite_layers,
+ &live.0,
+ &live.1,
+ live_offset,
+ page_clip,
+ )
+ .context("hover swipe live sidebar page")?;
+ sidebar_frame
+ .apply_after(&mut composite_layers, &live.1)
+ .context("hover swipe sidebar chrome below the list")?;
+ composited_tracking_frame = render_space_track;
+ }
+ _ => {
+ sidebar_frame
+ .apply_to(&mut composite_layers)
+ .context("hover swipe sidebar fallback")?;
+ }
+ }
+ } else {
+ sidebar_frame
+ .apply_to(&mut composite_layers)
+ .context("hover swipe sidebar without viewport")?;
+ }
+ }
+ self.workspace_space_swipe_tracked |= composited_tracking_frame;
+
+ // The finger lifted on a committing gesture while the pages were
+ // already tracking it: keep this paint as the outgoing page (see the
+ // docked branch for the full story).
+ if render_space_track && self.workspace_space_swipe_capture_source {
+ self.workspace_space_swipe_source_frame = Some(crate::termwindow::CapturedSidebar {
+ quads: sidebar_frame,
+ list: live_list,
+ });
+ self.workspace_space_swipe_capture_source = false;
+ #[cfg(target_os = "macos")]
+ if self.workspace_space_swipe_pending_commit.is_some() {
+ if let Some(window) = self.window.clone() {
+ window.notify(TermWindowNotif::Apply(Box::new(|term_window| {
+ term_window.complete_workspace_space_swipe_switch();
+ })));
+ }
+ }
+ }
+ Ok(composite)
+ }
+
+ /// Slide the recorded panel in from the left edge, above everything
+ /// already drawn.
+ ///
+ /// Flattened into the last sub-layer rather than replayed layer for
+ /// layer: see `HeapQuadAllocator::apply_to_single_layer`. Anything
+ /// painted after this -- window borders, the modal, the context menu,
+ /// the drag overlays -- still lands on top, which is why this needs no
+ /// z-index of its own.
+ fn paint_workspace_sidebar_hover_overlay(
+ &self,
+ overlay: &HeapQuadAllocator,
+ hidden: f32,
+ ) -> anyhow::Result<()> {
+ let Some(rect) = self.workspace_sidebar_rect() else {
+ return Ok(());
+ };
+ let gl_state = self.render_state.as_ref().unwrap();
+ let layer = gl_state
+ .layer_for_zindex(0)
+ .context("hover sidebar layer")?;
+ let mut layers = layer.quad_allocator();
+ let offset_x = -(hidden * rect.width as f32);
+ // Containment only: the panel travels left and the window crops the
+ // overhang.
+ let clip = crate::quad::QuadClipRect::from_top_left_pixels(
+ 0.0,
+ 0.0,
+ self.dimensions.pixel_width as f32,
+ self.dimensions.pixel_height as f32,
+ &self.dimensions,
+ );
+ overlay.apply_to_single_layer(&mut layers, 2, offset_x, clip)
+ }
+
fn advance_workspace_space_swipe_push(&mut self, now: Instant) {
if self.workspace_sidebar_swipe.advance(now) {
// Ask for another frame without naming an interval. The native
@@ -2682,7 +2960,7 @@ impl crate::TermWindow {
now: Instant,
page_width: f32,
) -> Option<(f32, f32)> {
- let gesture_extent = self.workspace_sidebar_width() as f32;
+ let gesture_extent = self.workspace_sidebar_presented_width() as f32;
let visual = self.workspace_sidebar_swipe.visual(now, gesture_extent)?;
// Before the commit the direction is whichever way the finger has
// travelled; after it, the committed direction is authoritative,
@@ -2712,7 +2990,7 @@ impl crate::TermWindow {
// destination and the outgoing one is held in the source frame.
return Ok(());
}
- let gesture_extent = self.workspace_sidebar_width() as f32;
+ let gesture_extent = self.workspace_sidebar_presented_width() as f32;
let target = self
.workspace_sidebar_swipe
.visual(now, gesture_extent)
@@ -2773,6 +3051,7 @@ impl crate::TermWindow {
pub fn paint_pass(&mut self) -> anyhow::Result<()> {
let frame_now = Instant::now();
self.advance_workspace_space_swipe_push(frame_now);
+ self.advance_workspace_sidebar_hover(frame_now);
self.advance_content_view_fade(frame_now);
// Card texture work is queued per pass; a retried pass re-queues it.
self.pending_card_renders.borrow_mut().clear();
@@ -2935,7 +3214,8 @@ impl crate::TermWindow {
// the bottom quote most visibly, at 38% alpha over itself -- drawn
// twice. It also made the return look like a dissolve rather than a
// move, because the picture being travelled towards was already there.
- let paint_terminal_world = (!content_view_active && !fading_content_view) || recording_flight;
+ let paint_terminal_world =
+ (!content_view_active && !fading_content_view) || recording_flight;
if !content_view_active {
// Takeover remains opaque while this actively polls and hydrates
@@ -3029,6 +3309,12 @@ impl crate::TermWindow {
self.capture_workspace_space_swipe_target(frame_now)?;
+ // A hover reveal replaces the normal sidebar paint entirely: the
+ // panel is recorded off-screen here and composited after the tab
+ // bar, so both its pixels and its hit targets land above the
+ // chrome that would otherwise cover its top edge.
+ let hover_overlay = self.record_workspace_sidebar_hover_overlay(frame_now)?;
+
let render_space_push = self.workspace_space_swipe_push_active
&& self.workspace_space_swipe_source_frame.is_some();
// Before the commit the window still shows the Space being left, so
@@ -3046,7 +3332,11 @@ impl crate::TermWindow {
let mut sidebar_frame = HeapQuadAllocator::default();
let mut composited_tracking_frame = false;
- if render_space_push || render_space_track {
+ if hover_overlay.is_some() {
+ // The overlay recording above already painted the sidebar;
+ // painting it again here would put a second copy underneath
+ // the terminal-glyph sub-layer.
+ } else if render_space_push || render_space_track {
let mut sidebar_layers = TripleLayerQuadAllocator::Heap(&mut sidebar_frame);
self.paint_workspace_sidebar(&mut sidebar_layers)
.context("paint live workspace sidebar")?;
@@ -3054,7 +3344,7 @@ impl crate::TermWindow {
let live_list = self.workspace_sidebar_list_quads;
if self.workspace_space_swipe_needs_settle_start {
- let gesture_extent = self.workspace_sidebar_width() as f32;
+ let gesture_extent = self.workspace_sidebar_presented_width() as f32;
let opening = if self.workspace_space_swipe_tracked {
crate::termwindow::space_swipe::SettleOpening::WhereTheFingerLeftIt
} else {
@@ -3236,6 +3526,35 @@ impl crate::TermWindow {
.context("paint_tab_bar")?;
}
drop(chrome_layers);
+
+ if let Some((overlay, hidden, items)) = hover_overlay {
+ self.paint_workspace_sidebar_hover_overlay(&overlay, hidden)
+ .context("paint hover-revealed workspace sidebar")?;
+ // After the tab bar, on purpose: collapsed, the tab strip
+ // starts at x=0 and `resolve_ui_item` is last-pushed-wins,
+ // so items registered before it would lose the top of the
+ // panel to the tabs underneath.
+ self.ui_items.extend(items);
+ } else if self.workspace_sidebar_hover.is_arming() {
+ // The dwell is counting down: show a thin strip at the edge
+ // so a correctly-parked pointer looks different from a
+ // wrongly-parked one. Sub-layer 2, after the tab bar, for the
+ // same reason the overlay itself is.
+ if let Some((zx, zy, _, zh)) = self.workspace_sidebar_hover_hot_zone() {
+ let hint_width =
+ self.ui_px(crate::termwindow::ui::tokens::SIDEBAR_HOVER_HINT_WIDTH) as f32;
+ let palette =
+ UiPalette::for_appearance(crate::native_settings::effective_appearance());
+ let mut hint_layers = layer.quad_allocator();
+ self.filled_rectangle(
+ &mut hint_layers,
+ 2,
+ euclid::rect(zx as f32, zy as f32, hint_width, zh as f32),
+ palette.sidebar_row_active_border.mul_alpha(0.7),
+ )
+ .context("paint sidebar hover arming hint")?;
+ }
+ }
}
if fading_content_view {
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index 0b62d88d..5a635574 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -67,6 +67,50 @@ fn remote_divider_can_pump(
!in_flight && has_pending && (strategy == super::RemoteDividerResizeStrategy::Live || finishing)
}
+/// The tab geometry a local viewport publish was computed against.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub(crate) struct LocalTabShape {
+ size: TerminalSize,
+ /// Sorted, so two snapshots of the same pane set always compare equal.
+ panes: Vec<PaneId>,
+}
+
+impl LocalTabShape {
+ fn of(tab: &Arc<mux::tab::Tab>) -> Self {
+ let mut panes: Vec<PaneId> = tab
+ .iter_all_panes()
+ .into_iter()
+ .map(|pane| pane.pane_id())
+ .collect();
+ panes.sort_unstable();
+ Self {
+ size: tab.get_size(),
+ panes,
+ }
+ }
+}
+
+/// The last locally-published viewport the mux rejected, together with the
+/// tab shape it was computed against. A rejected viewport is deterministic:
+/// republishing it fails identically, and the failure revokes the lease and
+/// notifies every renderer — which brings us straight back here at the 120ms
+/// report cadence. Stay quiet until the geometry or the tab actually changes.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub(crate) struct RejectedLocalViewport {
+ viewport: mux::FrontendViewport,
+ shape: LocalTabShape,
+}
+
+/// A publish is worth attempting unless the exact same geometry was already
+/// rejected against the exact same tab shape.
+fn local_viewport_publish_is_worthwhile(
+ rejected: Option<&RejectedLocalViewport>,
+ candidate: &mux::FrontendViewport,
+ shape: &LocalTabShape,
+) -> bool {
+ rejected.is_none_or(|prior| prior.viewport != *candidate || prior.shape != *shape)
+}
+
// Full-screen TUIs handle SIGWINCH asynchronously after the server-side PTY
// resize has returned. Keep two 125ms overlay frames of quiet time so a
// slightly delayed clear/redraw cannot become the first visible GUI frame.
@@ -993,6 +1037,8 @@ impl super::TermWindow {
let Some(client_id) = mux.active_identity() else {
return;
};
+ // An explicit user takeover re-arms the local publish path.
+ self.forget_rejected_local_viewport(tab_id);
let viewport = self.local_frontend_viewport_for_tab(&tab, true);
if let Err(err) = mux.claim_local_frontend_viewport(&client_id, tab_id, viewport) {
log::warn!("claiming local GUI frontend viewport: {err:#}");
@@ -1098,6 +1144,8 @@ impl super::TermWindow {
codec::FrontendAccessMode::TmuxLatest => mux::FrontendAccessMode::TmuxLatest,
codec::FrontendAccessMode::Handoff => mux::FrontendAccessMode::Handoff,
};
+ // A mode change is an explicit user action: re-arm the local publish.
+ self.forget_rejected_local_viewport(tab_id);
let viewport = self.local_frontend_viewport_for_tab(&tab, true);
if let Err(err) =
mux.validate_frontend_access_mode_change(&client_id, target, tab_id, &viewport)
@@ -1205,6 +1253,9 @@ impl super::TermWindow {
fn report_frontend_viewport_now(&mut self) {
let mux = Mux::get();
+ // Rejections for tabs that no longer exist have nothing left to damp.
+ self.rejected_local_viewports
+ .retain(|tab_id, _| mux.get_tab(*tab_id).is_some());
let Some(tab) = mux.get_active_tab_for_window(self.mux_window_id) else {
return;
};
@@ -1491,7 +1542,14 @@ impl super::TermWindow {
.detach();
}
- fn report_frontend_viewport_for_tab(&self, tab: &Arc<mux::tab::Tab>) {
+ /// Allow the next local publish for `tab_id` even if an identical one was
+ /// rejected: an explicit user action (a claim, a mode change) means a
+ /// retry is meaningful again.
+ pub(crate) fn forget_rejected_local_viewport(&mut self, tab_id: mux::tab::TabId) {
+ self.rejected_local_viewports.remove(&tab_id);
+ }
+
+ fn report_frontend_viewport_for_tab(&mut self, tab: &Arc<mux::tab::Tab>) {
let mux = Mux::get();
let Some(active_pane) = tab.get_active_pane() else {
return;
@@ -1553,12 +1611,25 @@ impl super::TermWindow {
let Some(client_id) = mux.active_identity() else {
return;
};
- if let Err(err) = mux.set_client_viewport(
- &client_id,
- tab_id,
- self.local_frontend_viewport_for_tab(tab, owns),
+ let viewport = self.local_frontend_viewport_for_tab(tab, owns);
+ let shape = LocalTabShape::of(tab);
+ if !local_viewport_publish_is_worthwhile(
+ self.rejected_local_viewports.get(&tab_id),
+ &viewport,
+ &shape,
) {
- log::warn!("cannot publish local GUI viewport: {err:#}");
+ mux::zoom_trace!("gui.viewport.skip tab={tab_id} reason=rejected");
+ return;
+ }
+ match mux.set_client_viewport(&client_id, tab_id, viewport.clone()) {
+ Ok(_) => {
+ self.rejected_local_viewports.remove(&tab_id);
+ }
+ Err(err) => {
+ log::warn!("cannot publish local GUI viewport: {err:#}");
+ self.rejected_local_viewports
+ .insert(tab_id, RejectedLocalViewport { viewport, shape });
+ }
}
}
@@ -2654,13 +2725,84 @@ pub fn effective_right_padding(config: &ConfigHandle, context: DimensionContext)
#[cfg(test)]
mod frontend_geometry_tests {
use super::{
- frontend_geometry_action, geometry_confirmation_settled, remote_divider_can_pump,
+ frontend_geometry_action, geometry_confirmation_settled,
+ local_viewport_publish_is_worthwhile, remote_divider_can_pump,
remote_divider_target_is_owed, visible_geometry_targets, FrontendGeometryAction,
- FRONTEND_GEOMETRY_SETTLE,
+ LocalTabShape, RejectedLocalViewport, FRONTEND_GEOMETRY_SETTLE,
};
use crate::termwindow::{FrontendGeometryPhase, RemoteDividerResizeStrategy};
use std::collections::HashSet;
use std::time::{Duration, Instant};
+ use wezterm_term::TerminalSize;
+
+ fn test_size(cols: usize, rows: usize) -> TerminalSize {
+ TerminalSize {
+ cols,
+ rows,
+ pixel_width: cols * 8,
+ pixel_height: rows * 16,
+ dpi: 96,
+ }
+ }
+
+ fn test_shape(cols: usize, rows: usize, panes: &[usize]) -> LocalTabShape {
+ LocalTabShape {
+ size: test_size(cols, rows),
+ panes: panes.to_vec(),
+ }
+ }
+
+ fn test_viewport(cols: usize, rows: usize) -> mux::FrontendViewport {
+ mux::FrontendViewport::CellGrid {
+ size: test_size(cols, rows),
+ }
+ }
+
+ #[test]
+ fn an_identical_rejected_local_viewport_is_not_republished() {
+ let viewport = test_viewport(120, 40);
+ let shape = test_shape(120, 40, &[1, 2]);
+ assert!(local_viewport_publish_is_worthwhile(
+ None, &viewport, &shape
+ ));
+
+ let rejected = RejectedLocalViewport {
+ viewport: viewport.clone(),
+ shape: shape.clone(),
+ };
+ assert!(!local_viewport_publish_is_worthwhile(
+ Some(&rejected),
+ &viewport,
+ &shape
+ ));
+ }
+
+ #[test]
+ fn a_changed_viewport_or_tab_shape_re_arms_the_local_publish() {
+ let rejected = RejectedLocalViewport {
+ viewport: test_viewport(120, 40),
+ shape: test_shape(120, 40, &[1, 2]),
+ };
+
+ // A different viewport is worth publishing...
+ assert!(local_viewport_publish_is_worthwhile(
+ Some(&rejected),
+ &test_viewport(100, 30),
+ &test_shape(120, 40, &[1, 2]),
+ ));
+ // ...as is the same viewport against a resized tab...
+ assert!(local_viewport_publish_is_worthwhile(
+ Some(&rejected),
+ &test_viewport(120, 40),
+ &test_shape(90, 40, &[1, 2]),
+ ));
+ // ...or against a changed pane set.
+ assert!(local_viewport_publish_is_worthwhile(
+ Some(&rejected),
+ &test_viewport(120, 40),
+ &test_shape(120, 40, &[1, 2, 3]),
+ ));
+ }
#[test]
fn only_takeover_geometry_obscures_the_terminal() {
diff --git a/wezterm-gui/src/termwindow/sidebar_hover.rs b/wezterm-gui/src/termwindow/sidebar_hover.rs
new file mode 100644
index 00000000..b57b220c
--- /dev/null
+++ b/wezterm-gui/src/termwindow/sidebar_hover.rs
@@ -0,0 +1,683 @@
+//! Hover-reveal of the collapsed workspace sidebar.
+//!
+//! A pure state machine, deliberately free of `TermWindow`: it is fed a
+//! [`HoverInput`] snapshot once per mouse event and once per frame, and
+//! answers with the single [`HoverFrame`] obligation the frame loop owes it.
+//! The panel it drives is an OVERLAY — revealing must never reflow the
+//! terminal, which is why nothing in here touches `workspace_sidebar_width`
+//! or `workspace_sidebar_collapsed`.
+
+use crate::termwindow::ui::tokens::{SIDEBAR_HOVER_DWELL_MS, SIDEBAR_HOVER_GRACE_MS};
+use crate::ui::anim::{self, Easing, Timeline};
+use std::time::{Duration, Instant};
+
+const DWELL: Duration = Duration::from_millis(SIDEBAR_HOVER_DWELL_MS);
+const GRACE: Duration = Duration::from_millis(SIDEBAR_HOVER_GRACE_MS);
+/// Both SHORT: the panel is narrow and a hover reveal is asked for casually,
+/// so it should feel like a flick, not a page turn.
+const REVEAL: Duration = anim::SHORT;
+const RETREAT: Duration = anim::SHORT;
+
+/// Where the pointer is, in the only four terms the machine cares about.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum PointerZone {
+ /// Outside the window, or somewhere with no bearing on the panel.
+ Away,
+ /// In the narrow left-edge strip that arms a reveal.
+ HotZone,
+ /// Just outside the arming strip but inside the wider sticky band:
+ /// close enough to keep a running dwell alive, not close enough to
+ /// start one. The hysteresis that stops a one-pixel wobble from
+ /// restarting the count.
+ NearHotZone,
+ /// Inside the panel as presented.
+ Panel,
+}
+
+/// Everything the machine needs about the frame it is stepped in. `Copy`, so
+/// a caller cannot accidentally hold a borrow of the window across a
+/// transition.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) struct HoverInput {
+ /// A reveal is possible at all: enabled in settings, the sidebar
+ /// collapsed, no content view in the foreground, no menu, modal or
+ /// gesture in flight.
+ pub(crate) eligible: bool,
+ pub(crate) pointer: PointerZone,
+ /// A press, capture or drag is live, so retreating would pull the ground
+ /// out from under it — and arming would steal a click from the terminal.
+ pub(crate) pinned: bool,
+}
+
+/// What a step owes the frame loop.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum HoverFrame {
+ /// Nothing owed.
+ None,
+ /// As fast as the display will give it: something is travelling.
+ Now,
+ /// Exactly one wakeup, at this instant: a dwell or grace is counting
+ /// down.
+ At(Instant),
+}
+
+#[derive(Debug, Clone)]
+enum Phase {
+ Hidden,
+ Arming {
+ since: Instant,
+ },
+ /// `travel` runs 0 -> 1. It is carried through `Departing` so a pointer
+ /// that leaves mid-arrival still sees the panel finish arriving before
+ /// the grace runs out, rather than freezing part-way.
+ Revealing {
+ travel: Timeline,
+ },
+ Revealed,
+ Departing {
+ travel: Timeline,
+ grace_until: Instant,
+ },
+ Retreating {
+ travel: Timeline,
+ },
+ /// Collapsed by hand while the pointer was still in the strip. Re-arming
+ /// from here would undo the click that just closed the panel, so this
+ /// waits for the pointer to leave before it will consider anything.
+ Suppressed,
+}
+
+impl Default for Phase {
+ fn default() -> Self {
+ Self::Hidden
+ }
+}
+
+#[derive(Debug, Clone, Default)]
+pub(crate) struct SidebarHoverReveal {
+ phase: Phase,
+}
+
+impl SidebarHoverReveal {
+ /// The whole transition. Call once per frame and once per mouse event.
+ pub(crate) fn step(&mut self, input: HoverInput, now: Instant) -> HoverFrame {
+ let phase = std::mem::take(&mut self.phase);
+
+ if !input.eligible {
+ // Whatever made the machine ineligible (a content view opening, a
+ // settings change) may not repaint on its own; if the panel or
+ // the arming hint was on screen, one more frame erases it.
+ let needs_erase = !matches!(phase, Phase::Hidden | Phase::Suppressed);
+ self.phase = Phase::Hidden;
+ return if needs_erase {
+ HoverFrame::Now
+ } else {
+ HoverFrame::None
+ };
+ }
+
+ let (phase, frame) = match phase {
+ Phase::Hidden => {
+ if input.pointer == PointerZone::HotZone && !input.pinned {
+ (Phase::Arming { since: now }, HoverFrame::At(now + DWELL))
+ } else {
+ (Phase::Hidden, HoverFrame::None)
+ }
+ }
+ Phase::Arming { since } => {
+ // The hint strip is on screen: every exit owes one erasing
+ // frame. Holding tolerates the sticky band; only starting
+ // demanded the narrow strip.
+ let holding = matches!(
+ input.pointer,
+ PointerZone::HotZone | PointerZone::NearHotZone
+ );
+ if input.pinned {
+ // A press at the edge belongs to the terminal.
+ (Phase::Hidden, HoverFrame::Now)
+ } else if !holding {
+ (Phase::Hidden, HoverFrame::Now)
+ } else if now.saturating_duration_since(since) >= DWELL {
+ (
+ Phase::Revealing {
+ travel: Timeline::progress(now, REVEAL, Easing::OutCubic),
+ },
+ HoverFrame::Now,
+ )
+ } else {
+ (Phase::Arming { since }, HoverFrame::At(since + DWELL))
+ }
+ }
+ Phase::Revealing { mut travel } => {
+ if input.pointer == PointerZone::Away && !input.pinned {
+ (
+ Phase::Departing {
+ travel,
+ grace_until: now + GRACE,
+ },
+ HoverFrame::At(now + GRACE),
+ )
+ } else if travel.advance(now) {
+ (Phase::Revealing { travel }, HoverFrame::Now)
+ } else {
+ // One last frame lands the end value.
+ (Phase::Revealed, HoverFrame::Now)
+ }
+ }
+ Phase::Revealed => {
+ if input.pointer == PointerZone::Away && !input.pinned {
+ (
+ Phase::Departing {
+ travel: Timeline::settled(now, 1.0),
+ grace_until: now + GRACE,
+ },
+ HoverFrame::At(now + GRACE),
+ )
+ } else {
+ (Phase::Revealed, HoverFrame::None)
+ }
+ }
+ Phase::Departing {
+ mut travel,
+ grace_until,
+ } => {
+ if input.pointer != PointerZone::Away || input.pinned {
+ if travel.is_running() {
+ (Phase::Revealing { travel }, HoverFrame::Now)
+ } else {
+ (Phase::Revealed, HoverFrame::None)
+ }
+ } else if now >= grace_until {
+ travel.retarget(now, 0.0, RETREAT, Easing::OutCubic);
+ (Phase::Retreating { travel }, HoverFrame::Now)
+ } else if travel.advance(now) {
+ // Still arriving while the grace counts down.
+ (
+ Phase::Departing {
+ travel,
+ grace_until,
+ },
+ HoverFrame::Now,
+ )
+ } else {
+ (
+ Phase::Departing {
+ travel,
+ grace_until,
+ },
+ HoverFrame::At(grace_until),
+ )
+ }
+ }
+ Phase::Retreating { mut travel } => {
+ if input.pointer != PointerZone::Away {
+ // Departs from where the panel is: no jump.
+ travel.retarget(now, 1.0, REVEAL, Easing::OutCubic);
+ (Phase::Revealing { travel }, HoverFrame::Now)
+ } else if travel.advance(now) {
+ (Phase::Retreating { travel }, HoverFrame::Now)
+ } else {
+ // One more frame erases the panel.
+ (Phase::Hidden, HoverFrame::Now)
+ }
+ }
+ Phase::Suppressed => {
+ if input.pointer == PointerZone::Away {
+ (Phase::Hidden, HoverFrame::None)
+ } else {
+ (Phase::Suppressed, HoverFrame::None)
+ }
+ }
+ };
+ self.phase = phase;
+ frame
+ }
+
+ /// `None` = nothing presented; `Some(0.0..=1.0)` = how far out the panel
+ /// is.
+ pub(crate) fn progress(&self, now: Instant) -> Option<f32> {
+ match &self.phase {
+ Phase::Revealing { travel }
+ | Phase::Departing { travel, .. }
+ | Phase::Retreating { travel } => Some(travel.value(now).clamp(0.0, 1.0)),
+ Phase::Revealed => Some(1.0),
+ Phase::Hidden | Phase::Arming { .. } | Phase::Suppressed => None,
+ }
+ }
+
+ /// Whether the panel is on screen at all. Clock-free, so geometry code
+ /// can ask without a timestamp.
+ pub(crate) fn is_presented(&self) -> bool {
+ matches!(
+ self.phase,
+ Phase::Revealing { .. }
+ | Phase::Revealed
+ | Phase::Departing { .. }
+ | Phase::Retreating { .. }
+ )
+ }
+
+ /// Fully out: real hit targets may be registered.
+ pub(crate) fn is_fully_presented(&self, now: Instant) -> bool {
+ self.progress(now).is_some_and(|p| p >= 1.0)
+ }
+
+ /// The dwell is counting down: the edge hint should be visible.
+ pub(crate) fn is_arming(&self) -> bool {
+ matches!(self.phase, Phase::Arming { .. })
+ }
+
+ /// Whether the machine still owes frames — a travel in flight or a dwell
+ /// or grace counting down. Feeds the unfocused-window frame gate.
+ pub(crate) fn needs_frames(&self) -> bool {
+ !matches!(
+ self.phase,
+ Phase::Hidden | Phase::Revealed | Phase::Suppressed
+ )
+ }
+
+ /// A manual collapse with the pointer still at the edge must not re-open
+ /// the panel it just closed: wait for the pointer to leave first.
+ pub(crate) fn suppress_until_pointer_leaves(&mut self) {
+ self.phase = Phase::Suppressed;
+ }
+
+ /// Land a travelling panel instead of letting a geometry change make it
+ /// jump: a settled overlay survives a resize or DPI change cleanly.
+ pub(crate) fn settle_immediately(&mut self) {
+ self.phase = match std::mem::take(&mut self.phase) {
+ Phase::Revealing { .. } | Phase::Departing { .. } => Phase::Revealed,
+ Phase::Retreating { .. } => Phase::Hidden,
+ other => other,
+ };
+ }
+
+ /// Focus loss: drop the panel outright.
+ pub(crate) fn cancel_immediately(&mut self) {
+ self.phase = Phase::Hidden;
+ }
+}
+
+/// The left-edge strip that arms a reveal, given the panel's would-be rect.
+///
+/// Deliberately excludes the top chrome row: at the top-left the pointer is
+/// on its way to the traffic lights or to the sidebar toggle, and revealing
+/// the panel under it fights the button the user is aiming at.
+pub(crate) fn hot_zone(
+ x: usize,
+ y: usize,
+ height: usize,
+ hot_zone_width: usize,
+ top_chrome_height: usize,
+) -> Option<(usize, usize, usize, usize)> {
+ if hot_zone_width == 0 {
+ return None;
+ }
+ let top = y.max(top_chrome_height);
+ let bottom = y.saturating_add(height);
+ if top >= bottom {
+ return None;
+ }
+ Some((x, top, hot_zone_width, bottom - top))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn at(start: Instant, ms: u64) -> Instant {
+ start + Duration::from_millis(ms)
+ }
+
+ fn input(zone: PointerZone) -> HoverInput {
+ HoverInput {
+ eligible: true,
+ pointer: zone,
+ pinned: false,
+ }
+ }
+
+ fn pinned(zone: PointerZone) -> HoverInput {
+ HoverInput {
+ pinned: true,
+ ..input(zone)
+ }
+ }
+
+ /// Step until the machine reports Revealed (progress 1.0), sampling
+ /// values so the Timeline clock runs. Returns the time it settled at.
+ fn reveal(machine: &mut SidebarHoverReveal, start: Instant) -> Instant {
+ machine.step(input(PointerZone::HotZone), start);
+ let mut now = at(start, SIDEBAR_HOVER_DWELL_MS);
+ machine.step(input(PointerZone::HotZone), now);
+ // Sample the opening frame so the clock starts, then run it out.
+ for _ in 0..200 {
+ let _ = machine.progress(now);
+ now += Duration::from_millis(16);
+ machine.step(input(PointerZone::HotZone), now);
+ if machine.progress(now) == Some(1.0) && !machine.needs_frames() {
+ return now;
+ }
+ }
+ panic!("panel never settled");
+ }
+
+ #[test]
+ fn a_pointer_passing_through_the_edge_never_reveals() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ assert_eq!(
+ machine.step(input(PointerZone::HotZone), start),
+ HoverFrame::At(at(start, SIDEBAR_HOVER_DWELL_MS))
+ );
+ // Leaving owes one frame to erase the arming hint, then nothing.
+ assert_eq!(
+ machine.step(input(PointerZone::Away), at(start, 100)),
+ HoverFrame::Now
+ );
+ assert_eq!(machine.progress(at(start, 100)), None);
+ assert!(!machine.is_presented());
+ assert!(!machine.is_arming());
+ }
+
+ #[test]
+ fn a_wobble_into_the_sticky_band_keeps_the_dwell_counting() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ assert!(machine.is_arming());
+ // Drifts just outside the narrow strip: the count survives...
+ assert_eq!(
+ machine.step(input(PointerZone::NearHotZone), at(start, 60)),
+ HoverFrame::At(at(start, SIDEBAR_HOVER_DWELL_MS))
+ );
+ // ...and still fires on schedule, even from the sticky band.
+ assert_eq!(
+ machine.step(
+ input(PointerZone::NearHotZone),
+ at(start, SIDEBAR_HOVER_DWELL_MS)
+ ),
+ HoverFrame::Now
+ );
+ assert!(machine.is_presented());
+ // But the sticky band never STARTS a dwell.
+ let mut fresh = SidebarHoverReveal::default();
+ assert_eq!(
+ fresh.step(input(PointerZone::NearHotZone), start),
+ HoverFrame::None
+ );
+ assert!(!fresh.is_arming());
+ }
+
+ #[test]
+ fn a_motionless_pointer_reveals_when_the_dwell_expires() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ // One tick short: still counting down to the same deadline.
+ assert_eq!(
+ machine.step(
+ input(PointerZone::HotZone),
+ at(start, SIDEBAR_HOVER_DWELL_MS - 1)
+ ),
+ HoverFrame::At(at(start, SIDEBAR_HOVER_DWELL_MS))
+ );
+ assert_eq!(
+ machine.progress(at(start, SIDEBAR_HOVER_DWELL_MS - 1)),
+ None
+ );
+ // Expiry: travelling.
+ assert_eq!(
+ machine.step(
+ input(PointerZone::HotZone),
+ at(start, SIDEBAR_HOVER_DWELL_MS)
+ ),
+ HoverFrame::Now
+ );
+ assert!(machine
+ .progress(at(start, SIDEBAR_HOVER_DWELL_MS))
+ .is_some());
+ assert!(machine.is_presented());
+ }
+
+ #[test]
+ fn the_reveal_clock_does_not_start_until_the_first_frame_is_presented() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ machine.step(input(PointerZone::HotZone), at(start, 250));
+ // Opening frame: 0.0, and sampling is what arms the clock.
+ assert_eq!(machine.progress(at(start, 250)), Some(0.0));
+ // The clock starts on the *next* advance after the sample.
+ machine.step(input(PointerZone::HotZone), at(start, 350));
+ let p = machine.progress(at(start, 350)).unwrap();
+ assert!(p < 0.05, "clock should start at the sampled frame, got {p}");
+ }
+
+ #[test]
+ fn a_press_in_the_hot_zone_belongs_to_the_terminal() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ // Cancelling owes one frame to erase the arming hint.
+ assert_eq!(
+ machine.step(pinned(PointerZone::HotZone), at(start, 100)),
+ HoverFrame::Now
+ );
+ assert!(!machine.is_presented());
+ // And the pinned pointer sitting there does not re-arm.
+ assert_eq!(
+ machine.step(pinned(PointerZone::HotZone), at(start, 150)),
+ HoverFrame::None
+ );
+ }
+
+ #[test]
+ fn leaving_starts_a_grace_and_returning_inside_it_cancels_the_retreat() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ let settled = reveal(&mut machine, start);
+ assert_eq!(
+ machine.step(input(PointerZone::Away), settled),
+ HoverFrame::At(settled + GRACE)
+ );
+ // Comes back just inside the grace: still fully out, no travel.
+ machine.step(
+ input(PointerZone::Panel),
+ at(settled, SIDEBAR_HOVER_GRACE_MS - 1),
+ );
+ assert_eq!(
+ machine.progress(at(settled, SIDEBAR_HOVER_GRACE_MS - 1)),
+ Some(1.0)
+ );
+ assert!(!machine.needs_frames());
+ }
+
+ #[test]
+ fn the_grace_expiring_retreats_and_the_panel_leaves() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ let settled = reveal(&mut machine, start);
+ machine.step(input(PointerZone::Away), settled);
+ let mut now = at(settled, SIDEBAR_HOVER_GRACE_MS);
+ machine.step(input(PointerZone::Away), now);
+ assert!(machine.is_presented(), "retreat should be animated");
+ for _ in 0..200 {
+ let _ = machine.progress(now);
+ now += Duration::from_millis(16);
+ machine.step(input(PointerZone::Away), now);
+ if !machine.is_presented() {
+ return;
+ }
+ }
+ panic!("panel never left");
+ }
+
+ #[test]
+ fn a_pointer_that_comes_back_mid_retreat_departs_from_where_the_panel_is() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ let settled = reveal(&mut machine, start);
+ machine.step(input(PointerZone::Away), settled);
+ let mut now = at(settled, SIDEBAR_HOVER_GRACE_MS);
+ machine.step(input(PointerZone::Away), now);
+ // Run part of the retreat.
+ for _ in 0..4 {
+ let _ = machine.progress(now);
+ now += Duration::from_millis(16);
+ machine.step(input(PointerZone::Away), now);
+ }
+ let mid = machine.progress(now).unwrap();
+ assert!(mid < 1.0, "retreat should have moved, got {mid}");
+ // Return: the reveal departs from `mid`, monotonically upward.
+ machine.step(input(PointerZone::HotZone), now);
+ let mut last = machine.progress(now).unwrap();
+ assert!((last - mid).abs() < 0.05, "no jump on reversal");
+ for _ in 0..200 {
+ now += Duration::from_millis(16);
+ machine.step(input(PointerZone::HotZone), now);
+ let p = machine.progress(now).unwrap();
+ assert!(p >= last - 0.001, "progress went backwards: {p} < {last}");
+ last = p;
+ if p >= 1.0 && !machine.needs_frames() {
+ return;
+ }
+ }
+ panic!("panel never re-settled");
+ }
+
+ #[test]
+ fn leaving_during_the_arrival_still_lets_it_arrive_before_the_grace_runs_out() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ let mut now = at(start, SIDEBAR_HOVER_DWELL_MS);
+ machine.step(input(PointerZone::HotZone), now);
+ let _ = machine.progress(now); // present the opening frame
+ now += Duration::from_millis(16);
+ machine.step(input(PointerZone::HotZone), now);
+ // Leave mid-arrival; the grace (400ms) outlasts the travel (220ms).
+ machine.step(input(PointerZone::Away), now);
+ let mut reached_full = false;
+ for _ in 0..200 {
+ let _ = machine.progress(now);
+ now += Duration::from_millis(16);
+ machine.step(input(PointerZone::Away), now);
+ match machine.progress(now) {
+ Some(p) if p >= 1.0 => reached_full = true,
+ Some(_) if !reached_full => {}
+ _ => break,
+ }
+ }
+ assert!(
+ reached_full,
+ "panel should finish arriving before it retreats"
+ );
+ }
+
+ #[test]
+ fn a_drag_out_of_the_panel_pins_it_open() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ let settled = reveal(&mut machine, start);
+ assert_eq!(
+ machine.step(pinned(PointerZone::Away), at(settled, 50)),
+ HoverFrame::None
+ );
+ assert_eq!(machine.progress(at(settled, 50)), Some(1.0));
+ }
+
+ #[test]
+ fn collapsing_by_hand_does_not_re_reveal_under_the_pointer() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.suppress_until_pointer_leaves();
+ for ms in (0..1000).step_by(100) {
+ assert_eq!(
+ machine.step(input(PointerZone::HotZone), at(start, ms)),
+ HoverFrame::None
+ );
+ assert_eq!(machine.progress(at(start, ms)), None);
+ }
+ // Leaving releases the suppression...
+ machine.step(input(PointerZone::Away), at(start, 1100));
+ // ...and the strip arms again.
+ assert_eq!(
+ machine.step(input(PointerZone::HotZone), at(start, 1200)),
+ HoverFrame::At(at(start, 1200 + SIDEBAR_HOVER_DWELL_MS))
+ );
+ }
+
+ #[test]
+ fn becoming_ineligible_hides_immediately() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ let settled = reveal(&mut machine, start);
+ let gone = HoverInput {
+ eligible: false,
+ ..input(PointerZone::Panel)
+ };
+ // One erasing frame is owed, then nothing.
+ assert_eq!(machine.step(gone, at(settled, 10)), HoverFrame::Now);
+ assert_eq!(machine.progress(at(settled, 10)), None);
+ assert_eq!(machine.step(gone, at(settled, 20)), HoverFrame::None);
+ }
+
+ #[test]
+ fn settling_lands_a_travelling_panel_instead_of_deleting_it() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ machine.step(
+ input(PointerZone::HotZone),
+ at(start, SIDEBAR_HOVER_DWELL_MS),
+ );
+ assert!(machine.is_presented());
+ machine.settle_immediately();
+ assert_eq!(machine.progress(at(start, 300)), Some(1.0));
+ assert!(!machine.needs_frames());
+
+ // A retreat settles to gone.
+ machine.step(input(PointerZone::Away), at(start, 400));
+ machine.step(
+ input(PointerZone::Away),
+ at(start, 400 + SIDEBAR_HOVER_GRACE_MS),
+ );
+ machine.settle_immediately();
+ assert_eq!(machine.progress(at(start, 900)), None);
+ }
+
+ #[test]
+ fn only_a_pending_deadline_or_a_travelling_panel_owes_frames() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ assert!(!machine.needs_frames()); // Hidden
+ machine.step(input(PointerZone::HotZone), start);
+ assert!(machine.needs_frames()); // Arming
+ machine.step(
+ input(PointerZone::HotZone),
+ at(start, SIDEBAR_HOVER_DWELL_MS),
+ );
+ assert!(machine.needs_frames()); // Revealing
+ let settled = reveal(&mut machine, at(start, 1000));
+ assert!(!machine.needs_frames()); // Revealed
+ machine.step(input(PointerZone::Away), settled);
+ assert!(machine.needs_frames()); // Departing
+ machine.step(
+ input(PointerZone::Away),
+ at(settled, SIDEBAR_HOVER_GRACE_MS),
+ );
+ assert!(machine.needs_frames()); // Retreating
+ machine.suppress_until_pointer_leaves();
+ assert!(!machine.needs_frames()); // Suppressed
+ }
+
+ #[test]
+ fn the_hot_zone_excludes_the_tab_bar_row() {
+ assert_eq!(hot_zone(0, 0, 800, 6, 52), Some((0, 52, 6, 748)));
+ assert_eq!(hot_zone(0, 0, 40, 6, 52), None);
+ assert_eq!(hot_zone(0, 0, 800, 0, 52), None);
+ // No chrome: the strip spans the full height.
+ assert_eq!(hot_zone(0, 10, 700, 6, 0), Some((0, 10, 6, 700)));
+ }
+}
diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rs
index 827d1276..d9883ca8 100644
--- a/wezterm-gui/src/termwindow/ui/context_menu.rs
+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs
@@ -303,6 +303,11 @@ impl crate::TermWindow {
// button is still down forever. Release that bookkeeping here,
// where we know the release can no longer be observed.
self.release_pointer_ownership_for_native_menu();
+ // The only trace that a native menu is open: the hover-reveal
+ // machine must not retreat the panel this menu is anchored to.
+ // Cleared by whichever of PerformKeyAssignment /
+ // PerformContextMenuAction / ContextMenuDismissed ends the menu.
+ self.native_context_menu_open = true;
context.show_context_menu(coords, items);
return;
}
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index e8ef030a..cc18f79e 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -150,16 +150,48 @@ impl crate::TermWindow {
workspace_threads::acknowledge_thread_work_for_workspace_deferred(window.get_workspace())
}
+ /// The docked width, clamped. Not "the width right now": ask
+ /// `workspace_sidebar_width` for what the terminal is laid out against
+ /// and `workspace_sidebar_presented_width` for what is on screen.
+ fn workspace_sidebar_docked_width(&self) -> usize {
+ let min_width = scale_ui_usize(SIDEBAR_MIN_WIDTH, self.dimensions.dpi);
+ self.workspace_sidebar_width
+ .clamp(min_width, self.workspace_sidebar_max_width())
+ }
+
+ /// The width the TERMINAL is laid out against. Zero whenever the sidebar
+ /// is collapsed, hover reveal or not: a hover must never reflow a PTY.
+ /// Every consumer that decides where the terminal, the tab bar or a pane
+ /// lives asks this one.
pub fn workspace_sidebar_width(&self) -> usize {
if self.workspace_sidebar_collapsed {
0
} else {
- let min_width = scale_ui_usize(SIDEBAR_MIN_WIDTH, self.dimensions.dpi);
- self.workspace_sidebar_width
- .clamp(min_width, self.workspace_sidebar_max_width())
+ self.workspace_sidebar_docked_width()
+ }
+ }
+
+ /// The width the panel is DRAWN and HIT-TESTED at. Equal to
+ /// `workspace_sidebar_width` while docked; the full docked width while a
+ /// hover reveal is on screen, at which point the terminal behind it has
+ /// not moved. Presentation and pointer routing only.
+ pub(crate) fn workspace_sidebar_presented_width(&self) -> usize {
+ if self.workspace_sidebar_collapsed {
+ if self.workspace_sidebar_hover.is_presented() {
+ self.workspace_sidebar_docked_width()
+ } else {
+ 0
+ }
+ } else {
+ self.workspace_sidebar_docked_width()
}
}
+ /// Whether the panel is on screen at all, by either route.
+ pub(crate) fn workspace_sidebar_is_presented(&self) -> bool {
+ !self.workspace_sidebar_collapsed || self.workspace_sidebar_hover.is_presented()
+ }
+
pub fn workspace_sidebar_max_width(&self) -> usize {
let min_width = scale_ui_usize(SIDEBAR_MIN_WIDTH, self.dimensions.dpi);
scale_ui_usize(SIDEBAR_MAX_WIDTH, self.dimensions.dpi)
@@ -185,17 +217,22 @@ impl crate::TermWindow {
self.workspace_sidebar_swipe.cancel_immediately();
self.clear_workspace_space_swipe_frame_transition();
self.workspace_sidebar_collapsed = !self.workspace_sidebar_collapsed;
+ // Whichever way this went, the hover machine must not act on the
+ // pointer still sitting where it was: collapsing must not instantly
+ // re-reveal, and expanding makes the reveal moot.
+ self.workspace_sidebar_hover.suppress_until_pointer_leaves();
}
pub fn expand_workspace_sidebar(&mut self) {
self.workspace_sidebar_collapsed = false;
+ self.workspace_sidebar_hover.suppress_until_pointer_leaves();
}
pub(crate) fn workspace_sidebar_toggle_icon(&self) -> SvgIcon {
- if self.workspace_sidebar_collapsed {
- SvgIcon::PanelLeftOpen
- } else {
+ if self.workspace_sidebar_is_presented() {
SvgIcon::PanelLeftClose
+ } else {
+ SvgIcon::PanelLeftOpen
}
}
@@ -204,7 +241,13 @@ impl crate::TermWindow {
border.left.get() as usize + self.workspace_sidebar_width()
}
+ /// The panel as presented — a hover reveal is included. Anything
+ /// deriving terminal geometry wants `workspace_sidebar_width` instead.
pub fn workspace_sidebar_rect(&self) -> Option<WorkspaceSidebarRect> {
+ self.workspace_sidebar_rect_for_width(self.workspace_sidebar_presented_width())
+ }
+
+ fn workspace_sidebar_rect_for_width(&self, width: usize) -> Option<WorkspaceSidebarRect> {
let border = self.get_os_border();
let bottom_tab_bar_height = if self.config.tab_bar_at_bottom && self.show_tab_bar {
self.tab_bar_pixel_height().unwrap_or(0.0).ceil() as usize
@@ -214,7 +257,7 @@ impl crate::TermWindow {
let x = border.left.get() as usize;
let y = border.top.get() as usize;
- let width = self.workspace_sidebar_width().min(
+ let width = width.min(
self.dimensions
.pixel_width
.saturating_sub((border.left + border.right).get() as usize),
@@ -236,6 +279,25 @@ impl crate::TermWindow {
})
}
+ /// The left-edge strip that arms a hover reveal, as (x, y, w, h) in
+ /// window pixels. Computed against the docked rect so it exists while
+ /// the panel does not.
+ pub(crate) fn workspace_sidebar_hover_hot_zone(&self) -> Option<(usize, usize, usize, usize)> {
+ let rect = self.workspace_sidebar_rect_for_width(self.workspace_sidebar_docked_width())?;
+ let top_tab_bar_height = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
+ self.tab_bar_pixel_height().unwrap_or(0.0).ceil() as usize
+ } else {
+ 0
+ };
+ crate::termwindow::sidebar_hover::hot_zone(
+ rect.x,
+ rect.y,
+ rect.height,
+ self.ui_px(crate::termwindow::ui::tokens::SIDEBAR_HOVER_HOT_ZONE_WIDTH),
+ top_tab_bar_height,
+ )
+ }
+
fn workspace_sidebar_list_height(
view: &workspace_threads::WorkspaceThreadsView,
row_height: usize,
@@ -679,7 +741,7 @@ impl crate::TermWindow {
let Some(rect) = self.workspace_sidebar_rect() else {
return 0.0;
};
- if self.workspace_sidebar_collapsed {
+ if !self.workspace_sidebar_is_presented() {
return 0.0;
}
@@ -723,7 +785,7 @@ impl crate::TermWindow {
/// the header strip and footer, so it must not be used for that.
pub(crate) fn workspace_sidebar_list_viewport(&self) -> Option<(isize, isize)> {
let rect = self.workspace_sidebar_rect()?;
- if self.workspace_sidebar_collapsed {
+ if !self.workspace_sidebar_is_presented() {
return None;
}
let ui_cell_height = self.workspace_sidebar_cell_height();
@@ -737,7 +799,7 @@ impl crate::TermWindow {
pub fn workspace_sidebar_scroll_geometry(&self) -> Option<WorkspaceSidebarScrollGeometry> {
let rect = self.workspace_sidebar_rect()?;
- if self.workspace_sidebar_collapsed {
+ if !self.workspace_sidebar_is_presented() {
return None;
}
@@ -968,7 +1030,7 @@ impl crate::TermWindow {
item_type: UIItemType::WorkspaceSidebarResize,
});
- if self.workspace_sidebar_collapsed {
+ if !self.workspace_sidebar_is_presented() {
return Ok(());
}
diff --git a/wezterm-gui/src/termwindow/ui/tokens.rs b/wezterm-gui/src/termwindow/ui/tokens.rs
index 5f067e8f..2934b717 100644
--- a/wezterm-gui/src/termwindow/ui/tokens.rs
+++ b/wezterm-gui/src/termwindow/ui/tokens.rs
@@ -6,6 +6,29 @@ pub const SIDEBAR_ICON_GAP: usize = 10;
pub const SIDEBAR_ROW_GAP: usize = 10;
pub const SIDEBAR_ROW_RADIUS: f32 = 10.0;
pub const SIDEBAR_RESIZE_HANDLE_WIDTH: usize = 8;
+/// Left-edge strip that arms a hover reveal of the collapsed sidebar.
+///
+/// Scaled through `ui_px`, not a raw pixel count: cell width scales with DPI
+/// too, so scaling keeps the fraction of terminal column 0 the strip covers
+/// (~a cell) the same on every display instead of shrinking to nothing
+/// at 1x or swallowing several columns at 2x.
+pub const SIDEBAR_HOVER_HOT_ZONE_WIDTH: usize = 12;
+/// Once armed, the pointer only cancels the dwell by leaving THIS wider
+/// strip. Entry stays precise; holding does not have to be. Without the
+/// hysteresis a one-pixel wobble restarts the count and the reveal feels
+/// like it needs surgical stillness.
+pub const SIDEBAR_HOVER_STICKY_ZONE_WIDTH: usize = 28;
+/// The visible arming hint: a thin strip at the very edge that appears while
+/// the dwell counts down, so a correctly-parked pointer looks different from
+/// a wrongly-parked one.
+pub const SIDEBAR_HOVER_HINT_WIDTH: usize = 4;
+/// How long the pointer must sit in the strip. Long enough that crossing the
+/// edge on the way to a window control never triggers it.
+pub const SIDEBAR_HOVER_DWELL_MS: u64 = 180;
+/// How long a departed pointer has to come back before the panel leaves.
+/// Generous on purpose: it is the only defence against a native macOS menu,
+/// which sets no flag while open (see `ui/context_menu.rs`).
+pub const SIDEBAR_HOVER_GRACE_MS: u64 = 400;
pub const MACOS_TITLEBAR_CONTENT_TOP_INSET: usize = 52;
pub const MACOS_TRAFFIC_LIGHT_CLEARANCE_WIDTH: usize = 164;
pub const MACOS_WINDOW_TAB_RESERVED_ACTION_SLOTS: usize = 1;