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.

Give the collapsed sidebar hover a shadow and real button hot zones

RoversX4ab81752d43b
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index eeedaa20..3fd9a7e8 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -349,7 +349,6 @@ pub enum MouseCapture {
/// Type used together with Window::notify to do something in the
/// context of the window-specific event loop
pub enum TermWindowNotif {
- InvalidateShapeCache,
/// A font fallback resolve completed for exactly these codepoints. Only
/// entries whose text contains one of them shaped with a placeholder
/// and need re-shaping; everything else stays warm. The wholesale
@@ -3177,6 +3176,20 @@ impl TermWindow {
window.invalidate();
Ok(true)
}
+ WindowEvent::WorkspaceSidebarButtonHover(hovering) => {
+ self.titlebar_sidebar_button_hovered = hovering;
+ // Step the hover machine exactly like a mouse event would;
+ // the frame it asks for registers any dwell wakeup.
+ let input = self.workspace_sidebar_hover_input();
+ if self
+ .workspace_sidebar_hover
+ .step(input, std::time::Instant::now())
+ != crate::termwindow::sidebar_hover::HoverFrame::None
+ {
+ window.invalidate();
+ }
+ Ok(true)
+ }
WindowEvent::MouseLeave => {
self.mouse_leave_impl(window);
Ok(true)
@@ -3459,14 +3472,6 @@ impl TermWindow {
}
match notif {
- TermWindowNotif::InvalidateShapeCache => {
- self.shape_generation += 1;
- self.shape_cache.borrow_mut().clear();
- self.ui_shape_caches.borrow_mut().clear_all();
- self.publish_ui_shape_cache_diagnostics();
- self.invalidate_modal();
- window.invalidate();
- }
TermWindowNotif::InvalidateShapeCacheForChars(chars) => {
// The generation bump retires the terminal line caches
// (their rendered runs may hold placeholder glyphs for these
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index b95bbdda..d0a7a4c8 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -849,13 +849,35 @@ impl super::TermWindow {
.ui_px(crate::termwindow::ui::tokens::SIDEBAR_HOVER_STICKY_ZONE_WIDTH);
(x < zx.saturating_add(sticky) as isize).then_some(PointerZone::NearHotZone)
});
+ // The sidebar toggle button is a hot zone of its own:
+ // pointing at it already says "I want the sidebar", so the
+ // collapsed panel reveals on hover there too (the same dwell
+ // applies, and set_workspace_sidebar_shown's suppression
+ // keeps a collapse click from instantly re-revealing).
+ let over_toggle = self.ui_items.iter().any(|item| {
+ matches!(item.item_type, UIItemType::WorkspaceSidebarToggle)
+ && x >= item.x as isize
+ && x < item.x.saturating_add(item.width) as isize
+ && y >= item.y as isize
+ && y < item.y.saturating_add(item.height) as isize
+ });
if in_panel {
PointerZone::Panel
+ } else if over_toggle {
+ PointerZone::HotZone
} else {
zone.unwrap_or(PointerZone::Away)
}
}
};
+ // The native macOS titlebar button lives outside our view, so it is
+ // invisible to current_mouse_event; its hover arrives as a window
+ // event and overrides the pointer zone here.
+ let pointer = if self.titlebar_sidebar_button_hovered {
+ PointerZone::HotZone
+ } else {
+ pointer
+ };
let pinned = !self.current_mouse_buttons.is_empty()
|| self.current_mouse_capture.is_some()
|| self.dragging.is_some()
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index 39194a85..07df5b8b 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -2883,6 +2883,42 @@ impl crate::TermWindow {
}
}
+ /// A soft shadow falling off the hover-revealed panel's right edge, so
+ /// the overlay reads as a layer floating above the terminal rather than
+ /// a slab butted against it. Only the hover overlay gets this: the
+ /// docked sidebar sits beside the content, not on top of it.
+ ///
+ /// Painted into the same recording as the panel, so it travels with the
+ /// reveal/retreat animation. A run of thin strips with quadratically
+ /// decaying alpha stands in for a gradient.
+ fn paint_workspace_sidebar_hover_shadow(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator,
+ ) -> anyhow::Result<()> {
+ let Some(rect) = self.workspace_sidebar_rect() else {
+ return Ok(());
+ };
+ let edge = rect.x.saturating_add(rect.width) as f32;
+ let top = rect.y as f32;
+ let height = rect.height as f32;
+ let spread = self.ui_f32(16.0);
+ const STEPS: usize = 8;
+ const BASE_ALPHA: f32 = 0.22;
+ let step_width = spread / STEPS as f32;
+ for i in 0..STEPS {
+ let t = (i as f32 + 0.5) / STEPS as f32;
+ let alpha = BASE_ALPHA * (1.0 - t) * (1.0 - t);
+ self.filled_rectangle(
+ layers,
+ 0,
+ euclid::rect(edge + i as f32 * step_width, top, step_width, height),
+ LinearRgba::with_components(0.0, 0.0, 0.0, alpha),
+ )
+ .context("sidebar hover shadow strip")?;
+ }
+ Ok(())
+ }
+
/// Record the hover-revealed sidebar off-screen, holding back its hit
/// targets until after the tab bar has laid out its own.
///
@@ -2903,6 +2939,7 @@ impl crate::TermWindow {
let result = {
let mut sidebar_layers = TripleLayerQuadAllocator::Heap(&mut sidebar_frame);
self.paint_workspace_sidebar(&mut sidebar_layers)
+ .and_then(|_| self.paint_workspace_sidebar_hover_shadow(&mut sidebar_layers))
};
// The marks describe `sidebar_frame`, which the swipe composite below
// may still split; nobody downstream of this fn may.
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 0d25bc5b..dfcf7f0b 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -250,15 +250,21 @@ impl crate::TermWindow {
}
// Either way the hover machine must not act on the pointer still
// sitting where it was: collapsing must not instantly re-reveal, and
- // docking makes the reveal moot.
+ // docking makes the reveal moot. The native titlebar button also
+ // disappears/reappears with this change, so its hover flag would
+ // otherwise go stale (no exit event fires for a removed button).
+ self.titlebar_sidebar_button_hovered = false;
self.workspace_sidebar_hover.suppress_until_pointer_leaves();
}
pub(crate) fn workspace_sidebar_toggle_icon(&self) -> SvgIcon {
- if self.workspace_sidebar_is_presented() {
- SvgIcon::PanelLeftClose
- } else {
+ // Keyed to the DOCKED state, not the transient hover reveal: while
+ // the panel is only hover-previewed the button reads "open", telling
+ // the truth about what a click does (pin it open).
+ if self.workspace_sidebar_collapsed {
SvgIcon::PanelLeftOpen
+ } else {
+ SvgIcon::PanelLeftClose
}
}
@@ -2914,6 +2920,30 @@ impl crate::TermWindow {
let settings_body_width = overview_action_x
.saturating_sub(settings_row_x)
.saturating_sub(self.ui_px(SIDEBAR_INSET) / 2);
+ // When the label cannot fit, the whole row collapses to an
+ // icon-sized pill: a full-width hover capsule around a lone gear
+ // reads as a broken button.
+ let settings_icon_probe = icon_size.min(settings_row_height.saturating_sub(8));
+ let settings_label = crate::i18n::tr("sidebar-settings");
+ let settings_label_x_inset = self.ui_px(SIDEBAR_SETTINGS_ICON_EXTRA_INSET)
+ + settings_icon_probe
+ + self.ui_px(SIDEBAR_ICON_GAP)
+ + 8;
+ let settings_label_fits = self
+ .cached_ui_text_advance(&ui_font, &ui_metrics, &settings_label)
+ .map(|advance| {
+ settings_label_x_inset
+ + (advance.ceil() as usize)
+ + self.ui_px(SIDEBAR_INSET)
+ <= settings_body_width
+ })
+ .unwrap_or(false);
+ let settings_body_width = if settings_label_fits {
+ settings_body_width
+ } else {
+ (self.ui_px(SIDEBAR_SETTINGS_ICON_EXTRA_INSET) * 2 + settings_icon_probe)
+ .min(settings_body_width)
+ };
let settings_hovered = self.is_pointer_over_ui_rect(
settings_row_x,
settings_row_y,
@@ -3062,18 +3092,23 @@ impl crate::TermWindow {
settings_icon_size,
foreground,
)?;
- self.paint_sidebar_text(
- layers,
- &ui_font,
- ui_metrics,
- &crate::i18n::tr("sidebar-settings"),
- settings_text_x,
- settings_text_y,
- settings_body_width
- .saturating_sub(settings_text_x.saturating_sub(settings_row_x))
- .saturating_sub(self.ui_px(SIDEBAR_INSET)),
- foreground,
- )?;
+ // A truncated "S…" reads worse than no label: when the sidebar is
+ // too narrow for the whole word, the gear icon stands alone (and
+ // the row shrank to an icon pill above).
+ if settings_label_fits {
+ self.paint_sidebar_text(
+ layers,
+ &ui_font,
+ ui_metrics,
+ &settings_label,
+ settings_text_x,
+ settings_text_y,
+ settings_body_width
+ .saturating_sub(settings_text_x.saturating_sub(settings_row_x))
+ .saturating_sub(self.ui_px(SIDEBAR_INSET)),
+ foreground,
+ )?;
+ }
let settings_action_icon_size = settings_icon_size;
self.paint_sidebar_icon(
layers,
@@ -3603,14 +3638,13 @@ fn notification_badge_pulse_phase(elapsed: Duration) -> Option<f32> {
/// The `shown` state a sidebar toggle should move to.
///
-/// Split out from [`TermWindow::toggle_workspace_sidebar`] because its two
-/// inputs disagree during a hover reveal — the panel is on screen while
-/// `collapsed` is still true — and that disagreement is exactly where this went
-/// wrong: reading `collapsed` alone turned a click on a button labelled "close"
-/// into a dock.
-fn workspace_sidebar_toggle_target(collapsed: bool, hover_presented: bool) -> bool {
- let presented = !collapsed || hover_presented;
- !presented
+/// Split out from [`TermWindow::toggle_workspace_sidebar`] so the hover-reveal
+/// case has one authoritative answer. The toggle acts on the DOCKED state: a
+/// hover reveal is only a preview, so clicking the button there pins the
+/// panel open instead of retracting it — matching its "open" icon, which is
+/// keyed to the same state ([`TermWindow::workspace_sidebar_toggle_icon`]).
+fn workspace_sidebar_toggle_target(collapsed: bool, _hover_presented: bool) -> bool {
+ collapsed
}
#[cfg(test)]
@@ -3624,13 +3658,13 @@ mod tests {
use std::collections::HashMap;
use std::time::Duration;
- /// Clicking the tab bar's toggle acts on what the user sees. During a hover
- /// reveal the panel is presented while `collapsed` is still true, and the
- /// button reads "close" — so it must collapse, not dock. Docking there also
- /// persisted `show_left_sidebar_by_default`, permanently re-docking the
- /// panel for every future window.
+ /// The toggle acts on the DOCKED state and its icon is keyed to the same
+ /// state. A hover reveal is only a preview: hovering the toggle button
+ /// pops the panel out, and the click that follows must pin it open — a
+ /// hover-then-click that merely retracted the panel would make the
+ /// button do nothing useful while the panel is previewed.
#[test]
- fn toggling_a_hover_revealed_sidebar_collapses_it() {
+ fn toggling_pins_a_hover_revealed_sidebar_open() {
// (collapsed, hover_presented) -> shown
assert!(
!workspace_sidebar_toggle_target(false, false),
@@ -3641,12 +3675,12 @@ mod tests {
"collapsed panel should dock"
);
assert!(
- !workspace_sidebar_toggle_target(true, true),
- "hover-revealed panel should collapse, not dock"
+ workspace_sidebar_toggle_target(true, true),
+ "hover-revealed panel should dock (pin open), not retract"
);
assert!(
!workspace_sidebar_toggle_target(false, true),
- "docked panel under a reveal should still collapse"
+ "docked panel should still collapse regardless of hover state"
);
}
diff --git a/window/src/lib.rs b/window/src/lib.rs
index 816c3b88..7d1fb068 100644
--- a/window/src/lib.rs
+++ b/window/src/lib.rs
@@ -630,6 +630,11 @@ pub enum WindowEvent {
ToggleWorkspaceSidebar,
+ /// The pointer entered (true) or left (false) the native titlebar
+ /// sidebar-toggle button (macOS windowed mode). Lets the GUI's
+ /// hover-reveal treat the native button like its own painted toggles.
+ WorkspaceSidebarButtonHover(bool),
+
Notification(Box<dyn Any + Send + Sync>),
// Called while files are being dragged over the window.
diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs
index 9eadfdc3..54585605 100644
--- a/window/src/os/macos/window.rs
+++ b/window/src/os/macos/window.rs
@@ -69,6 +69,10 @@ const THINKTERM_TITLEBAR_SIDEBAR_BUTTON_FALLBACK_X: f64 = 96.0;
const THINKTERM_TITLEBAR_SIDEBAR_BUTTON_GAP: f64 = 8.0;
const THINKTERM_TITLEBAR_SIDEBAR_BUTTON_SIZE: f64 = 30.0;
const THINKTERM_TITLEBAR_SIDEBAR_BUTTON_TAG: NSInteger = 0x7474_7362;
+/// userInfo marker on the titlebar sidebar button's tracking area, so the
+/// WindowView's mouseEntered:/mouseExited: can tell it apart from the
+/// content view's own tracking area.
+const THINKTERM_TITLEBAR_SIDEBAR_BUTTON_TRACKING_KEY: &str = "thinkterm_sidebar_button";
/// `NSDragOperation` values. The dragging entered/updated methods return this
/// mask, not a BOOL: the runtime reads a full word, so returning a byte-wide
@@ -2208,6 +2212,46 @@ fn install_thinkterm_titlebar_sidebar_button(window: &StrongPtr, target: id) {
}
let () = msg_send![titlebar_view_container_id, addSubview: button];
+
+ // A tracking area owned by the WindowView, so hovering the native
+ // button reaches the GUI as WorkspaceSidebarButtonHover — this is
+ // what lets the hover-reveal treat it like the painted toggles.
+ let info: id = msg_send![class!(NSMutableDictionary), new];
+ let marker_key = nsstring(THINKTERM_TITLEBAR_SIDEBAR_BUTTON_TRACKING_KEY);
+ let marker_val = nsstring("1");
+ let () = msg_send![info, setObject: *marker_val forKey: *marker_key];
+ // NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp
+ // | NSTrackingInVisibleRect
+ let options: NSUInteger = 0x01 | 0x40 | 0x200;
+ let area: id = msg_send![class!(NSTrackingArea), alloc];
+ let area: id = msg_send![
+ area,
+ initWithRect: NSRect::new(NSPoint::new(0.0, 0.0), NSSize::new(0.0, 0.0))
+ options: options
+ owner: target
+ userInfo: info
+ ];
+ let () = msg_send![button, addTrackingArea: area];
+ let () = msg_send![area, release];
+ let () = msg_send![info, release];
+ }
+}
+
+/// Whether this enter/exit event came from the titlebar sidebar button's
+/// tracking area (as opposed to the content view's own).
+fn event_is_sidebar_button_tracking(nsevent: id) -> bool {
+ unsafe {
+ let area: id = msg_send![nsevent, trackingArea];
+ if area.is_null() {
+ return false;
+ }
+ let info: id = msg_send![area, userInfo];
+ if info.is_null() {
+ return false;
+ }
+ let key = nsstring(THINKTERM_TITLEBAR_SIDEBAR_BUTTON_TRACKING_KEY);
+ let val: id = msg_send![info, objectForKey: *key];
+ !val.is_null()
}
}
@@ -3745,13 +3789,29 @@ impl WindowView {
Self::mouse_common(this, nsevent, MouseEventKind::Move, None, None, None);
}
- extern "C" fn mouse_exited(this: &mut Object, _sel: Sel, _nsevent: id) {
+ extern "C" fn mouse_exited(this: &mut Object, _sel: Sel, nsevent: id) {
+ if let Some(myself) = Self::get_this(this) {
+ let event = if event_is_sidebar_button_tracking(nsevent) {
+ WindowEvent::WorkspaceSidebarButtonHover(false)
+ } else {
+ WindowEvent::MouseLeave
+ };
+ myself.inner.borrow_mut().events.dispatch(event);
+ }
+ }
+
+ /// Only the titlebar sidebar button's tracking area is interesting here;
+ /// the content view's own area announces itself through mouseMoved.
+ extern "C" fn mouse_entered(this: &mut Object, _sel: Sel, nsevent: id) {
+ if !event_is_sidebar_button_tracking(nsevent) {
+ return;
+ }
if let Some(myself) = Self::get_this(this) {
myself
.inner
.borrow_mut()
.events
- .dispatch(WindowEvent::MouseLeave);
+ .dispatch(WindowEvent::WorkspaceSidebarButtonHover(true));
}
}
@@ -4778,6 +4838,10 @@ impl WindowView {
sel!(mouseExited:),
Self::mouse_exited as extern "C" fn(&mut Object, Sel, id),
);
+ cls.add_method(
+ sel!(mouseEntered:),
+ Self::mouse_entered as extern "C" fn(&mut Object, Sel, id),
+ );
cls.add_method(
sel!(resetCursorRects),
Self::reset_cursor_rects as extern "C" fn(&mut Object, Sel),