A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
Animate Space switching from the workspace sidebar
RoversXa24f4159d97d
diff --git a/wezterm-gui/src/quad.rs b/wezterm-gui/src/quad.rsindex d51f8978..abb0997b 100644--- a/wezterm-gui/src/quad.rs+++ b/wezterm-gui/src/quad.rs@@ -5,6 +5,7 @@use crate::renderstate::BorrowedLayers;use ::window::bitmaps::TextureRect;use ::window::color::LinearRgba;+use ::window::Dimensions;use config::HsbTransform;/// Each cell is composed of two triangles built from 4 vertices.@@ -110,6 +111,7 @@ pub trait QuadTrait {pub enum QuadImpl<'a> {Vert(Quad<'a>),Boxed(&'a mut BoxedQuad),+ Tee(Quad<'a>, &'a mut BoxedQuad),}impl<'a> QuadTrait for QuadImpl<'a> {@@ -117,6 +119,10 @@ impl<'a> QuadTrait for QuadImpl<'a> {match self {Self::Vert(q) => q.set_texture_discrete(x1, x2, y1, y2),Self::Boxed(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);+ }}}@@ -124,6 +130,10 @@ impl<'a> QuadTrait for QuadImpl<'a> {match self {Self::Vert(q) => q.set_has_color_impl(has_color),Self::Boxed(q) => q.set_has_color_impl(has_color),+ Self::Tee(gpu, heap) => {+ gpu.set_has_color_impl(has_color);+ heap.set_has_color_impl(has_color);+ }}}@@ -131,6 +141,10 @@ impl<'a> QuadTrait for QuadImpl<'a> {match self {Self::Vert(q) => q.set_fg_color(color),Self::Boxed(q) => q.set_fg_color(color),+ Self::Tee(gpu, heap) => {+ gpu.set_fg_color(color);+ heap.set_fg_color(color);+ }}}@@ -138,6 +152,10 @@ impl<'a> QuadTrait for QuadImpl<'a> {match self {Self::Vert(q) => q.set_alt_color_and_mix_value(color, mix_value),Self::Boxed(q) => q.set_alt_color_and_mix_value(color, mix_value),+ Self::Tee(gpu, heap) => {+ gpu.set_alt_color_and_mix_value(color, mix_value);+ heap.set_alt_color_and_mix_value(color, mix_value);+ }}}@@ -145,6 +163,10 @@ impl<'a> QuadTrait for QuadImpl<'a> {match self {Self::Vert(q) => q.set_hsv(hsv),Self::Boxed(q) => q.set_hsv(hsv),+ Self::Tee(gpu, heap) => {+ gpu.set_hsv(hsv);+ heap.set_hsv(hsv);+ }}}@@ -152,6 +174,10 @@ impl<'a> QuadTrait for QuadImpl<'a> {match self {Self::Vert(q) => q.set_position(left, top, right, bottom),Self::Boxed(q) => q.set_position(left, top, right, bottom),+ Self::Tee(gpu, heap) => {+ gpu.set_position(left, top, right, bottom);+ heap.set_position(left, top, right, bottom);+ }}}}@@ -321,6 +347,94 @@ impl std::fmt::Debug for HeapQuadAllocator {}}+/// A clip rectangle in the window-centre-relative space that quad positions+/// live in.+///+/// Every painter goes through `filled_rectangle` and friends, which subtract+/// half the window size from each edge, so a quad's `position` is *not* in the+/// same coordinates as the layout rects (`workspace_sidebar_rect`, the list+/// viewport, …) that describe where it was asked to go. Clipping against an+/// un-rebased rect does not fail loudly: every quad simply falls outside and+/// is dropped. That is how the space-swipe transition once drew an entirely+/// empty sidebar while every offset in the logs looked correct.+///+/// The fields are private and [`Self::from_top_left_pixels`] is the only way+/// in, so layout coordinates cannot reach the clipper by accident. Bands+/// carved out of an existing rect go through [`Self::with_vertical`] /+/// [`Self::with_horizontal`], which inherit the already-converted edges.+#[derive(Debug, Clone, Copy, PartialEq)]+pub struct QuadClipRect {+ left: f32,+ top: f32,+ right: f32,+ bottom: f32,+}++impl QuadClipRect {+ /// Rebase a top-left pixel rect -- sidebar geometry, a list viewport, a+ /// UI item's bounds -- into the quads' own space.+ ///+ /// Takes the window's own [`Dimensions`] rather than a pair of numbers on+ /// purpose: the conversion is only correct against the surface the quads+ /// were laid out for, and a caller with two loose `usize`s can silently+ /// pass the wrong ones (or zeroes) and get a rect that quietly matches+ /// nothing.+ pub fn from_top_left_pixels(+ left: f32,+ top: f32,+ right: f32,+ bottom: f32,+ dimensions: &Dimensions,+ ) -> Self {+ let dx = dimensions.pixel_width as f32 / 2.0;+ let dy = dimensions.pixel_height as f32 / 2.0;+ Self {+ left: left - dx,+ top: top - dy,+ right: right - dx,+ bottom: bottom - dy,+ }+ }++ pub fn left(&self) -> f32 {+ self.left+ }++ pub fn top(&self) -> f32 {+ self.top+ }++ pub fn right(&self) -> f32 {+ self.right+ }++ pub fn bottom(&self) -> f32 {+ self.bottom+ }++ pub fn width(&self) -> f32 {+ self.right - self.left+ }++ /// A horizontal band of this rect. Both edges are already centre-relative.+ pub fn with_vertical(&self, top: f32, bottom: f32) -> Self {+ Self {+ top,+ bottom,+ ..*self+ }+ }++ /// A vertical band of this rect. Both edges are already centre-relative.+ pub fn with_horizontal(&self, left: f32, right: f32) -> Self {+ Self {+ left,+ right,+ ..*self+ }+ }+}+impl HeapQuadAllocator {pub fn apply_to(&self, other: &mut TripleLayerQuadAllocator) -> anyhow::Result<()> {let start = std::time::Instant::now();@@ -332,6 +446,94 @@ impl HeapQuadAllocator {metrics::histogram!("quad_buffer_apply").record(start.elapsed());Ok(())}++ pub fn apply_to_translated_clipped_rect(+ &self,+ other: &mut TripleLayerQuadAllocator,+ offset_x: f32,+ clip: QuadClipRect,+ ) -> anyhow::Result<()> {+ let start = std::time::Instant::now();+ for (layer_num, quads) in [(0, &self.layer0), (1, &self.layer1), (2, &self.layer2)] {+ for quad in quads {+ let Some(vertices) = quad.translated_clipped_vertices(offset_x, clip) else {+ continue;+ };+ other.extend_with(layer_num, &vertices);+ }+ }+ metrics::histogram!("quad_buffer_translated_rect_clip_apply").record(start.elapsed());+ Ok(())+ }+}++impl BoxedQuad {+ fn translated_clipped_vertices(+ &self,+ offset_x: f32,+ clip: QuadClipRect,+ ) -> Option<[Vertex; VERTICES_PER_CELL]> {+ let (clip_left, clip_top, clip_right, clip_bottom) =+ (clip.left(), clip.top(), clip.right(), clip.bottom());+ let (left, top, right, bottom) = self.position;+ let translated_left = left + offset_x;+ let translated_right = right + offset_x;+ if translated_right <= clip_left+ || translated_left >= clip_right+ || bottom <= clip_top+ || top >= clip_bottom+ {+ return None;+ }++ let visible_left = translated_left.max(clip_left);+ let visible_right = translated_right.min(clip_right);+ let visible_top = top.max(clip_top);+ let visible_bottom = bottom.min(clip_bottom);+ if visible_right <= visible_left+ || visible_bottom <= visible_top+ || right <= left+ || bottom <= top+ {+ return None;+ }++ let left_ratio = (visible_left - translated_left) / (translated_right - translated_left);+ let right_ratio = (visible_right - translated_left) / (translated_right - translated_left);+ let top_ratio = (visible_top - top) / (bottom - top);+ let bottom_ratio = (visible_bottom - top) / (bottom - top);+ let (tex_left, tex_right, tex_top, tex_bottom) = self.tex;+ let visible_tex_left = tex_left + (tex_right - tex_left) * left_ratio;+ let visible_tex_right = tex_left + (tex_right - tex_left) * right_ratio;+ let visible_tex_top = tex_top + (tex_bottom - tex_top) * top_ratio;+ let visible_tex_bottom = tex_top + (tex_bottom - tex_top) * bottom_ratio;++ let mut clipped = BoxedQuad {+ position: (visible_left, visible_top, visible_right, visible_bottom),+ fg_color: self.fg_color,+ alt_color: self.alt_color,+ tex: (+ visible_tex_left,+ visible_tex_right,+ visible_tex_top,+ visible_tex_bottom,+ ),+ hsv: self.hsv,+ has_color: self.has_color,+ mix_value: self.mix_value,+ };+ // Preserve a zero-width texture interval exactly for solid-colour+ // quads instead of manufacturing tiny floating-point differences.+ if tex_left == tex_right {+ clipped.tex.0 = tex_left;+ clipped.tex.1 = tex_right;+ }+ if tex_top == tex_bottom {+ clipped.tex.2 = tex_top;+ clipped.tex.3 = tex_bottom;+ }+ Some(clipped.to_vertices())+ }}impl TripleLayerQuadAllocatorTrait for HeapQuadAllocator {@@ -377,6 +579,10 @@ impl TripleLayerQuadAllocatorTrait for HeapQuadAllocator {pub enum TripleLayerQuadAllocator<'a> {Gpu(BorrowedLayers),Heap(&'a mut HeapQuadAllocator),+ Tee {+ gpu: BorrowedLayers,+ heap: &'a mut HeapQuadAllocator,+ },}impl<'a> TripleLayerQuadAllocatorTrait for TripleLayerQuadAllocator<'a> {@@ -384,6 +590,14 @@ impl<'a> TripleLayerQuadAllocatorTrait for TripleLayerQuadAllocator<'a> {match self {Self::Gpu(b) => b.allocate(layer_num),Self::Heap(h) => h.allocate(layer_num),+ Self::Tee { gpu, heap } => {+ let gpu_quad = gpu.allocate(layer_num)?;+ let heap_quad = heap.allocate(layer_num)?;+ match (gpu_quad, heap_quad) {+ (QuadImpl::Vert(gpu), QuadImpl::Boxed(heap)) => Ok(QuadImpl::Tee(gpu, heap)),+ _ => unreachable!("tee allocators must pair GPU and heap quads"),+ }+ }}}@@ -391,6 +605,10 @@ impl<'a> TripleLayerQuadAllocatorTrait for TripleLayerQuadAllocator<'a> {match self {Self::Gpu(b) => b.extend_with(layer_num, vertices),Self::Heap(h) => h.extend_with(layer_num, vertices),+ Self::Tee { gpu, heap } => {+ gpu.extend_with(layer_num, vertices);+ heap.extend_with(layer_num, vertices);+ }}}}@@ -401,3 +619,93 @@ fn size() {assert_eq!(std::mem::size_of::<Vertex>() * VERTICES_PER_CELL, 272);assert_eq!(std::mem::size_of::<BoxedQuad>(), 84);}++#[cfg(test)]+mod translated_clip_tests {+ use super::*;++ /// Fixtures below that predate the rebase work state their coordinates+ /// already centre-relative, so they convert against a zero-sized window.+ const ORIGIN: Dimensions = Dimensions {+ pixel_width: 0,+ pixel_height: 0,+ dpi: 96,+ };++ #[test]+ fn translated_rect_clip_moves_positions_and_crops_texture_coordinates_together() {+ let quad = BoxedQuad {+ position: (10.0, 2.0, 30.0, 8.0),+ tex: (0.2, 0.6, 0.1, 0.9),+ ..Default::default()+ };+ let clip = QuadClipRect::from_top_left_pixels(25.0, 3.0, 35.0, 7.0, &ORIGIN);+ let vertices = quad+ .translated_clipped_vertices(10.0, clip)+ .expect("visible clip");++ assert_eq!(vertices[V_TOP_LEFT].position, [25.0, 3.0]);+ assert_eq!(vertices[V_BOT_RIGHT].position, [35.0, 7.0]);+ assert!((vertices[V_TOP_LEFT].tex[0] - 0.3).abs() < 0.0001);+ assert!((vertices[V_TOP_RIGHT].tex[0] - 0.5).abs() < 0.0001);+ assert!((vertices[V_TOP_LEFT].tex[1] - (0.1 + 0.8 / 6.0)).abs() < 0.0001);+ assert!((vertices[V_BOT_LEFT].tex[1] - (0.9 - 0.8 / 6.0)).abs() < 0.0001);+ }++ /// Regression: the swipe transition built its clip rect straight from the+ /// sidebar's top-left layout geometry and handed it to the quad clipper,+ /// whose quads are window-centre relative. Every one of the ~300 quads+ /// failed the bounds test, so the sidebar drew nothing at all for the+ /// whole 220ms -- with correct-looking offsets in every log. Nothing about+ /// that is visible from inside the clipper, so pin the conversion here.+ #[test]+ fn a_clip_rect_is_useless_until_it_is_rebased_into_the_quads_own_space() {+ let window = Dimensions {+ pixel_width: 2560,+ pixel_height: 1600,+ dpi: 144,+ };+ // A window of zero size is the only way to express the old bug now.+ let no_window = Dimensions {+ pixel_width: 0,+ pixel_height: 0,+ dpi: 144,+ };++ // A sidebar row as a painter would emit it: laid out at top-left+ // pixels x 0..465, y 300..320, then written centre-relative.+ let row = QuadClipRect::from_top_left_pixels(0.0, 300.0, 465.0, 320.0, &window);+ let quad = BoxedQuad {+ position: (row.left(), row.top(), row.right(), row.bottom()),+ ..Default::default()+ };++ // The list viewport in the layout's own coordinates. Used as-is, it+ // silently discards a row that is plainly inside it.+ // `QuadClipRect` has private fields, so this is only expressible in a+ // test that reaches for the raw numbers on purpose.+ let unrebased = QuadClipRect::from_top_left_pixels(0.0, 204.0, 465.0, 1316.0, &no_window);+ assert!(+ quad.translated_clipped_vertices(0.0, unrebased).is_none(),+ "an un-rebased clip rect drops everything -- this is the failure \+ mode, not a healthy result"+ );++ // Rebased against the real window, the row survives.+ let list =+ QuadClipRect::from_top_left_pixels(0.0, 204.0, 465.0, 1316.0, &window);+ assert!(quad.translated_clipped_vertices(0.0, list).is_some());+ }++ #[test]+ fn translated_rect_clip_discards_quads_outside_the_sidebar_page() {+ let quad = BoxedQuad {+ position: (10.0, 2.0, 30.0, 8.0),+ ..Default::default()+ };+ let full = QuadClipRect::from_top_left_pixels(0.0, 0.0, 40.0, 10.0, &ORIGIN);+ let below = QuadClipRect::from_top_left_pixels(0.0, 20.0, 40.0, 30.0, &ORIGIN);+ assert!(quad.translated_clipped_vertices(-100.0, full).is_none());+ assert!(quad.translated_clipped_vertices(0.0, below).is_none());+ }+}diff --git a/wezterm-gui/src/renderstate.rs b/wezterm-gui/src/renderstate.rsindex da865d0d..3fdcf943 100644--- a/wezterm-gui/src/renderstate.rs+++ b/wezterm-gui/src/renderstate.rs@@ -586,6 +586,16 @@ impl RenderLayer {}}+ pub fn tee_quad_allocator<'a>(+ &'a self,+ heap: &'a mut HeapQuadAllocator,+ ) -> TripleLayerQuadAllocator<'a> {+ match self.quad_allocator() {+ TripleLayerQuadAllocator::Gpu(gpu) => TripleLayerQuadAllocator::Tee { gpu, heap },+ _ => unreachable!("render layers always allocate GPU quads"),+ }+ }+pub fn need_more_quads(&self, vb_idx: usize) -> Option<usize> {self.vb.borrow()[vb_idx].need_more_quads()}diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex d5b601dd..419ab1bd 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -9,6 +9,7 @@ use crate::overlay::{start_overlay, start_overlay_pane, CopyModeParams, CopyOverlay, LauncherArgs, LauncherFlags,QuickSelectOverlay,};+use crate::quad::HeapQuadAllocator;use crate::resize_increment_calculator::ResizeIncrementCalculator;use crate::scripting::guiwin::GuiWin;use crate::scrollbar::*;@@ -162,6 +163,7 @@ pub(crate) mod remote_walk;pub mod render;pub mod resize;mod selection;+mod space_swipe;pub mod spawn;pub mod ssh_hosts_view;pub(crate) mod transfer_walk;@@ -1499,6 +1501,16 @@ pub struct TermWindow {workspace_sidebar_pending_thread_selection: Option<String>,workspace_sidebar_collapsed: bool,workspace_sidebar_scroll_offset: f32,+ workspace_sidebar_swipe: space_swipe::SidebarSpaceSwipeState,+ /// A CPU-side copy of the source Space's left sidebar. During a committed+ /// switch only its middle project/thread list viewport is composited beside+ /// the destination; sidebar chrome and the rest of the window stay live.+ workspace_space_swipe_source_frame: Option<HeapQuadAllocator>,+ workspace_space_swipe_capture_source: bool,+ workspace_space_swipe_push_active: bool,+ workspace_space_swipe_direction: f32,+ workspace_space_swipe_pending_commit: Option<(String, f32)>,+ workspace_space_swipe_needs_settle_start: bool,workspace_sidebar_scrollbar_visible_until: Option<Instant>,/// Last notification state painted by this GUI window. Comparing identities/// and statuses (rather than just the count) lets the bell pulse when one@@ -1860,6 +1872,15 @@ impl TermWindow {}}+ fn clear_workspace_space_swipe_frame_transition(&mut self) {+ self.workspace_space_swipe_source_frame = None;+ self.workspace_space_swipe_capture_source = false;+ self.workspace_space_swipe_push_active = false;+ self.workspace_space_swipe_direction = 0.0;+ self.workspace_space_swipe_pending_commit = None;+ self.workspace_space_swipe_needs_settle_start = false;+ }+fn focus_changed(&mut self, focused: bool, window: &Window) {log::trace!("Setting focus to {:?}", focused);self.focused = if focused { Some(Instant::now()) } else { None };@@ -1883,6 +1904,8 @@ impl TermWindow {}if self.focused.is_none() {+ self.workspace_sidebar_swipe.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);self.right_sidebar_note.freeze_live_source();@@ -2270,6 +2293,13 @@ impl TermWindow {workspace_sidebar_pending_thread_selection: None,workspace_sidebar_collapsed: !native_settings.onboarding.show_left_sidebar_by_default,workspace_sidebar_scroll_offset: 0.0,+ workspace_sidebar_swipe: space_swipe::SidebarSpaceSwipeState::default(),+ workspace_space_swipe_source_frame: None,+ workspace_space_swipe_capture_source: false,+ workspace_space_swipe_push_active: false,+ workspace_space_swipe_direction: 0.0,+ workspace_space_swipe_pending_commit: None,+ workspace_space_swipe_needs_settle_start: false,workspace_sidebar_scrollbar_visible_until: None,workspace_notification_snapshot: None,workspace_notification_pulse_started_at: None,@@ -2626,6 +2656,16 @@ impl TermWindow {window_state,live_resizing,} => {+ // Switching Spaces can synchronously trigger a layout/size+ // reconciliation. Preserve the already-committed sidebar+ // transition through that internal resize; otherwise the+ // source and target pages snap before the first animation+ // frame. Interactive/uncommitted gestures are still cancelled+ // when the user actually resizes the window.+ if !self.workspace_sidebar_swipe.is_committing_or_committed() {+ self.workspace_sidebar_swipe.cancel_immediately();+ self.clear_workspace_space_swipe_frame_transition();+ }self.resize(dimensions, window_state, window, live_resizing);Ok(true)}@@ -3707,6 +3747,10 @@ impl TermWindow {preferred_thread: Option<String>,window: &Window,) -> bool {+ if self.workspace_sidebar_swipe.pending_switch_target() != Some(space_id.as_str()) {+ self.workspace_sidebar_swipe.cancel_immediately();+ self.clear_workspace_space_swipe_frame_transition();+ }if self.active_space_id == space_id {if let Some(thread_id) = preferred_thread {self.clear_right_sidebar_text_focus();diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex c35b8ba9..29cbb647 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -1,6 +1,8 @@use crate::frontend::front_end;use crate::tabbar::TabBarItem;use crate::termwindow::content_view::ContentViewId;+#[cfg(target_os = "macos")]+use crate::termwindow::space_swipe::{SidebarSpaceSwipeFinish, SidebarSpaceSwipeUpdate};use crate::termwindow::ui::platform_chrome::WindowTabChromeParams;use crate::termwindow::ui::sidebar::SpaceConnectionState;use crate::termwindow::ui::tokens::{@@ -13,6 +15,8 @@ use crate::termwindow::{PaneDropZone, PaneNavAction, PaneTabDragState, PaneTabDropTarget, PositionedSplit, ScrollHit,TabWheelSurface, TermWindowNotif, UIItem, UIItemType, TMB,};+#[cfg(target_os = "macos")]+use ::window::ScrollPhase;use ::window::{ContextMenuIcon, ContextMenuItem, IntegratedTitleButtonStyle, MouseButtons as WMB, MouseCursor,MouseEvent, MouseEventKind as WMEK, MousePress, WindowOps, WindowState,@@ -790,6 +794,11 @@ impl super::TermWindow {event: &MouseEvent,context: &dyn WindowOps,) -> bool {+ #[cfg(target_os = "macos")]+ if let Some(handled) = self.mouse_wheel_workspace_sidebar_space_swipe(event, context) {+ return handled;+ }+let Some(rect) = self.workspace_sidebar_rect() else {return false;};@@ -816,9 +825,17 @@ impl super::TermWindow {return true;}+ self.scroll_workspace_sidebar_by(delta, context);+ true+ }++ fn scroll_workspace_sidebar_by(&mut self, delta: f32, context: &dyn WindowOps) {+ if delta.abs() <= f32::EPSILON {+ return;+ }let max_offset = self.workspace_sidebar_scroll_max();if max_offset <= 0.0 {- return true;+ return;}self.show_workspace_sidebar_scrollbar();@@ -829,7 +846,249 @@ impl super::TermWindow {} else {context.invalidate();}- true+ }++ #[cfg(target_os = "macos")]+ fn mouse_wheel_workspace_sidebar_space_swipe(+ &mut self,+ event: &MouseEvent,+ context: &dyn WindowOps,+ ) -> Option<bool> {+ if !matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_)) {+ return None;+ }++ if matches!(event.momentum_phase, Some(ScrollPhase::Began)) && event.scroll_phase.is_none()+ {+ // Some macOS trackpads transition directly from Changed into+ // momentum without emitting a scroll-phase Ended event. Treat the+ // beginning of momentum as the finger-up boundary so a horizontal+ // gesture can commit instead of remaining stuck in Tracking.+ self.finish_workspace_sidebar_space_swipe(Instant::now(), context);+ }++ if let Some(momentum_phase) = event.momentum_phase {+ let ended = matches!(momentum_phase, ScrollPhase::Ended | ScrollPhase::Cancelled);+ if self.workspace_sidebar_swipe.consume_momentum(ended) {+ return Some(true);+ }+ }++ let scroll_phase = event.scroll_phase?;+ let (delta_x, delta_y) = event+ .precise_scroll_delta+ .map(|delta| (delta.x, delta.y))+ .unwrap_or((0.0, 0.0));+ let inside_sidebar = self.workspace_sidebar_rect().is_some_and(|rect| {+ let x = event.coords.x;+ let y = event.coords.y;+ 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+ });+ if !inside_sidebar && !self.workspace_sidebar_swipe.is_active() {+ return None;+ }++ let can_begin_without_space_lookup = inside_sidebar+ && !self.workspace_sidebar_collapsed+ && self.context_menu.is_none()+ && self.modal.borrow().is_none()+ && self.inline_tab_rename.is_none()+ && self.current_mouse_capture.is_none()+ && self.dragging.is_none()+ && self.sidebar_row_drag.is_none()+ && self.right_sidebar_file_drag.is_none()+ && self.pane_tab_drag.is_none();+ let now = Instant::now();++ if matches!(scroll_phase, ScrollPhase::MayBegin) {+ if !can_begin_without_space_lookup {+ return None;+ }+ let active_space_is_local =+ crate::workspace_threads::spaces_for_window(self.space_owner_id)+ .iter()+ .any(|space| space.id == self.active_space_id && !space.is_remote);+ if active_space_is_local {+ self.prepare_workspace_space_swipe_source_capture();+ context.invalidate();+ return Some(true);+ }+ return None;+ }++ let needs_begin = matches!(scroll_phase, ScrollPhase::Began)+ || (matches!(scroll_phase, ScrollPhase::Changed)+ && !self.workspace_sidebar_swipe.is_active());+ if needs_begin {+ if !can_begin_without_space_lookup {+ return None;+ }+ if matches!(scroll_phase, ScrollPhase::Began)+ && self.workspace_sidebar_swipe.is_active()+ {+ // A fresh gesture supersedes any unfinished/settling visual+ // from the preceding gesture.+ self.workspace_sidebar_swipe.cancel_immediately();+ self.clear_workspace_space_swipe_frame_transition();+ }+ let spaces = crate::workspace_threads::spaces_for_window(self.space_owner_id);+ if !spaces+ .iter()+ .any(|space| space.id == self.active_space_id && !space.is_remote)+ {+ return None;+ }+ let (previous, next) =+ crate::workspace_threads::adjacent_local_space_ids(&spaces, &self.active_space_id);+ if self.workspace_space_swipe_source_frame.is_none() {+ self.prepare_workspace_space_swipe_source_capture();+ }+ self.workspace_sidebar_swipe.begin(+ self.active_space_id.clone(),+ previous,+ next,+ self.workspace_sidebar_scroll_offset,+ now,+ );+ }++ if matches!(scroll_phase, ScrollPhase::Began | ScrollPhase::Changed)+ && (delta_x.abs() > f32::EPSILON || delta_y.abs() > f32::EPSILON)+ {+ let update = self.workspace_sidebar_swipe.update(delta_x, delta_y, now);+ match update {+ SidebarSpaceSwipeUpdate::Pending => {}+ SidebarSpaceSwipeUpdate::Horizontal => context.invalidate(),+ SidebarSpaceSwipeUpdate::Vertical(delta_y) => {+ self.clear_workspace_space_swipe_frame_transition();+ self.scroll_workspace_sidebar_by(-delta_y, context);+ }+ }+ }++ match scroll_phase {+ ScrollPhase::Ended => {+ self.finish_workspace_sidebar_space_swipe(now, context);+ }+ ScrollPhase::Cancelled => {+ self.workspace_sidebar_swipe.cancel_immediately();+ self.clear_workspace_space_swipe_frame_transition();+ context.invalidate();+ }+ _ => {}+ }++ Some(true)+ }++ #[cfg(target_os = "macos")]+ fn finish_workspace_sidebar_space_swipe(+ &mut self,+ now: Instant,+ context: &dyn WindowOps,+ ) -> bool {+ let width = self.workspace_sidebar_width() as f32;+ let finish = self.workspace_sidebar_swipe.finish(now, width);+ match finish {+ SidebarSpaceSwipeFinish::Switch(target) => {+ let direction = self+ .workspace_sidebar_swipe+ .visual(now, width)+ .map(|visual| visual.offset.signum())+ .unwrap_or(0.0);+ self.workspace_space_swipe_pending_commit = Some((target, direction));+ if self.workspace_space_swipe_source_frame.is_none() {+ // A very fast flick can end before AppKit presents even+ // one source-sidebar paint. Defer the actual Space adoption+ // until paint_pass has mirrored the still-current sidebar;+ // this keeps its list-page transition from degrading into+ // an immediate destination flash.+ self.workspace_space_swipe_capture_source = true;+ } else {+ self.complete_workspace_space_swipe_switch();+ }+ context.invalidate();+ true+ }+ SidebarSpaceSwipeFinish::AnimateBack => {+ self.workspace_sidebar_swipe.cancel_immediately();+ self.clear_workspace_space_swipe_frame_transition();+ context.invalidate();+ true+ }+ SidebarSpaceSwipeFinish::None => {+ // `None` means "this call had no gesture to settle". That is+ // true both when nothing was in flight and when a previous+ // call already moved the state machine into AwaitingCommit or+ // Settling -- macOS routinely delivers a trailing Ended after+ // momentum has already ended the gesture, so this runs a+ // second time right after a commit. Only tear down the frame+ // transition when the state machine really is idle; otherwise+ // the just-committed push is destroyed before its first frame.+ if !self.workspace_sidebar_swipe.is_active() {+ self.clear_workspace_space_swipe_frame_transition();+ }+ false+ }+ }+ }++ #[cfg(target_os = "macos")]+ pub(super) fn complete_workspace_space_swipe_switch(&mut self) {+ let Some((target, direction)) = self.workspace_space_swipe_pending_commit.take() else {+ return;+ };+ let width = self.workspace_sidebar_width() as f32;+ let now = Instant::now();+ let source_is_current = self+ .workspace_sidebar_swipe+ .visual(now, width)+ .is_some_and(|visual| visual.source_space_id == self.active_space_id);+ let target_is_available = crate::workspace_threads::spaces_for_window(self.space_owner_id)+ .iter()+ .any(|space| {+ space.id == target && !space.is_remote && !space.is_occupied_by_other_window+ });+ let gui_window = self.window.clone();+ let switched = source_is_current+ && target_is_available+ && gui_window+ .as_ref()+ .is_some_and(|window| self.switch_space_to_thread(target, None, window));++ self.workspace_space_swipe_push_active =+ switched && direction != 0.0 && self.workspace_space_swipe_source_frame.is_some();+ self.workspace_space_swipe_direction = if self.workspace_space_swipe_push_active {+ direction+ } else {+ 0.0+ };+ self.workspace_space_swipe_capture_source = false;+ self.workspace_space_swipe_needs_settle_start = self.workspace_space_swipe_push_active;+ if !switched {+ self.workspace_sidebar_swipe+ .resolve_switch(false, Instant::now(), width);+ }+ if !self.workspace_space_swipe_push_active {+ self.workspace_sidebar_swipe.cancel_immediately();+ self.workspace_space_swipe_source_frame = None;+ }+ if let Some(window) = gui_window {+ window.invalidate();+ }+ }++ #[cfg(target_os = "macos")]+ fn prepare_workspace_space_swipe_source_capture(&mut self) {+ self.workspace_space_swipe_source_frame = None;+ self.workspace_space_swipe_capture_source = true;+ self.workspace_space_swipe_push_active = false;+ self.workspace_space_swipe_direction = 0.0;+ self.workspace_space_swipe_pending_commit = None;+ self.workspace_space_swipe_needs_settle_start = false;}fn scroll_right_sidebar_note_table_at(&mut self, x: f32, y: f32, delta: f32) -> bool {@@ -1217,6 +1476,32 @@ impl super::TermWindow {}}+ /// Release the pointer-ownership bookkeeping for a `Release` that is+ /// about to be consumed by an early return.+ ///+ /// `mouse_event_impl` normally clears these in its `Release` arm, but two+ /// context-menu paths return before reaching it: the suppressed release+ /// that follows a menu choice, and any release delivered while a menu is+ /// open. Suppressing the *action* is intended; forgetting that the button+ /// physically came up is not. Left armed, `current_mouse_capture` and+ /// `current_mouse_buttons` stay set for the rest of the session and+ /// silently veto every guard that tests them -- which disabled the+ /// sidebar space swipe permanently after any context-menu use.+ fn release_pointer_ownership(&mut self, event: &MouseEvent) {+ if let WMEK::Release(ref press) = event.kind {+ self.current_mouse_capture = None;+ self.current_mouse_buttons.retain(|p| p != press);+ }+ }++ /// Same bookkeeping, for the case where the release will never arrive at+ /// all: a native AppKit menu tracks in a nested event loop that consumes+ /// the mouse-up outright. See the call site in `show_term_context_menu`.+ pub(crate) fn release_pointer_ownership_for_native_menu(&mut self) {+ self.current_mouse_capture = None;+ self.current_mouse_buttons.clear();+ }+pub fn mouse_event_impl(&mut self, event: MouseEvent, context: &dyn WindowOps) {log::trace!("{:?}", event);let pane = self.get_active_pane_or_overlay();@@ -1246,10 +1531,16 @@ impl super::TermWindow {});let terminal_surface = point_is_in_terminal_area&& (self.resolve_ui_item(&event).is_none() || terminal_ui_item);- let takeover_gesture = matches!(- event.kind,- WMEK::Press(_) | WMEK::VertWheel(_) | WMEK::HorzWheel(_)- );+ let wheel_has_motion = match event.kind {+ WMEK::VertWheel(amount) | WMEK::HorzWheel(amount) => {+ amount != 0+ || event.precise_scroll_delta.is_some_and(|delta| {+ delta.x.abs() > f32::EPSILON || delta.y.abs() > f32::EPSILON+ })+ }+ _ => false,+ };+ let takeover_gesture = matches!(event.kind, WMEK::Press(_)) || wheel_has_motion;if terminal_surface && self.frontend_surface_blocked() {if takeover_gesture && self.frontend_takeover_claimable() {@@ -1271,11 +1562,13 @@ impl super::TermWindow {self.current_mouse_event.replace(event.clone());if self.consume_context_menu_suppressed_release(&event) {+ self.release_pointer_ownership(&event);return;}if let Some(pane) = pane.as_ref() {if self.mouse_event_context_menu(&event, pane, context) {+ self.release_pointer_ownership(&event);return;}} else if matches!(diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex 997dfe5a..7512444e 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -1,4 +1,4 @@-use crate::quad::{QuadTrait, TripleLayerQuadAllocator};+use crate::quad::{HeapQuadAllocator, QuadTrait, TripleLayerQuadAllocator};use crate::termwindow::{RenderFrame, TermWindowNotif};use crate::ui::{DrawContext, UiPalette};use ::window::bitmaps::atlas::OutOfTextureSpace;@@ -767,7 +767,52 @@ impl crate::TermWindow {Ok(())}+ 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+ // backend already throttles repaints to+ // min(config.max_fps, this display's refresh rate), so letting it+ // set the pace gives 120Hz on a ProMotion panel, 60Hz on a+ // 60Hz one, and follows the panel when it varies -- whereas the+ // fixed 16ms this replaces pinned every machine to ~60fps. The+ // transition is driven by elapsed time, not by a frame count, so+ // a slower display simply draws fewer frames over the same 220ms.+ //+ // `invalidate` is part of `WindowOps`, so the Windows and Linux+ // gesture backends can reuse this path with their own pacing.+ if let Some(window) = self.window.as_ref() {+ window.invalidate();+ }+ }++ if self.workspace_space_swipe_push_active && !self.workspace_sidebar_swipe.is_active() {+ self.workspace_space_swipe_push_active = false;+ self.workspace_space_swipe_source_frame = None;+ self.workspace_space_swipe_direction = 0.0;+ }+ }++ fn workspace_space_swipe_push_offsets(+ &self,+ now: Instant,+ page_width: f32,+ ) -> Option<(f32, f32)> {+ if !self.workspace_space_swipe_push_active {+ return None;+ }+ let gesture_extent = self.workspace_sidebar_width() as f32;+ let visual = self.workspace_sidebar_swipe.visual(now, gesture_extent)?;+ Some(super::super::space_swipe::sidebar_page_push_offsets(+ visual.offset,+ gesture_extent,+ page_width,+ self.workspace_space_swipe_direction,+ ))+ }+pub fn paint_pass(&mut self) -> anyhow::Result<()> {+ let frame_now = Instant::now();+ self.advance_workspace_space_swipe_push(frame_now);{let gl_state = self.render_state.as_ref().unwrap();for layer in gl_state.layers.borrow().iter() {@@ -938,8 +983,171 @@ impl crate::TermWindow {.context("paint_content_view")?;}- self.paint_workspace_sidebar(&mut layers)- .context("paint_workspace_sidebar")?;+ // Space switching is a left-sidebar interaction. Keep the terminal,+ // tab bar, right sidebar and window chrome on the live GPU path, then+ // isolate just the left sidebar while its middle list page transitions.+ drop(layers);++ let render_space_push = self.workspace_space_swipe_push_active+ && self.workspace_space_swipe_source_frame.is_some();+ let capture_space_source = self.workspace_space_swipe_capture_source && !render_space_push;+ let mut sidebar_frame = HeapQuadAllocator::default();++ if render_space_push {+ let mut sidebar_layers = TripleLayerQuadAllocator::Heap(&mut sidebar_frame);+ self.paint_workspace_sidebar(&mut sidebar_layers)+ .context("paint target workspace sidebar")?;+ drop(sidebar_layers);++ if self.workspace_space_swipe_needs_settle_start {+ let gesture_extent = self.workspace_sidebar_width() as f32;+ self.workspace_sidebar_swipe+ .resolve_switch(true, Instant::now(), gesture_extent);+ self.workspace_space_swipe_needs_settle_start = false;+ // The settle clock does not start until the *next* frame (see+ // `Settle::started`), so this frame only has to make sure a+ // next frame happens; `advance` paces everything after it.+ if let Some(window) = self.window.as_ref() {+ window.invalidate();+ }+ }++ let mut gpu_layers = layer.quad_allocator();+ let sidebar_rect = self.workspace_sidebar_rect();+ let list_viewport = self.workspace_sidebar_list_viewport();+ if let (Some(rect), Some((list_top, list_bottom))) = (sidebar_rect, list_viewport) {+ // Quad positions are window-centre relative (see+ // `filled_rectangle`), while the sidebar rect and list+ // viewport are top-left pixel coordinates. Rebase the clip+ // rect into the quads' space, otherwise every quad fails the+ // bounds test and the sidebar renders empty for the whole+ // transition.+ let list_clip = crate::quad::QuadClipRect::from_top_left_pixels(+ rect.x as f32,+ list_top.max(0) as f32,+ rect.x.saturating_add(rect.width) as f32,+ list_bottom.max(list_top) as f32,+ &self.dimensions,+ );+ let (clip_left, clip_top, clip_right, clip_bottom) = (+ list_clip.left(),+ list_clip.top(),+ list_clip.right(),+ list_clip.bottom(),+ );+ let top_offset = self.dimensions.pixel_height as f32 / 2.0;+ let window_top = -top_offset;+ // The one-pixel separator is sidebar chrome, not page content.+ let page_right = (clip_right - 1.0).max(clip_left);+ // The settings row is lifted above `content_bottom` and the+ // scroll fade higher still, so the stationary band starts+ // above the list's own bottom edge and is drawn over the+ // moving pages rather than beside them.+ let footer_chrome_top = self+ .workspace_sidebar_footer_chrome_top()+ .map(|top| top.max(list_top) as f32 - top_offset)+ .unwrap_or(clip_bottom)+ .min(clip_bottom);+ let sidebar_bottom = rect.y.saturating_add(rect.height) as f32 - top_offset;+ let page_width = page_right - clip_left;++ // The pages stop where the stationary footer band begins, not+ // at the list's own bottom edge. Overlapping the two bands+ // leaves a moving sliver of the outgoing settings row visible+ // whenever the footer's fade is absent (it is only drawn when+ // the list actually scrolls), so the footer must own that+ // strip outright.+ let page_bottom = footer_chrome_top;+ let page_clip = list_clip+ .with_horizontal(clip_left, page_right)+ .with_vertical(clip_top, page_bottom);+ let offsets = self+ .workspace_space_swipe_push_offsets(Instant::now(), page_width)+ .filter(|_| page_width > 0.0 && page_bottom > clip_top);++ if let Some((source_offset, target_offset)) = offsets {+ // Paint the target sidebar chrome in place. Only the+ // project/thread list viewport below is double-buffered.+ sidebar_frame+ .apply_to_translated_clipped_rect(+ &mut gpu_layers,+ 0.0,+ list_clip.with_vertical(window_top, clip_top),+ )+ .context("space swipe stationary sidebar header")?;+ sidebar_frame+ .apply_to_translated_clipped_rect(+ &mut gpu_layers,+ 0.0,+ list_clip.with_horizontal(page_right, clip_right),+ )+ .context("space swipe stationary sidebar separator")?;+ if let Some(source) = self.workspace_space_swipe_source_frame.as_ref() {+ source+ .apply_to_translated_clipped_rect(+ &mut gpu_layers,+ source_offset,+ page_clip,+ )+ .context("space swipe source sidebar page")?;+ }+ sidebar_frame+ .apply_to_translated_clipped_rect(+ &mut gpu_layers,+ target_offset,+ page_clip,+ )+ .context("space swipe target sidebar page")?;++ // Drawn last: the settings row is lifted above+ // `content_bottom` and the scroll fade sits above that, so+ // this band overlaps the moving pages instead of abutting+ // them. Compositing it after the pages keeps the footer+ // whole and lets its fade mask the content sliding beneath.+ sidebar_frame+ .apply_to_translated_clipped_rect(+ &mut gpu_layers,+ 0.0,+ list_clip.with_vertical(footer_chrome_top, sidebar_bottom),+ )+ .context("space swipe stationary sidebar footer")?;+ } else {+ sidebar_frame+ .apply_to(&mut gpu_layers)+ .context("space swipe target sidebar fallback")?;+ }+ } else {+ sidebar_frame+ .apply_to(&mut gpu_layers)+ .context("space swipe target sidebar without viewport")?;+ }+ drop(gpu_layers);+ } else if capture_space_source {+ let mut sidebar_layers = layer.tee_quad_allocator(&mut sidebar_frame);+ self.paint_workspace_sidebar(&mut sidebar_layers)+ .context("capture source workspace sidebar")?;+ drop(sidebar_layers);++ self.workspace_space_swipe_source_frame = Some(sidebar_frame);+ 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(crate::termwindow::TermWindowNotif::Apply(Box::new(+ |term_window| {+ term_window.complete_workspace_space_swipe_switch();+ },+ )));+ }+ }+ } else {+ let mut sidebar_layers = layer.quad_allocator();+ self.paint_workspace_sidebar(&mut sidebar_layers)+ .context("paint_workspace_sidebar")?;+ drop(sidebar_layers);+ }++ let mut layers = layer.quad_allocator();self.paint_right_sidebar(&mut layers).context("paint_right_sidebar")?;@@ -950,6 +1158,7 @@ impl crate::TermWindow {self.paint_window_borders(&mut layers).context("paint_window_borders")?;drop(layers);+self.paint_modal().context("paint_modal")?;self.paint_context_menu().context("paint_context_menu")?;self.paint_pane_tab_drag_overlay()diff --git a/wezterm-gui/src/termwindow/space_swipe.rs b/wezterm-gui/src/termwindow/space_swipe.rsnew file mode 100644index 00000000..84e7f0b1--- /dev/null+++ b/wezterm-gui/src/termwindow/space_swipe.rs@@ -0,0 +1,773 @@+use std::time::{Duration, Instant};++const HORIZONTAL_LOCK_DISTANCE: f32 = 8.0;+const VERTICAL_LOCK_DISTANCE: f32 = 18.0;+const AXIS_LOCK_RATIO: f32 = 1.15;+const AXIS_LOCK_FALLBACK_DISTANCE: f32 = 32.0;+const EDGE_RESISTANCE: f32 = 0.25;+const EDGE_MAX_OFFSET: f32 = 48.0;+const COMMIT_DISTANCE_RATIO: f32 = 0.28;+const COMMIT_MIN_FLING_DISTANCE: f32 = 16.0;+const COMMIT_VELOCITY: f32 = 600.0;+const SETTLE_DURATION: Duration = Duration::from_millis(220);++pub(crate) fn sidebar_page_push_offsets(+ visual_offset: f32,+ gesture_extent: f32,+ page_width: f32,+ direction: f32,+) -> (f32, f32) {+ if gesture_extent <= 0.0 || page_width <= 0.0 || direction == 0.0 {+ return (0.0, 0.0);+ }++ let direction = direction.signum();+ let progress = (visual_offset.abs() / gesture_extent).clamp(0.0, 1.0);+ let source = direction * page_width * progress;+ let target = source - direction * page_width;+ (source, target)+}++#[derive(Debug, Clone, Copy, PartialEq)]+pub(crate) enum SidebarSpaceSwipeUpdate {+ Pending,+ Horizontal,+ Vertical(f32),+}++#[derive(Debug, Clone, PartialEq, Eq)]+pub(crate) enum SidebarSpaceSwipeFinish {+ None,+ Switch(String),+ AnimateBack,+}++#[derive(Debug, Clone, PartialEq)]+pub(crate) struct SidebarSpaceSwipeVisual {+ pub(crate) source_space_id: String,+ pub(crate) target_space_id: Option<String>,+ pub(crate) source_scroll_offset: f32,+ pub(crate) offset: f32,+}++#[derive(Debug, Clone)]+struct Gesture {+ source_space_id: String,+ previous_space_id: Option<String>,+ next_space_id: Option<String>,+ source_scroll_offset: f32,+ raw_x: f32,+ raw_y: f32,+ velocity_x: f32,+ last_sample_at: Instant,+}++impl Gesture {+ fn new(+ source_space_id: String,+ previous_space_id: Option<String>,+ next_space_id: Option<String>,+ source_scroll_offset: f32,+ now: Instant,+ ) -> Self {+ Self {+ source_space_id,+ previous_space_id,+ next_space_id,+ source_scroll_offset,+ raw_x: 0.0,+ raw_y: 0.0,+ velocity_x: 0.0,+ last_sample_at: now,+ }+ }++ fn update(&mut self, delta_x: f32, delta_y: f32, now: Instant) {+ let dt = now+ .saturating_duration_since(self.last_sample_at)+ .as_secs_f32()+ .clamp(1.0 / 240.0, 1.0 / 20.0);+ self.last_sample_at = now;+ self.raw_x += delta_x;+ self.raw_y += delta_y;++ let instantaneous = delta_x / dt;+ self.velocity_x = self.velocity_x * 0.65 + instantaneous * 0.35;+ }++ fn target_space_id(&self) -> Option<&String> {+ if self.raw_x < 0.0 {+ self.next_space_id.as_ref()+ } else if self.raw_x > 0.0 {+ self.previous_space_id.as_ref()+ } else {+ None+ }+ }++ fn display_offset(&self, sidebar_width: f32) -> f32 {+ if self.raw_x < 0.0 {+ if self.next_space_id.is_some() {+ self.raw_x.max(-sidebar_width)+ } else {+ (self.raw_x * EDGE_RESISTANCE).max(-EDGE_MAX_OFFSET)+ }+ } else if self.raw_x > 0.0 {+ if self.previous_space_id.is_some() {+ self.raw_x.min(sidebar_width)+ } else {+ (self.raw_x * EDGE_RESISTANCE).min(EDGE_MAX_OFFSET)+ }+ } else {+ 0.0+ }+ }++ fn target_offset(&self, sidebar_width: f32) -> f32 {+ if self.raw_x < 0.0 {+ -sidebar_width+ } else {+ sidebar_width+ }+ }++ fn should_commit(&self, sidebar_width: f32) -> bool {+ if self.target_space_id().is_none() {+ return false;+ }++ let distance_commit =+ self.display_offset(sidebar_width).abs() >= sidebar_width * COMMIT_DISTANCE_RATIO;+ let velocity_toward_target = if self.raw_x < 0.0 {+ -self.velocity_x+ } else {+ self.velocity_x+ };+ let fling_commit = self.raw_x.abs() >= COMMIT_MIN_FLING_DISTANCE+ && velocity_toward_target >= COMMIT_VELOCITY;+ distance_commit || fling_commit+ }+}++#[derive(Debug, Clone)]+struct Settle {+ source_space_id: String,+ target_space_id: Option<String>,+ source_scroll_offset: f32,+ from: f32,+ to: f32,+ started_at: Instant,+ /// The frame that first shows `from` is also the frame that adopts the+ /// destination Space, so it pays for its glyph rasterisation and atlas+ /// growth -- routinely 100ms+, roughly half the transition. Holding the+ /// clock until the *next* frame starts keeps that cost out of the+ /// animation instead of letting it swallow the opening frames.+ started: bool,+ committed: bool,+}++#[derive(Debug, Clone)]+enum Phase {+ Idle,+ Candidate(Gesture),+ Vertical,+ Tracking(Gesture),+ AwaitingCommit(Gesture),+ Settling(Settle),+}++impl Default for Phase {+ fn default() -> Self {+ Self::Idle+ }+}++#[derive(Debug, Clone, Default)]+pub(crate) struct SidebarSpaceSwipeState {+ phase: Phase,+ suppress_momentum: bool,+}++impl SidebarSpaceSwipeState {+ pub(crate) fn begin(+ &mut self,+ source_space_id: String,+ previous_space_id: Option<String>,+ next_space_id: Option<String>,+ source_scroll_offset: f32,+ now: Instant,+ ) -> bool {+ if !matches!(self.phase, Phase::Idle) {+ return false;+ }+ self.suppress_momentum = false;+ self.phase = Phase::Candidate(Gesture::new(+ source_space_id,+ previous_space_id,+ next_space_id,+ source_scroll_offset,+ now,+ ));+ true+ }++ pub(crate) fn update(+ &mut self,+ delta_x: f32,+ delta_y: f32,+ now: Instant,+ ) -> SidebarSpaceSwipeUpdate {+ let phase = std::mem::take(&mut self.phase);+ match phase {+ Phase::Candidate(mut gesture) => {+ gesture.update(delta_x, delta_y, now);+ let x = gesture.raw_x.abs();+ let y = gesture.raw_y.abs();+ let max_axis = x.max(y);++ if x >= HORIZONTAL_LOCK_DISTANCE && x > y * AXIS_LOCK_RATIO {+ self.phase = Phase::Tracking(gesture);+ SidebarSpaceSwipeUpdate::Horizontal+ } else if y >= VERTICAL_LOCK_DISTANCE && y > x * AXIS_LOCK_RATIO {+ self.phase = Phase::Vertical;+ SidebarSpaceSwipeUpdate::Vertical(gesture.raw_y)+ } else if max_axis >= AXIS_LOCK_FALLBACK_DISTANCE && x >= y {+ self.phase = Phase::Tracking(gesture);+ SidebarSpaceSwipeUpdate::Horizontal+ } else if max_axis >= AXIS_LOCK_FALLBACK_DISTANCE {+ self.phase = Phase::Vertical;+ SidebarSpaceSwipeUpdate::Vertical(gesture.raw_y)+ } else {+ self.phase = Phase::Candidate(gesture);+ SidebarSpaceSwipeUpdate::Pending+ }+ }+ Phase::Tracking(mut gesture) => {+ gesture.update(delta_x, delta_y, now);+ self.phase = Phase::Tracking(gesture);+ SidebarSpaceSwipeUpdate::Horizontal+ }+ Phase::Vertical => {+ self.phase = Phase::Vertical;+ SidebarSpaceSwipeUpdate::Vertical(delta_y)+ }+ other => {+ self.phase = other;+ SidebarSpaceSwipeUpdate::Pending+ }+ }+ }++ pub(crate) fn finish(&mut self, now: Instant, sidebar_width: f32) -> SidebarSpaceSwipeFinish {+ let phase = std::mem::take(&mut self.phase);+ match phase {+ Phase::Tracking(gesture) if gesture.should_commit(sidebar_width) => {+ self.suppress_momentum = true;+ let target = gesture.target_space_id().cloned().expect("checked above");+ self.phase = Phase::AwaitingCommit(gesture);+ SidebarSpaceSwipeFinish::Switch(target)+ }+ Phase::Tracking(gesture) => {+ self.suppress_momentum = true;+ let from = gesture.display_offset(sidebar_width);+ let target_space_id = gesture.target_space_id().cloned();+ self.phase = Phase::Settling(Settle {+ source_space_id: gesture.source_space_id,+ target_space_id,+ source_scroll_offset: gesture.source_scroll_offset,+ from,+ to: 0.0,+ started_at: now,+ started: true,+ committed: false,+ });+ SidebarSpaceSwipeFinish::AnimateBack+ }+ Phase::Candidate(_) | Phase::Vertical => {+ self.phase = Phase::Idle;+ self.suppress_momentum = false;+ SidebarSpaceSwipeFinish::None+ }+ other => {+ self.phase = other;+ SidebarSpaceSwipeFinish::None+ }+ }+ }++ pub(crate) fn resolve_switch(&mut self, switched: bool, now: Instant, sidebar_width: f32) {+ let phase = std::mem::take(&mut self.phase);+ match phase {+ Phase::AwaitingCommit(gesture) => {+ // The renderer captures the source sidebar, adopts and paints+ // the destination, and only then resolves the switch. Always+ // start the list-page push at rest so destination preparation+ // cannot consume or skip its opening frames.+ let from = if switched {+ 0.0+ } else {+ gesture.display_offset(sidebar_width)+ };+ let target_space_id = gesture.target_space_id().cloned();+ let target_offset = gesture.target_offset(sidebar_width);+ self.phase = Phase::Settling(Settle {+ source_space_id: gesture.source_space_id,+ target_space_id,+ source_scroll_offset: gesture.source_scroll_offset,+ from,+ to: if switched { target_offset } else { 0.0 },+ started_at: now,+ // A committed switch defers its clock to the next frame;+ // a rejected one has nothing expensive to wait for.+ started: !switched,+ committed: switched,+ });+ }+ other => self.phase = other,+ }+ }++ pub(crate) fn cancel_immediately(&mut self) {+ self.phase = Phase::Idle;+ self.suppress_momentum = false;+ }++ pub(crate) fn advance(&mut self, now: Instant) -> bool {+ let phase = std::mem::take(&mut self.phase);+ let Phase::Settling(mut settle) = phase else {+ self.phase = phase;+ return false;+ };++ if !settle.started {+ // The opening frame has been presented; start timing from here.+ settle.started = true;+ settle.started_at = now;+ self.phase = Phase::Settling(settle);+ return true;+ }++ let elapsed = now.saturating_duration_since(settle.started_at);+ if elapsed >= SETTLE_DURATION {+ self.phase = Phase::Idle;+ return false;+ }++ self.phase = Phase::Settling(settle);+ true+ }++ pub(crate) fn visual(+ &self,+ now: Instant,+ sidebar_width: f32,+ ) -> Option<SidebarSpaceSwipeVisual> {+ match &self.phase {+ Phase::Tracking(gesture) | Phase::AwaitingCommit(gesture) => {+ Some(SidebarSpaceSwipeVisual {+ source_space_id: gesture.source_space_id.clone(),+ target_space_id: gesture.target_space_id().cloned(),+ source_scroll_offset: gesture.source_scroll_offset,+ offset: gesture.display_offset(sidebar_width),+ })+ }+ Phase::Settling(settle) => {+ let raw_t = if settle.started {+ now.saturating_duration_since(settle.started_at).as_secs_f32()+ / SETTLE_DURATION.as_secs_f32()+ } else {+ // Clock not running yet: hold the opening position.+ 0.0+ };+ let t = raw_t.clamp(0.0, 1.0);+ let eased = 1.0 - (1.0 - t).powi(3);+ Some(SidebarSpaceSwipeVisual {+ source_space_id: settle.source_space_id.clone(),+ target_space_id: settle.target_space_id.clone(),+ source_scroll_offset: settle.source_scroll_offset,+ offset: settle.from + (settle.to - settle.from) * eased,+ })+ }+ _ => None,+ }+ }++ pub(crate) fn is_active(&self) -> bool {+ !matches!(self.phase, Phase::Idle)+ }++ pub(crate) fn is_committing_or_committed(&self) -> bool {+ matches!(+ &self.phase,+ Phase::AwaitingCommit(_)+ | Phase::Settling(Settle {+ committed: true,+ ..+ })+ )+ }++ pub(crate) fn pending_switch_target(&self) -> Option<&str> {+ match &self.phase {+ Phase::AwaitingCommit(gesture) => gesture.target_space_id().map(String::as_str),+ _ => None,+ }+ }++ pub(crate) fn consume_momentum(&mut self, ended: bool) -> bool {+ let consume = self.suppress_momentum || self.is_active();+ if ended {+ self.suppress_momentum = false;+ }+ consume+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ fn at(start: Instant, millis: u64) -> Instant {+ start + Duration::from_millis(millis)+ }++ #[test]+ fn sidebar_page_push_tiles_source_and_target_across_the_list_viewport() {+ assert_eq!(+ sidebar_page_push_offsets(-150.0, 300.0, 300.0, -1.0),+ (-150.0, 150.0)+ );+ assert_eq!(+ sidebar_page_push_offsets(300.0, 300.0, 300.0, 1.0),+ (300.0, 0.0)+ );+ }++ #[test]+ fn horizontal_gesture_tracks_then_commits_by_distance() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ assert!(swipe.begin(+ "source".into(),+ Some("previous".into()),+ Some("next".into()),+ 0.0,+ start,+ ));+ assert_eq!(+ swipe.update(-4.0, 1.0, at(start, 8)),+ SidebarSpaceSwipeUpdate::Pending+ );+ assert_eq!(+ swipe.update(-92.0, 1.0, at(start, 24)),+ SidebarSpaceSwipeUpdate::Horizontal+ );+ assert_eq!(+ swipe.visual(at(start, 24), 300.0),+ Some(SidebarSpaceSwipeVisual {+ source_space_id: "source".into(),+ target_space_id: Some("next".into()),+ source_scroll_offset: 0.0,+ offset: -96.0,+ })+ );+ assert_eq!(+ swipe.finish(at(start, 30), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ swipe.resolve_switch(true, at(start, 30), 300.0);+ // The frame that commits renders the opening position; `advance`, run+ // at the top of each paint, starts the clock on the frame after it.+ assert_eq!(swipe.visual(at(start, 30), 300.0).unwrap().offset, 0.0);+ assert!(swipe.advance(at(start, 100)));+ assert!(swipe.visual(at(start, 200), 300.0).unwrap().offset < -96.0);+ assert!(!swipe.advance(at(start, 340)));+ }++ #[test]+ fn vertical_axis_stays_vertical_for_the_whole_gesture() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ assert_eq!(+ swipe.update(2.0, -20.0, at(start, 16)),+ SidebarSpaceSwipeUpdate::Vertical(-20.0)+ );+ assert_eq!(+ swipe.update(-40.0, 1.0, at(start, 32)),+ SidebarSpaceSwipeUpdate::Vertical(1.0)+ );+ assert_eq!(swipe.visual(at(start, 32), 300.0), None);+ assert_eq!(+ swipe.finish(at(start, 40), 300.0),+ SidebarSpaceSwipeFinish::None+ );+ }++ #[test]+ fn early_vertical_noise_does_not_steal_a_horizontal_swipe() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);++ assert_eq!(+ swipe.update(-1.0, 5.0, at(start, 8)),+ SidebarSpaceSwipeUpdate::Pending+ );+ assert_eq!(+ swipe.update(-2.0, 5.0, at(start, 16)),+ SidebarSpaceSwipeUpdate::Pending+ );+ assert_eq!(+ swipe.update(-12.0, 2.0, at(start, 24)),+ SidebarSpaceSwipeUpdate::Horizontal+ );+ assert_eq!(swipe.visual(at(start, 24), 300.0).unwrap().offset, -15.0);+ }++ #[test]+ fn short_slow_drag_animates_back_without_switching() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-20.0, 0.0, at(start, 100));+ assert_eq!(+ swipe.finish(at(start, 200), 300.0),+ SidebarSpaceSwipeFinish::AnimateBack+ );+ let before = swipe.visual(at(start, 200), 300.0).unwrap().offset;+ let after = swipe.visual(at(start, 300), 300.0).unwrap().offset;+ assert!(before < 0.0);+ assert!(after > before);+ }++ #[test]+ fn quick_flick_commits_before_the_distance_threshold() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-10.0, 0.0, at(start, 8));+ swipe.update(-10.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ }++ #[test]+ fn unavailable_edge_is_resisted_and_never_commits() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(400.0, 0.0, at(start, 16));+ let visual = swipe.visual(at(start, 16), 300.0).unwrap();+ assert_eq!(visual.target_space_id, None);+ assert_eq!(visual.offset, 48.0);+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::AnimateBack+ );+ }++ #[test]+ fn momentum_is_suppressed_after_a_completed_gesture() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-20.0, 0.0, at(start, 16));+ swipe.finish(at(start, 20), 300.0);+ assert!(swipe.consume_momentum(false));+ assert!(swipe.consume_momentum(true));+ swipe.cancel_immediately();+ assert!(!swipe.consume_momentum(false));+ }++ #[test]+ fn a_rejected_switch_returns_to_the_source_and_cannot_commit_twice() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 23.0, start);+ swipe.update(-120.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ assert_eq!(+ swipe.finish(at(start, 21), 300.0),+ SidebarSpaceSwipeFinish::None+ );++ swipe.resolve_switch(false, at(start, 24), 300.0);+ let visual = swipe.visual(at(start, 100), 300.0).unwrap();+ assert_eq!(visual.source_scroll_offset, 23.0);+ assert!(visual.offset > -120.0);+ assert!(visual.offset < 0.0);+ }++ #[test]+ fn committed_settle_survives_layout_sync_until_the_animation_finishes() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-120.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ swipe.resolve_switch(true, at(start, 20), 300.0);++ assert!(swipe.is_committing_or_committed());+ // First paint after the commit: starts the clock, nothing elapsed yet.+ assert!(swipe.advance(at(start, 120)));+ assert!(swipe.is_committing_or_committed());+ assert!(swipe.advance(at(start, 250)));+ assert!(swipe.is_committing_or_committed());+ assert!(!swipe.advance(at(start, 350)));+ assert!(!swipe.is_committing_or_committed());+ }++ #[test]+ fn awaiting_commit_is_preserved_during_the_switch_layout_sync() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-120.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );++ // switch_space_to_thread can synchronously cause a Resized event+ // before resolve_switch records the successful commit.+ assert!(swipe.is_committing_or_committed());+ swipe.resolve_switch(true, at(start, 20), 300.0);+ assert!(swipe.is_committing_or_committed());+ }++ #[test]+ fn committed_animation_clock_starts_after_slow_space_adoption() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-120.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );++ // Model a destination adoption that takes much longer than the visual+ // transition. Resolution supplies a fresh clock after that work.+ let adoption_finished = at(start, 1_000);+ swipe.resolve_switch(true, adoption_finished, 300.0);+ assert!(swipe.advance(adoption_finished));+ assert_eq!(swipe.visual(adoption_finished, 300.0).unwrap().offset, 0.0);+ assert!(swipe.advance(at(start, 1_100)));+ assert!(!swipe.advance(at(start, 1_250)));+ }++ #[test]+ fn unpainted_full_distance_swipe_still_has_a_visible_commit_animation() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-500.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ swipe.resolve_switch(true, at(start, 1_000), 300.0);++ let first = swipe.visual(at(start, 1_000), 300.0).unwrap().offset;+ assert_eq!(first, 0.0);+ assert!(swipe.advance(at(start, 1_000)));+ let middle = swipe.visual(at(start, 1_100), 300.0).unwrap().offset;+ let last = swipe.visual(at(start, 1_220), 300.0).unwrap().offset;+ assert!(middle < first && middle > -300.0);+ assert_eq!(last, -300.0);+ }++ /// Regression: macOS routinely delivers a trailing `Ended` after momentum+ /// has already ended the gesture, so `finish` runs a second time moments+ /// after a commit. That second call has nothing to settle and returns+ /// `None` -- which the caller read as "no gesture in flight" and used to+ /// tear down the frame transition, destroying the just-committed animation+ /// before its first frame. `None` must therefore leave an in-flight settle+ /// completely untouched, and `is_active` must stay true so the caller can+ /// tell "nothing to do" apart from "nothing here".+ #[test]+ fn a_second_finish_after_committing_reports_none_without_disturbing_the_settle() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-120.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );++ // Trailing Ended, still in AwaitingCommit.+ assert_eq!(swipe.finish(at(start, 21), 300.0), SidebarSpaceSwipeFinish::None);+ assert!(swipe.is_active());+ assert!(swipe.is_committing_or_committed());+ assert_eq!(swipe.pending_switch_target(), Some("next"));++ swipe.resolve_switch(true, at(start, 22), 300.0);+ assert!(swipe.advance(at(start, 30)));++ // And again once the settle is running.+ assert_eq!(swipe.finish(at(start, 40), 300.0), SidebarSpaceSwipeFinish::None);+ assert!(swipe.is_active());+ assert!(swipe.is_committing_or_committed());+ let mid = swipe.visual(at(start, 120), 300.0).expect("settle still live");+ assert!(mid.offset < 0.0 && mid.offset > -300.0);++ // An idle machine is the only case where `None` really means empty.+ swipe.cancel_immediately();+ assert_eq!(swipe.finish(at(start, 50), 300.0), SidebarSpaceSwipeFinish::None);+ assert!(!swipe.is_active());+ }++ /// The commit frame adopts the destination Space, so it can take 100ms+ of+ /// glyph rasterisation before it reaches the screen. That cost must not be+ /// billed to the 220ms transition, or the first visible motion jumps+ /// straight to ~87% and the swipe reads as an instant cut.+ #[test]+ fn a_slow_commit_frame_does_not_consume_the_transition() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-120.0, 0.0, at(start, 16));+ assert_eq!(+ swipe.finish(at(start, 20), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ swipe.resolve_switch(true, at(start, 20), 300.0);++ // That first frame takes 500ms to present.+ let after_slow_frame = at(start, 520);+ assert!(swipe.advance(after_slow_frame));+ assert_eq!(swipe.visual(after_slow_frame, 300.0).unwrap().offset, 0.0);++ // A full 220ms of travel is still ahead, measured from that point.+ let mid = swipe.visual(at(start, 520 + 110), 300.0).unwrap().offset;+ assert!(mid < 0.0 && mid > -300.0);+ assert!(swipe.advance(at(start, 520 + 200)));+ assert!(!swipe.advance(at(start, 520 + 240)));+ }++ #[test]+ fn committed_push_starts_at_rest_after_destination_preparation() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);+ swipe.update(-40.0, 0.0, at(start, 16));+ swipe.update(-40.0, 0.0, at(start, 48));+ swipe.update(-40.0, 0.0, at(start, 80));+ assert_eq!(+ swipe.finish(at(start, 90), 300.0),+ SidebarSpaceSwipeFinish::Switch("next".into())+ );+ swipe.resolve_switch(true, at(start, 100), 300.0);+ assert_eq!(swipe.visual(at(start, 100), 300.0).unwrap().offset, 0.0);+ }+}diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rsindex 01dc7dc1..827d1276 100644--- a/wezterm-gui/src/termwindow/ui/context_menu.rs+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs@@ -296,6 +296,13 @@ impl crate::TermWindow {}if cfg!(target_os = "macos") && !crate::native_settings::force_fallback_context_menu() {+ // AppKit tracks a native menu in a nested event loop that eats the+ // mouse-up belonging to the click that opened it, and only reports+ // back via `ContextMenuDismissed` when the menu closed *without* a+ // selection. Choosing an item therefore leaves us believing the+ // 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();context.show_context_menu(coords, items);return;}diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rsindex ceca52d1..cdcc85de 100644--- a/wezterm-gui/src/termwindow/ui/sidebar.rs+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs@@ -182,6 +182,8 @@ impl crate::TermWindow {}pub fn toggle_workspace_sidebar(&mut self) {+ self.workspace_sidebar_swipe.cancel_immediately();+ self.clear_workspace_space_swipe_frame_transition();self.workspace_sidebar_collapsed = !self.workspace_sidebar_collapsed;}@@ -733,6 +735,39 @@ impl crate::TermWindow {Some((layout.list_top as isize, layout.content_bottom as isize))}+ /// Top of the band that belongs to the stationary footer rather than the+ /// scrolling list. `content_bottom` is *not* that boundary: the settings+ /// row is deliberately lifted above `settings_footer_y`, and the scroll+ /// fade sits higher still. A space-swipe transition that splits the+ /// sidebar at `content_bottom` therefore slices those elements in half —+ /// the lower part stays put while the upper sliver slides away with the+ /// page. Everything from here down must be composited in place.+ pub(crate) fn workspace_sidebar_footer_chrome_top(&self) -> Option<isize> {+ let rect = self.workspace_sidebar_rect()?;+ if self.workspace_sidebar_collapsed {+ return None;+ }+ let ui_cell_height = self.workspace_sidebar_cell_height();+ let icon_size = (ui_cell_height + self.ui_px(12)).clamp(self.ui_px(30), self.ui_px(36));+ let layout = self.workspace_sidebar_layout(rect, ui_cell_height, icon_size);+ if layout.settings_footer_height == 0 {+ return Some(layout.content_bottom as isize);+ }+ let settings_row_top = (layout.settings_footer_y+ + self.ui_px(SIDEBAR_SETTINGS_ROW_TOP_PADDING))+ .saturating_sub(self.ui_px(SIDEBAR_SETTINGS_ROW_LIFT));+ let fade_top = layout+ .settings_footer_y+ .saturating_sub(self.ui_px(SIDEBAR_SETTINGS_FADE_HEIGHT));+ Some(+ layout+ .content_bottom+ .min(settings_row_top)+ .min(fade_top)+ .max(layout.list_top) as isize,+ )+ }+pub fn workspace_sidebar_scroll_geometry(&self) -> Option<WorkspaceSidebarScrollGeometry> {let rect = self.workspace_sidebar_rect()?;if self.workspace_sidebar_collapsed {diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rsindex 2a6be7c5..44750fa1 100644--- a/wezterm-gui/src/workspace_threads.rs+++ b/wezterm-gui/src/workspace_threads.rs@@ -334,6 +334,26 @@ pub struct SpaceView {pub domain: Option<String>,}+pub fn adjacent_local_space_ids(+ spaces: &[SpaceView],+ active_space_id: &str,+) -> (Option<SpaceId>, Option<SpaceId>) {+ let local = spaces+ .iter()+ .filter(|space| !space.is_remote && !space.is_occupied_by_other_window)+ .collect::<Vec<_>>();+ let Some(index) = local.iter().position(|space| space.id == active_space_id) else {+ return (None, None);+ };++ let previous = index+ .checked_sub(1)+ .and_then(|previous| local.get(previous))+ .map(|space| space.id.clone());+ let next = local.get(index + 1).map(|space| space.id.clone());+ (previous, next)+}+lazy_static::lazy_static! {static ref THREAD_STORE: Mutex<WorkspaceThreadStore> =Mutex::new(load_workspace_thread_store().unwrap_or_else(|err| {@@ -6352,6 +6372,43 @@ mod tests {store}+ fn space_view(id: &str, is_remote: bool, is_occupied_by_other_window: bool) -> SpaceView {+ SpaceView {+ id: id.to_string(),+ name: id.to_string(),+ is_active: false,+ is_default: false,+ is_occupied_by_other_window,+ is_remote,+ domain: is_remote.then(|| "server".to_string()),+ }+ }++ #[test]+ fn adjacent_space_swipe_targets_keep_local_order_and_skip_unavailable_spaces() {+ let spaces = vec![+ space_view("local-1", false, false),+ space_view("remote", true, false),+ space_view("occupied", false, true),+ space_view("local-2", false, false),+ space_view("local-3", false, false),+ ];++ assert_eq!(+ adjacent_local_space_ids(&spaces, "local-2"),+ (Some("local-1".into()), Some("local-3".into()))+ );+ assert_eq!(+ adjacent_local_space_ids(&spaces, "local-1"),+ (None, Some("local-2".into()))+ );+ assert_eq!(+ adjacent_local_space_ids(&spaces, "local-3"),+ (Some("local-2".into()), None)+ );+ assert_eq!(adjacent_local_space_ids(&spaces, "remote"), (None, None));+ }+/// A store that fails to parse must not come back as an empty one that/// then overwrites the file it could not read. The parse is strict, so the/// next field added to `Space`, `Project` or `WorkspaceThread` without adiff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rsindex b855cdf0..8e23c1e9 100644--- a/window/src/os/macos/window.rs+++ b/window/src/os/macos/window.rs@@ -176,6 +176,53 @@ fn ns_event_phase_to_scroll_phase(phase: NSEventPhase) -> Option<ScrollPhase> {}}+fn should_dispatch_scroll_event(+ vert_delta: f64,+ horz_delta: f64,+ has_precise_delta: bool,+ scroll_phase: Option<ScrollPhase>,+ momentum_phase: Option<ScrollPhase>,+) -> bool {+ let phase_only_completion = matches!(+ scroll_phase,+ Some(ScrollPhase::Ended | ScrollPhase::Cancelled)+ ) || matches!(+ momentum_phase,+ Some(ScrollPhase::Ended | ScrollPhase::Cancelled)+ );+ vert_delta.abs() >= 1.0 || horz_delta.abs() >= 1.0 || has_precise_delta || phase_only_completion+}++#[cfg(test)]+mod scroll_phase_tests {+ use super::{should_dispatch_scroll_event, ScrollPhase};++ #[test]+ fn zero_delta_scroll_completion_is_still_dispatched() {+ assert!(should_dispatch_scroll_event(+ 0.0,+ 0.0,+ false,+ Some(ScrollPhase::Ended),+ None,+ ));+ assert!(should_dispatch_scroll_event(+ 0.0,+ 0.0,+ false,+ None,+ Some(ScrollPhase::Cancelled),+ ));+ assert!(!should_dispatch_scroll_event(+ 0.0,+ 0.0,+ false,+ Some(ScrollPhase::Stationary),+ None,+ ));+ }+}+unsafe fn set_view_background_color(view: id, color: RgbaColor) {if view.is_null() {return;@@ -664,6 +711,7 @@ impl Window {gl_context_pair: None,text_cursor_position: Rect::new(Point::new(0, 0), Size::new(0, 0)),tracking_rect_tag: 0,+ tracking_rect_size: (0.0, 0.0),hscroll_remainder: 0.,vscroll_remainder: 0.,last_wheel: Instant::now(),@@ -2336,6 +2384,9 @@ struct Inner {gl_context_pair: Option<GlContextPair>,text_cursor_position: Rect,tracking_rect_tag: NSInteger,+ /// Backing size the live tracking rect was registered for, so+ /// `updateTrackingAreas` can skip a no-op rebuild. See the comment there.+ tracking_rect_size: (f64, f64),hscroll_remainder: f64,vscroll_remainder: f64,last_wheel: Instant,@@ -3148,6 +3199,21 @@ impl WindowView {}let tag = inner.tracking_rect_tag;+ let size = (frame.size.width, frame.size.height);++ // AppKit calls `updateTrackingAreas` for all sorts of reasons+ // beyond an actual geometry change. Tearing the rect down and+ // re-adding it is not free: `removeTrackingRect` while the+ // pointer is inside emits a `mouseExited`, and the replacement+ // is registered with `assumeInside: NO`, so AppKit then owes us+ // a fresh `mouseEntered`. That exit/enter pair clears+ // `current_mouse_event` on the GUI side and makes hover+ // highlights flicker between hovered and idle. Rebuild only+ // when the tracked area really changed.+ if tag != 0 && inner.tracking_rect_size == size {+ return;+ }+if tag != 0 {unsafe {let () = msg_send![*view, removeTrackingRect: tag];@@ -3161,6 +3227,7 @@ impl WindowView {inner.tracking_rect_tag = unsafe {msg_send![*view, addTrackingRect: rect owner: *view userData: nil assumeInside: NO]};+ inner.tracking_rect_size = size;}}}@@ -3523,7 +3590,13 @@ impl WindowView {// even when the legacy line accumulator has not reached a whole line;// pixel-scrolling surfaces (Files/Note/sidebars) consume the precise// payload directly while terminal grids keep using the integer kind.- if vert_delta.abs() < 1.0 && horz_delta.abs() < 1.0 && precise_scroll_delta.is_none() {+ if !should_dispatch_scroll_event(+ vert_delta,+ horz_delta,+ precise_scroll_delta.is_some(),+ scroll_phase,+ momentum_phase,+ ) {return;}@@ -3560,6 +3633,60 @@ impl WindowView {);}+ extern "C" fn wants_scroll_events_for_swipe_tracking(+ _this: &Object,+ _sel: Sel,+ axis: NSInteger,+ ) -> BOOL {+ if axis == appkit::NSEventGestureAxis::NSEventGestureAxisHorizontal as NSInteger {+ YES+ } else {+ NO+ }+ }++ extern "C" fn swipe_with_event(this: &mut Object, _sel: Sel, nsevent: id) {+ // When AppKit can track a page swipe as scroll events, scroll_wheel+ // above drives the interactive animation. Some trackpad settings only+ // deliver this discrete responder callback; synthesize a short precise+ // horizontal gesture so the same GUI state machine and hit testing are+ // used in both cases.+ let recently_received_scroll = Self::get_this(this).is_some_and(|myself| {+ myself.inner.borrow().last_wheel.elapsed() < std::time::Duration::from_millis(100)+ });+ if recently_received_scroll {+ return;+ }++ let native_x = unsafe { nsevent.deltaX() };+ let native_y = unsafe { nsevent.deltaY() };+ if native_x.abs() <= native_y.abs() || native_x.abs() <= f64::EPSILON {+ return;+ }++ // NSEvent uses +1 for a swipe left and -1 for a swipe right, while+ // precise scroll events use a negative x delta for leftward content+ // travel. Preserve the latter convention for the shared state machine.+ let delta_x = -native_x.signum() as f32 * 20.0;+ let amount = if delta_x < 0.0 { -1 } else { 1 };+ Self::mouse_common(+ this,+ nsevent,+ MouseEventKind::HorzWheel(amount),+ Some(PreciseScrollDelta { x: delta_x, y: 0.0 }),+ Some(ScrollPhase::Began),+ None,+ );+ Self::mouse_common(+ this,+ nsevent,+ MouseEventKind::HorzWheel(0),+ None,+ Some(ScrollPhase::Ended),+ None,+ );+ }+extern "C" fn right_mouse_down(this: &mut Object, _sel: Sel, nsevent: id) {Self::mouse_common(this,@@ -4581,6 +4708,15 @@ impl WindowView {sel!(scrollWheel:),Self::scroll_wheel as extern "C" fn(&mut Object, Sel, id),);+ cls.add_method(+ sel!(wantsScrollEventsForSwipeTrackingOnAxis:),+ Self::wants_scroll_events_for_swipe_tracking+ as extern "C" fn(&Object, Sel, NSInteger) -> BOOL,+ );+ cls.add_method(+ sel!(swipeWithEvent:),+ Self::swipe_with_event as extern "C" fn(&mut Object, Sel, id),+ );cls.add_method(sel!(mouseExited:),Self::mouse_exited as extern "C" fn(&mut Object, Sel, id),