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
feat(gui): swipe past the first Space to open the Library
RoversX1ba5e5065382
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex 3dd7db97..4b6ef230 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -1165,8 +1165,9 @@ impl super::TermWindow {context: &dyn WindowOps,) -> bool {// Over the Library, a wheel or a trackpad moves along its cards, never- // to another Space.- if self.library_presented() {+ // to another Space -- but for the swipe that is bringing it out, which+ // goes on as it began.+ if self.library_presented() && !self.workspace_sidebar_swipe.is_active() {let sideways = self.sidebar_horizontal_scroll_delta(event);let down = self.sidebar_vertical_scroll_delta(event);if let Some(handled) = self.scroll_library(event, sideways, down, context) {@@ -1325,7 +1326,11 @@ impl super::TermWindow {&& self.workspace_sidebar_swipe.is_active(){// A fresh gesture supersedes any unfinished/settling visual- // from the preceding gesture.+ // from the preceding gesture -- and lets go of a Library the+ // preceding one never finished bringing out.+ if self.workspace_sidebar_swipe.library_pull().is_some() {+ self.let_go_library(0.0, context);+ }self.workspace_sidebar_swipe.cancel_immediately();self.clear_workspace_space_swipe_frame_transition();}@@ -1359,7 +1364,14 @@ impl super::TermWindow {let update = self.workspace_sidebar_swipe.update(delta_x, delta_y, now);match update {SidebarSpaceSwipeUpdate::Pending => {}- SidebarSpaceSwipeUpdate::Horizontal => context.invalidate(),+ SidebarSpaceSwipeUpdate::Horizontal => {+ // On past the first Space: the Library comes out with+ // the finger.+ if let Some(pull) = self.workspace_sidebar_swipe.library_pull() {+ self.hold_library(true, pull, context);+ }+ context.invalidate();+ }SidebarSpaceSwipeUpdate::Vertical(delta_y) => {self.clear_workspace_space_swipe_frame_transition();self.scroll_workspace_sidebar_by(-delta_y, context);@@ -1372,6 +1384,11 @@ impl super::TermWindow {self.finish_workspace_sidebar_space_swipe(now, context);}ScrollPhase::Cancelled => {+ // Taken over, not ended: the Library it was bringing out is+ // let go of where it is.+ if self.workspace_sidebar_swipe.library_pull().is_some() {+ self.let_go_library(0.0, context);+ }self.workspace_sidebar_swipe.cancel_immediately();self.clear_workspace_space_swipe_frame_transition();context.invalidate();@@ -1425,6 +1442,14 @@ impl super::TermWindow {self.scroll_workspace_sidebar_by(-delta_y, context);true}+ SidebarSpaceSwipeFinish::Library { velocity } => {+ // On past the first Space the Library came out with the+ // finger: on out, or back, as it lets go.+ self.clear_workspace_space_swipe_frame_transition();+ self.let_go_library(velocity, context);+ 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 previousdiff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex fbe86cfa..f9b4dac0 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -4326,12 +4326,16 @@ impl crate::TermWindow {let color = self.tab_bar_surface(self.chrome().header_bg);// Behind where it starts, between its two parts, and past where// it ends, laid out beside a right panel that is not all the way- // out yet.- for (left, right) in [+ // out yet. Beside the Library its end goes along with the+ // terminal and covers the rest itself: filled under that too,+ // a see-through row would show darker there.+ let rooms = [(between.min_x(), row_left + lead_shift),(lead_end, trail),(row_right, between.max_x()),- ] {+ ];+ let rooms = if self.library_presented() { &rooms[..1] } else { &rooms[..] };+ for &(left, right) in rooms {let (left, right) = (left.max(between.min_x()), right.min(between.max_x()));if right > left {self.filled_rectangle(diff --git a/wezterm-gui/src/termwindow/space_swipe.rs b/wezterm-gui/src/termwindow/space_swipe.rsindex f4e2a67a..00d77967 100644--- a/wezterm-gui/src/termwindow/space_swipe.rs+++ b/wezterm-gui/src/termwindow/space_swipe.rs@@ -54,6 +54,10 @@ pub(crate) enum SidebarSpaceSwipeFinish {None,Switch(String),AnimateBack,+ /// Past the first Space, where a Space before it would be, the Library+ /// went along with the finger: it lets go, at `velocity` pixels a second+ /// towards the Library.+ Library { velocity: f32 },/// The gesture ended before either axis locked, so its vertical travel was/// only ever accumulated. Scroll by it now: the state machine consumed the/// events, so nothing else will.@@ -91,6 +95,9 @@ struct Gesture {raw_y: f32,velocity_x: f32,last_sample_at: Instant,+ /// Gone towards a Space before the first: the Library's, which comes+ /// out with the finger from then on, the pages staying where they are.+ library: bool,}impl Gesture {@@ -110,6 +117,7 @@ impl Gesture {raw_y: 0.0,velocity_x: 0.0,last_sample_at: now,+ library: false,}}@@ -126,8 +134,19 @@ impl Gesture {self.velocity_x = self.velocity_x * 0.65 + instantaneous * 0.35;}+ /// Following the finger sideways: one heading for a Space before the+ /// first goes to the Library, and stays its.+ fn track(mut self) -> Self {+ if self.previous_space_id.is_none() && self.raw_x > 0.0 {+ self.library = true;+ }+ self+ }+fn target_space_id(&self) -> Option<&String> {- if self.raw_x < 0.0 {+ if self.library {+ None+ } else 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()@@ -137,7 +156,9 @@ impl Gesture {}fn display_offset(&self, sidebar_width: f32) -> f32 {- if self.raw_x < 0.0 {+ if self.library {+ 0.0+ } else if self.raw_x < 0.0 {if self.next_space_id.is_some() {self.raw_x.max(-sidebar_width)} else {@@ -253,13 +274,13 @@ impl SidebarSpaceSwipeState {let max_axis = x.max(y);if x >= HORIZONTAL_LOCK_DISTANCE && x > y * AXIS_LOCK_RATIO {- self.phase = Phase::Tracking(gesture);+ self.phase = Phase::Tracking(gesture.track());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);+ self.phase = Phase::Tracking(gesture.track());SidebarSpaceSwipeUpdate::Horizontal} else if max_axis >= AXIS_LOCK_FALLBACK_DISTANCE {self.phase = Phase::Vertical;@@ -271,7 +292,7 @@ impl SidebarSpaceSwipeState {}Phase::Tracking(mut gesture) => {gesture.update(delta_x, delta_y, now);- self.phase = Phase::Tracking(gesture);+ self.phase = Phase::Tracking(gesture.track());SidebarSpaceSwipeUpdate::Horizontal}Phase::Vertical => {@@ -294,6 +315,15 @@ impl SidebarSpaceSwipeState {self.phase = Phase::AwaitingCommit(gesture);SidebarSpaceSwipeFinish::Switch(target)}+ Phase::Tracking(gesture) if gesture.library => {+ // The Library has had the gesture: where it goes on to is+ // its to decide.+ self.suppress_momentum = true;+ self.phase = Phase::Idle;+ SidebarSpaceSwipeFinish::Library {+ velocity: gesture.velocity_x,+ }+ }Phase::Tracking(gesture) => {self.suppress_momentum = true;let from = gesture.display_offset(sidebar_width);@@ -400,6 +430,8 @@ impl SidebarSpaceSwipeState {sidebar_width: f32,) -> Option<SidebarSpaceSwipeVisual> {match &self.phase {+ // The Library has the gesture, and the sidebar with it.+ Phase::Tracking(gesture) if gesture.library => None,Phase::Tracking(gesture) | Phase::AwaitingCommit(gesture) => {Some(SidebarSpaceSwipeVisual {source_space_id: gesture.source_space_id.clone(),@@ -450,6 +482,15 @@ impl SidebarSpaceSwipeState {}}+ /// How far a swipe past the first Space has gone towards the Library,+ /// in pixels, while the finger is down; `None` for any other.+ pub(crate) fn library_pull(&self) -> Option<f32> {+ match &self.phase {+ Phase::Tracking(gesture) if gesture.library => Some(gesture.raw_x.max(0.0)),+ _ => None,+ }+ }+pub(crate) fn consume_momentum(&mut self, ended: bool) -> bool {let consume = self.suppress_momentum || self.is_active();if ended {@@ -724,17 +765,46 @@ mod tests {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));+ swipe.begin("source".into(), Some("previous".into()), None, 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!(visual.offset, -48.0);assert_eq!(swipe.finish(at(start, 20), 300.0),SidebarSpaceSwipeFinish::AnimateBack);}+ #[test]+ fn a_swipe_on_past_the_first_space_takes_the_library_with_it() {+ let start = Instant::now();+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("first".into(), None, Some("next".into()), 0.0, start);+ swipe.update(40.0, 0.0, at(start, 16));+ // From the first pixel, all of it: the pages stay put.+ assert_eq!(swipe.library_pull(), Some(40.0));+ assert_eq!(swipe.visual(at(start, 16), 300.0), None);+ swipe.update(60.0, 0.0, at(start, 32));+ assert_eq!(swipe.library_pull(), Some(100.0));+ // Back past where it began is the Library's still, and next is not+ // gone to.+ swipe.update(-150.0, 0.0, at(start, 48));+ assert_eq!(swipe.library_pull(), Some(0.0));+ match swipe.finish(at(start, 64), 300.0) {+ SidebarSpaceSwipeFinish::Library { .. } => {}+ other => panic!("the Library's to let go: {other:?}"),+ }+ assert!(!swipe.is_active());+ assert_eq!(swipe.library_pull(), None);++ // Anywhere but the first Space, a Space before it is gone to.+ let mut swipe = SidebarSpaceSwipeState::default();+ swipe.begin("second".into(), Some("first".into()), None, 0.0, start);+ swipe.update(40.0, 0.0, at(start, 16));+ assert_eq!(swipe.library_pull(), None);+ }+#[test]fn momentum_is_suppressed_after_a_completed_gesture() {let start = Instant::now();diff --git a/wezterm-gui/src/termwindow/ui/library.rs b/wezterm-gui/src/termwindow/ui/library.rsindex 32e8080c..4252d0bd 100644--- a/wezterm-gui/src/termwindow/ui/library.rs+++ b/wezterm-gui/src/termwindow/ui/library.rs@@ -34,7 +34,7 @@ use wezterm_font::LoadedFont;use window::color::LinearRgba;use window::{ContextMenuIcon, ContextMenuItem, MouseCursor, MouseEvent, MouseEventKind as WMEK, MousePress,- RectF, WindowOps,+ RectF, ScrollPhase, WindowOps,};/// The least of the terminal that stays in view beside the Library, in@@ -117,6 +117,9 @@ const SNAP: Feel = Feel {/// Going back, the card lifts out first and the Library follows it this much/// later, in seconds.const GO_BACK_LAG: f32 = 0.12;+/// Let go at this speed or more, in pixels a second, towards where the+/// finger was taking it, the Library goes on there however far it got.+const LET_GO_FLING: f32 = 600.0;/// Springs are stepped this finely, and a frame is never taken for longer/// than the most, so a stall cannot fling one.const STEP: f32 = 1.0 / 240.0;@@ -188,6 +191,26 @@ struct Edge {spring: Spring,}+/// The Library going with a finger on the trackpad, out from the first+/// Space or back from beside its cards: as far along as the finger has+/// gone, its springs left where it puts them until it lets go.+#[derive(Clone, Copy, Debug)]+struct Held {+ opening: bool,+}++/// A swipe begun beside the cards -- the rail, the title, between and+/// under them: sideways towards the terminal it takes the Library back.+#[derive(Clone, Copy, Debug)]+struct Swipe {+ x: f32,+ y: f32,+ /// Towards the terminal, in pixels a second.+ velocity: f32,+ last: Instant,+ sideways: bool,+}+/// The row of cards on its way to show in full a card chosen from it, as/// the card goes back.#[derive(Clone, Copy, Debug)]@@ -241,6 +264,11 @@ pub(crate) struct LibraryState {/// was bringing out.sidebar_out: f32,edge: Option<Edge>,+ held: Option<Held>,+ swipe: Option<Swipe>,+ /// After a swipe that took the Library back or failed to: its momentum+ /// is not for the cards.+ swipe_momentum: bool,/// How far the row of cards is scrolled.scroll: f32,glide: Option<Glide>,@@ -619,6 +647,7 @@ impl crate::TermWindow {|| library.landing.moving()|| library.edge.is_some()|| library.glide.is_some()+ || library.held.is_some()}/// A window out of sight, drawn as boxes, under a view covering the@@ -685,6 +714,7 @@ impl crate::TermWindow {if !self.library.open {return;}+ self.library.held = None;if self.library.edge.is_some() {self.commit_library_edge();}@@ -717,6 +747,82 @@ impl crate::TermWindow {context.invalidate();}+ /// A finger on the trackpad takes the Library out from the first Space+ /// (`opening`), or back from beside its cards, as far as `pull` pixels+ /// of the way the terminal's edge goes: the edge keeps under it.+ pub(crate) fn hold_library(&mut self, opening: bool, pull: f32, context: &dyn WindowOps) {+ if self.library.held.is_none() {+ if opening {+ if self.library.open {+ return;+ }+ self.open_library(context);+ } else if !self.library.open || self.library_moving() {+ return;+ }+ if !self.library.open || !self.library_drawable() {+ return;+ }+ if !opening {+ // The window's own card out of view: the row brings it in+ // as the finger takes the Library back.+ if let Some((glide, cut)) = self.library_glide_to(&self.active_space_id.clone()) {+ self.library.glide = Some(glide);+ self.library.flight_cut = Some(cut);+ }+ }+ self.library.held = Some(Held { opening });+ }+ let along = clamp01(pull / self.library_reach());+ let x = if opening { along } else { 1.0 - along };+ for spring in [&mut self.library.out, &mut self.library.landing] {+ spring.x = x;+ spring.v = 0.0;+ spring.delay = 0.0;+ }+ context.invalidate();+ }++ /// The finger lets go: the Library goes on to where it was being+ /// taken, if it got halfway or was flung that way, else back; at+ /// `velocity` pixels a second towards where it was being taken.+ pub(crate) fn let_go_library(&mut self, velocity: f32, context: &dyn WindowOps) {+ let Some(held) = self.library.held.take() else {+ return;+ };+ let x = self.library.out.x;+ let along = if held.opening { x } else { 1.0 - x };+ let goes_on = along >= 0.5 || (velocity >= LET_GO_FLING && along > 0.02);+ // Out of the finger's speed into the springs': the way it was going+ // is towards 1 opening, towards 0 going back. Left where it began,+ // it has nothing to carry on with.+ let speed = if along > 0.02 {+ velocity / self.library_reach() * if held.opening { 1.0 } else { -1.0 }+ } else {+ 0.0+ };+ if held.opening != goes_on {+ self.close_library(context);+ // From where the finger left it, together: nothing has lifted+ // out first for the Library to follow.+ self.library.out.to(0.0, GO_BACK, 0.0);+ } else {+ self.library.out.to(1.0, COME_OUT, 0.0);+ self.library.landing.to(1.0, LAND, 0.0);+ }+ self.library.paints = 0;+ for spring in [&mut self.library.out, &mut self.library.landing] {+ spring.v = speed;+ }+ context.invalidate();+ }++ /// How far the terminal's edge goes between the sidebar and the+ /// Library, which is how far a finger takes the Library all the way.+ fn library_reach(&self) -> f32 {+ (self.library_shown_width() - self.library.sidebar_width).max(1.0)+ }+/// Let go of what the Library holds while it is on screen.fn release_library(&mut self) {let library = &mut self.library;@@ -726,6 +832,9 @@ impl crate::TermWindow {library.flight = None;library.glide = None;library.flight_cut = None;+ library.held = None;+ library.swipe = None;+ library.swipe_momentum = false;library.recordings.clear();}@@ -737,6 +846,20 @@ impl crate::TermWindow {self.release_library();return;}+ // A hold whose finger has gone -- its gesture cancelled, or taken+ // over with no end -- lets go where the finger left it.+ if let Some(held) = self.library.held {+ let finger = if held.opening {+ self.workspace_sidebar_swipe.library_pull().is_some()+ } else {+ self.library.swipe.is_some_and(|swipe| swipe.sideways)+ };+ if !finger {+ if let Some(window) = self.window.clone() {+ self.let_go_library(0.0, &window);+ }+ }+ }if !self.library_moving() {self.library.last_step = None;self.library.paints = 0;@@ -752,8 +875,15 @@ impl crate::TermWindow {let library = &mut self.library;library.last_step = Some(now);library.paints += 1;+ if library.held.is_some() {+ // Where the finger has it, for as long as it takes.+ library.paints = 0;+ }let give_up = !drawable || library.paints > MOST_PAINTS;for spring in [&mut library.out, &mut library.landing] {+ if library.held.is_some() {+ continue;+ }if give_up {spring.settle();} else {@@ -2252,6 +2382,25 @@ impl crate::TermWindow {if !self.library_presented() || !matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_)) {return None;}+ // What a swipe that took the Library in or out, or might have,+ // flings on with is not for the cards -- until the next one begins.+ if matches!(event.scroll_phase, Some(ScrollPhase::Began)) {+ self.library.swipe_momentum = false;+ }+ if let Some(momentum) = event.momentum_phase {+ let ended = matches!(momentum, ScrollPhase::Ended | ScrollPhase::Cancelled);+ let after_space_swipe = self.workspace_sidebar_swipe.consume_momentum(ended);+ let after_own = self.library.swipe_momentum;+ if ended {+ self.library.swipe_momentum = false;+ }+ if after_space_swipe || after_own {+ return Some(true);+ }+ }+ if let Some(handled) = self.swipe_library_back(event, context) {+ return Some(handled);+ }let left = self.get_os_border().left.get() as f32;let x = event.coords.x as f32;if x < left || x >= left + self.library_terminal_edge() {@@ -2285,6 +2434,76 @@ impl crate::TermWindow {Some(true)}+ /// A trackpad swipe begun on the Library beside its cards -- the rail,+ /// the title, between and under them: sideways towards the terminal it+ /// takes the Library back with it, as far as the finger goes. `None`+ /// for any other, the cards' to scroll.+ fn swipe_library_back(&mut self, event: &MouseEvent, context: &dyn WindowOps) -> Option<bool> {+ let phase = library_swipe_phase(event.scroll_phase, event.momentum_phase)?;+ let now = Instant::now();+ let (dx, dy) = event+ .precise_scroll_delta+ .map(|delta| (delta.x, delta.y))+ .unwrap_or((0.0, 0.0));+ if matches!(phase, ScrollPhase::Began) {+ self.library.swipe = None;+ let left = self.get_os_border().left.get() as f32;+ let at = euclid::point2(event.coords.x as f32, event.coords.y as f32);+ if self.library.open+ && !self.library_moving()+ && at.x >= left+ && at.x < left + self.library_terminal_edge()+ && self.library_card_at(at).is_none()+ {+ self.library.swipe = Some(Swipe {+ x: 0.0,+ y: 0.0,+ velocity: 0.0,+ last: now,+ sideways: false,+ });+ }+ }+ let mut swipe = self.library.swipe?;+ if matches!(phase, ScrollPhase::Began | ScrollPhase::Changed) {+ let dt = now+ .saturating_duration_since(swipe.last)+ .as_secs_f32()+ .clamp(1.0 / 240.0, 1.0 / 20.0);+ swipe.last = now;+ swipe.x += dx;+ swipe.y += dy;+ // Towards the terminal is the way the next Space is swiped to.+ swipe.velocity = swipe.velocity * 0.65 + (-dx / dt) * 0.35;+ if !swipe.sideways {+ let (x, y) = (swipe.x.abs(), swipe.y.abs());+ if x >= 8.0 && x > y * 1.15 && swipe.x > 0.0 {+ // Away from the terminal: the cards' to scroll along.+ self.library.swipe = None;+ return None;+ } else if x >= 8.0 && x > y * 1.15 {+ swipe.sideways = true;+ } else if y >= 18.0 {+ // Up or down: the cards' as any wheel is.+ self.library.swipe = None;+ return None;+ }+ }+ }+ self.library.swipe = Some(swipe);+ if swipe.sideways {+ self.hold_library(false, (-swipe.x).max(0.0), context);+ }+ if matches!(phase, ScrollPhase::Ended | ScrollPhase::Cancelled) {+ self.library.swipe = None;+ if swipe.sideways {+ self.library.swipe_momentum = true;+ self.let_go_library(swipe.velocity, context);+ }+ }+ Some(true)+ }+/// The card at `at`, if one is, not under what floats on the rail: its/// Space, and where it is.fn library_card_at(&self, at: window::PointF) -> Option<(String, RectF)> {@@ -2387,10 +2606,36 @@ impl crate::TermWindow {}}+// macOS can start momentum without a scroll Ended. Release the finger+// without applying the momentum delta to the held position.+fn library_swipe_phase(+ scroll: Option<ScrollPhase>,+ momentum: Option<ScrollPhase>,+) -> Option<ScrollPhase> {+ scroll.or_else(|| matches!(momentum, Some(ScrollPhase::Began)).then_some(ScrollPhase::Ended))+}+#[cfg(test)]mod tests {use super::*;+ #[test]+ fn momentum_without_scroll_ended_releases_the_library_swipe() {+ assert_eq!(+ library_swipe_phase(Some(ScrollPhase::Changed), None),+ Some(ScrollPhase::Changed)+ );+ assert_eq!(+ library_swipe_phase(None, Some(ScrollPhase::Began)),+ Some(ScrollPhase::Ended)+ );+ assert_eq!(library_swipe_phase(None, Some(ScrollPhase::Changed)), None);+ assert_eq!(+ library_swipe_phase(Some(ScrollPhase::Cancelled), None),+ Some(ScrollPhase::Cancelled)+ );+ }+fn space(id: &str, domain: Option<&str>) -> SpaceView {SpaceView {id: id.to_string(),