Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(gui): slide the sidebars open and closed

RoversXcf0e07fc896b
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index a767a477..96d006bf 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -370,6 +370,7 @@ tooltip-sidebar-thread-search = Thread finden
tooltip-sidebar-ssh-hosts = Remote-Hosts
tooltip-sidebar-live-overview = Live-Übersicht
tooltip-sidebar-notifications = Mitteilungen
+tooltip-sidebar-jump = Zum aktuellen Thread scrollen
menu-rename-project = Projekt umbenennen…
menu-grant-folder-access = Ordnerzugriff gewähren…
menu-new-thread = Neuer Thread
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index b181b85e..891f3bb7 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -370,6 +370,7 @@ tooltip-sidebar-thread-search = Find Thread
tooltip-sidebar-ssh-hosts = Remote Hosts
tooltip-sidebar-live-overview = Live Overview
tooltip-sidebar-notifications = Notifications
+tooltip-sidebar-jump = Scroll to Current Thread
menu-rename-project = Rename Project…
menu-grant-folder-access = Grant Folder Access…
menu-new-thread = New Thread
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index d6f730ef..e3c9b2b7 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -370,6 +370,7 @@ tooltip-sidebar-thread-search = Trouver un fil
tooltip-sidebar-ssh-hosts = Hôtes distants
tooltip-sidebar-live-overview = Aperçu en direct
tooltip-sidebar-notifications = Notifications
+tooltip-sidebar-jump = Aller à la session actuelle
menu-rename-project = Renommer le projet…
menu-grant-folder-access = Autoriser l'accès au dossier…
menu-new-thread = Nouvelle session
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index 4e684a57..82e75c41 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -367,6 +367,7 @@ tooltip-sidebar-thread-search = スレッドを検索
tooltip-sidebar-ssh-hosts = リモートホスト
tooltip-sidebar-live-overview = ライブ概要
tooltip-sidebar-notifications = 通知
+tooltip-sidebar-jump = 現在のセッションへスクロール
menu-rename-project = プロジェクト名を変更…
menu-grant-folder-access = フォルダへのアクセスを許可…
menu-new-thread = 新しいセッション
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index d92b2851..e1ad54eb 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -367,6 +367,7 @@ tooltip-sidebar-thread-search = 查找线程
tooltip-sidebar-ssh-hosts = 远程主机
tooltip-sidebar-live-overview = 实时总览
tooltip-sidebar-notifications = 通知
+tooltip-sidebar-jump = 滚到当前会话
menu-rename-project = 重命名项目…
menu-grant-folder-access = 授权文件夹访问…
menu-new-thread = 新建会话
diff --git a/wezterm-gui/src/termwindow/content_view.rs b/wezterm-gui/src/termwindow/content_view.rs
index 0120d7cf..143ae6bd 100644
--- a/wezterm-gui/src/termwindow/content_view.rs
+++ b/wezterm-gui/src/termwindow/content_view.rs
@@ -71,8 +71,9 @@ pub(crate) struct ContentViewFade {
/// How long a running transition may hold input before it is assumed stuck.
///
-/// The longest piece of the animation is 260ms, and its clock does not start
-/// until a frame has been presented. This ceiling is well clear of that while
+/// The longest piece of the animation is the terminal settling into its card,
+/// about 360ms, and its clock does not start until a frame has been
+/// presented. This ceiling is well clear of that while
/// still bounded, because the fade is only ever cleared by painting: a window
/// that stops painting mid-transition -- occluded, or on a display that has
/// gone to sleep -- would otherwise hold input forever.
@@ -145,9 +146,9 @@ mod card_landing_tests {
#[test]
fn the_travel_and_the_wait_end_before_input_is_let_go() {
- assert!(
- crate::termwindow::CONTENT_VIEW_TRAVEL + FLIGHT_LANDING_WAIT < TRANSITION_INPUT_HOLD
- );
+ // Settling into a card, the travel takes longer.
+ let travel = crate::termwindow::CONTENT_VIEW_TRAVEL.mul_f32(FLIGHT_SETTLE_STRETCH);
+ assert!(travel + FLIGHT_LANDING_WAIT < TRANSITION_INPUT_HOLD);
}
}
@@ -179,6 +180,16 @@ mod flight_rect_tests {
assert_eq!(flight_rect_at(source(), destination(), 4.0), destination());
}
+ #[test]
+ fn it_goes_past_by_no_more_than_asked_on_the_edge_that_goes_furthest() {
+ // The right edge goes furthest: from 1600 in to 700.
+ let overshoot = flight_overshoot(source(), destination(), 9.0);
+ assert!((overshoot - 0.01).abs() < 1e-6, "{}", overshoot);
+ // A short way goes past by its share, not by the most allowed.
+ let near = euclid::rect(10.0, 50.0, 1600.0, 900.0);
+ assert_eq!(flight_overshoot(source(), near, 9.0), FLIGHT_OVERSHOOT);
+ }
+
#[test]
fn halfway_is_halfway_on_every_edge() {
let mid = flight_rect_at(source(), destination(), 0.5);
@@ -374,8 +385,36 @@ pub(crate) fn flight_is_landing(source: RectF, destination: RectF, travel: f32)
<= FLIGHT_LANDING_OVERSIZE
}
+/// How far past its card the terminal landing in it goes as it settles, card
+/// and all, as a share of its way... Further than a sidebar does: a
+/// sidebar's few pixels were lost on a terminal shrinking by most of the
+/// window.
+const FLIGHT_OVERSHOOT: f32 = 0.02;
+/// ...and never further than this on the edge that goes furthest, at the
+/// design scale.
+pub(crate) const FLIGHT_MOST_OVERSHOOT: f32 = 24.0;
+/// How many times as long settling into a card takes as the plain travel:
+/// the going past and back needs time to be seen.
+pub(crate) const FLIGHT_SETTLE_STRETCH: f32 = 1.4;
+
+/// How far past its card the terminal landing in it goes as it settles, as
+/// a share of its way: no more than `most` on the edge that goes furthest.
+pub(crate) fn flight_overshoot(source: RectF, destination: RectF, most: f32) -> f32 {
+ let furthest = [
+ destination.min_x() - source.min_x(),
+ destination.min_y() - source.min_y(),
+ destination.max_x() - source.max_x(),
+ destination.max_y() - source.max_y(),
+ ]
+ .iter()
+ .fold(0.0f32, |furthest, way| furthest.max(way.abs()));
+ FLIGHT_OVERSHOOT.min(most / furthest.max(1.0))
+}
+
/// Where the travelling terminal sits at `travel`, between the rectangle it
-/// was recorded in and the one it is heading for.
+/// was recorded in and the one it is heading for. Settling past a card, it
+/// stays on the card, which goes past and back with it
+/// (`set_terminal_landing_settle`).
pub(crate) fn flight_rect_at(source: RectF, destination: RectF, travel: f32) -> RectF {
let travel = travel.clamp(0.0, 1.0);
let lerp = |from: f32, to: f32| from + (to - from) * travel;
@@ -714,6 +753,12 @@ pub(crate) trait ContentView {
/// same thing rather than one thing moving.
fn set_terminal_in_flight(&mut self, _tab_id: Option<TabId>) {}
+ /// The terminal landing in its place here has gone `past` of its way
+ /// beyond it, from `source` where it set off, as it settles: the place
+ /// goes past and back with it, the terminal on it. `None` while it is
+ /// not past.
+ fn set_terminal_landing_settle(&mut self, _settle: Option<(RectF, f32)>) {}
+
/// The opening frame of a full-window transition records the terminal and
/// grows the atlas; defer thumbnail capture until the next frame so that
/// work is not stacked onto the click that triggered the transition.
diff --git a/wezterm-gui/src/termwindow/live_overview.rs b/wezterm-gui/src/termwindow/live_overview.rs
index 89190f5c..934d47d4 100644
--- a/wezterm-gui/src/termwindow/live_overview.rs
+++ b/wezterm-gui/src/termwindow/live_overview.rs
@@ -539,6 +539,9 @@ pub(crate) struct LiveOverviewView {
/// When that terminal set off. Its card keeps the first picture captured
/// after this until it lands; see the capture in `paint`.
terminal_in_flight_since: Option<Instant>,
+ /// How far past its card that terminal is as it settles, and where it set
+ /// off: see `set_terminal_landing_settle`.
+ terminal_landing_settle: Option<(RectF, f32)>,
visible_panes: HashSet<PaneId>,
live_resizing: bool,
card_motion: HashMap<LiveThreadKey, CardMotion>,
@@ -606,6 +609,7 @@ impl LiveOverviewView {
card_preview_rects: HashMap::new(),
terminal_in_flight: None,
terminal_in_flight_since: None,
+ terminal_landing_settle: None,
visible_panes: HashSet::new(),
live_resizing: false,
card_motion: HashMap::new(),
@@ -1016,12 +1020,28 @@ impl LiveOverviewView {
0.0,
self.viewport.origin.y - self.scroll.offset,
));
+ let in_flight = self.terminal_in_flight == Some(card.tab_id);
+ // Where the card's picture is at rest, which is what the
+ // terminal landing in it has built...
+ let resting_preview = card_preview_rect(
+ rect,
+ card_header_height,
+ card_inset,
+ self.host_preview_aspect,
+ );
+ // ...and the card, carried past it by that terminal as it
+ // settles.
+ let rect = match self.terminal_landing_settle.filter(|_| in_flight) {
+ Some((source, past)) => {
+ card_carried_past(rect, resting_preview, source, past)
+ }
+ None => rect,
+ };
// Keep one complete row warm above and below the viewport
// so a scroll does not reveal an uncaptured thumbnail. All
// other cards remain metadata-only.
let overscan = layout.grid.card_height + gap;
- let in_flight = self.terminal_in_flight == Some(card.tab_id);
let snapshot = if card_is_warm(rect, self.viewport, overscan) {
warm_tabs.insert(card.tab_id);
if self.defer_preview_captures {
@@ -1165,12 +1185,11 @@ impl LiveOverviewView {
let close_x = rect.max_x() - ctx.px(CARD_CLOSE_RIGHT_PAD) - close_size;
let close_y = rect.origin.y + (ctx.px(CAPSULE_HEIGHT) - close_size) / 2.0;
- let preview_width = (rect.size.width - card_inset * 2.0).max(1.0);
- let preview = euclid::rect(
- rect.origin.x + card_inset,
- panel.origin.y + card_inset,
- preview_width,
- preview_width / self.host_preview_aspect,
+ let preview = card_preview_rect(
+ rect,
+ card_header_height,
+ card_inset,
+ self.host_preview_aspect,
);
// A card whose terminal is currently flying to it is left
// empty, but not neutral: the panel takes that terminal's
@@ -1212,7 +1231,9 @@ impl LiveOverviewView {
self.previews.push(TerminalPreviewRequest {
tab_id,
snapshot: Arc::clone(snapshot),
- area: preview,
+ // At rest: carried past, it would be
+ // built again for every frame of it.
+ area: resting_preview,
clip,
hold_scale: self.live_resizing,
opacity: 0.0,
@@ -2436,6 +2457,10 @@ impl ContentView for LiveOverviewView {
self.card_preview_rects.get(&tab_id).copied()
}
+ fn set_terminal_landing_settle(&mut self, settle: Option<(RectF, f32)>) {
+ self.terminal_landing_settle = settle;
+ }
+
fn set_terminal_in_flight(&mut self, tab_id: Option<TabId>) {
if tab_id.is_none() {
self.terminal_in_flight_since = None;
@@ -3197,6 +3222,36 @@ fn group_grid(
}
#[allow(clippy::too_many_arguments)]
+/// Where a card's picture is in `card`: below a header `header` high and
+/// `inset` inside the panel, `aspect` wide to high.
+fn card_preview_rect(card: RectF, header: f32, inset: f32, aspect: f32) -> RectF {
+ let width = (card.size.width - inset * 2.0).max(1.0);
+ euclid::rect(
+ card.origin.x + inset,
+ card.origin.y + header + inset,
+ width,
+ width / aspect,
+ )
+}
+
+/// `card`, carried by the terminal landing in it from `source` as that goes
+/// `past` of its way beyond the card's picture, `preview`: the whole card
+/// goes past and back, rather than the picture alone shrinking inside a card
+/// that stays put.
+fn card_carried_past(card: RectF, preview: RectF, source: RectF, past: f32) -> RectF {
+ let beyond = |from: f32, to: f32| to + (to - from) * past;
+ let left = beyond(source.min_x(), preview.min_x());
+ let top = beyond(source.min_y(), preview.min_y());
+ let scale_x = (beyond(source.max_x(), preview.max_x()) - left) / preview.size.width.max(1.0);
+ let scale_y = (beyond(source.max_y(), preview.max_y()) - top) / preview.size.height.max(1.0);
+ euclid::rect(
+ left + (card.origin.x - preview.origin.x) * scale_x,
+ top + (card.origin.y - preview.origin.y) * scale_y,
+ card.size.width * scale_x,
+ card.size.height * scale_y,
+ )
+}
+
fn group_layouts(
counts: &[usize],
content_width: f32,
@@ -3255,6 +3310,29 @@ mod tests {
// Lives in `ui::geometry` now, and only the tests reach for it directly.
use crate::ui::grid_columns;
+ #[test]
+ fn a_card_carried_past_goes_with_the_terminal_landing_in_it() {
+ let card = euclid::rect(100.0, 100.0, 300.0, 240.0);
+ let preview = card_preview_rect(card, 40.0, 10.0, 1.6);
+ assert_eq!(preview, euclid::rect(110.0, 150.0, 280.0, 175.0));
+ let source = euclid::rect(0.0, 0.0, 1600.0, 1000.0);
+ assert_eq!(card_carried_past(card, preview, source, 0.0), card);
+ // 2% past a terminal shrinking from 1600 wide into 280: the whole
+ // card narrows as its picture would, 26.4 of 280, inside where it was.
+ let carried = card_carried_past(card, preview, source, 0.02);
+ let scale = (280.0 - 1320.0 * 0.02) / 280.0;
+ assert!(
+ (carried.size.width - 300.0 * scale).abs() < 1e-3,
+ "{:?}",
+ carried
+ );
+ assert!(
+ carried.min_x() > card.min_x() && carried.max_x() < card.max_x(),
+ "{:?}",
+ carried
+ );
+ }
+
#[allow(clippy::too_many_arguments)]
fn test_group_grid(
count: usize,
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 51bb196d..70d6317c 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -168,6 +168,7 @@ pub mod resize;
pub(crate) mod share;
mod selection;
mod sidebar_hover;
+mod sidebar_slide;
mod space_swipe;
mod window_tab_reveal;
pub mod spawn;
@@ -849,6 +850,8 @@ pub enum UIItemType {
WorkspaceSidebarSshHosts,
WorkspaceSidebarLiveOverview,
WorkspaceSidebarNotifications,
+ /// The pill that brings the list back to the thread out of sight.
+ WorkspaceSidebarJump,
UpdateCapsule,
UpdateCapsuleDismiss,
RightSidebarToggle,
@@ -1674,6 +1677,7 @@ mod tooltip_tests {
UIItemType::WorkspaceSidebarSshHosts,
UIItemType::WorkspaceSidebarLiveOverview,
UIItemType::WorkspaceSidebarNotifications,
+ UIItemType::WorkspaceSidebarJump,
] {
let label = tooltip_label_for(&item_type)
.unwrap_or_else(|| panic!("no tooltip label for {:?}", item_type));
@@ -2194,6 +2198,7 @@ pub fn tooltip_label_for(item_type: &UIItemType) -> Option<String> {
UIItemType::WorkspaceSidebarSshHosts => "tooltip-sidebar-ssh-hosts",
UIItemType::WorkspaceSidebarLiveOverview => "tooltip-sidebar-live-overview",
UIItemType::WorkspaceSidebarNotifications => "tooltip-sidebar-notifications",
+ UIItemType::WorkspaceSidebarJump => "tooltip-sidebar-jump",
UIItemType::PaneNav {
action: PaneNavAction::Share,
..
@@ -3163,6 +3168,9 @@ pub struct TermWindow {
/// A pane sliding in on a split, or out on closing (see
/// `render::split_slide`).
split_slides: render::split_slide::SplitSlides,
+ /// A docked sidebar sliding out as it opens, or back as it closes (see
+ /// `sidebar_slide`).
+ sidebar_slides: sidebar_slide::SidebarSlides,
/// Set while a closed pane is painted on its way out.
closed_pane_nav: Option<render::split_slide::ClosedNav>,
/// Set while a pane carried into another stack is painted on its way.
@@ -3300,6 +3308,9 @@ pub struct TermWindow {
/// when the sidebar collapses.
workspace_sidebar_scratch: HeapQuadAllocator,
workspace_sidebar_scrollbar_visible_until: Option<Instant>,
+ /// The pill at the list's edge while the window's thread is out of
+ /// sight, and the scroll its click starts.
+ pub(crate) sidebar_jump: ui::sidebar_jump::SidebarJump,
/// Presentation-only hover reveal of the collapsed sidebar. This never
/// touches `workspace_sidebar_collapsed` or `workspace_sidebar_width`:
/// the terminal must not reflow for a hover.
@@ -4401,6 +4412,8 @@ impl TermWindow {
// What is split or closed while it is out of sight is not to
// slide when it is seen again, nor a closed pane held till then.
self.split_slides.release();
+ // Nor a sidebar left on its way, still holding what it shows.
+ self.finish_sidebar_slides();
}
}
@@ -5146,6 +5159,7 @@ impl TermWindow {
edge_lights: vec![],
pending_paste: None,
split_slides: Default::default(),
+ sidebar_slides: Default::default(),
closed_pane_nav: None,
nav_morph: None,
right_press_claimed: false,
@@ -5207,6 +5221,7 @@ impl TermWindow {
workspace_space_swipe_pending_commit: None,
workspace_space_swipe_needs_settle_start: false,
workspace_sidebar_scrollbar_visible_until: None,
+ sidebar_jump: Default::default(),
workspace_sidebar_hover: sidebar_hover::SidebarHoverReveal::default(),
window_tab_reveal,
right_sidebar_hover: sidebar_hover::SidebarHoverReveal::default(),
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index fea54872..014be139 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -1171,6 +1171,13 @@ impl super::TermWindow {
{
return false;
}
+ // On its way, the panel is not where its list is laid out: the wheel
+ // moves nothing under the pointer.
+ if matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_))
+ && self.sidebar_panel_moving(crate::termwindow::sidebar_slide::Side::Left)
+ {
+ return true;
+ }
let delta = match event.kind {
WMEK::VertWheel(_) => self.sidebar_vertical_scroll_delta(event).unwrap_or(0.0),
@@ -1250,9 +1257,12 @@ impl super::TermWindow {
return None;
}
- // Docked, or hover-revealed and fully arrived: a panel still sliding
- // out must not host a second animation.
- let panel_ready_for_swipe = !self.workspace_sidebar_collapsed
+ // Docked and done sliding, or hover-revealed and fully arrived: a
+ // panel still on its way must not host a second animation.
+ let panel_ready_for_swipe = (!self.workspace_sidebar_collapsed
+ && !self
+ .sidebar_slides
+ .sliding(crate::termwindow::sidebar_slide::Side::Left))
|| self
.workspace_sidebar_hover
.is_fully_presented(Instant::now());
@@ -1544,6 +1554,20 @@ impl super::TermWindow {
}
fn mouse_wheel_right_sidebar(&mut self, event: &MouseEvent, context: &dyn WindowOps) -> bool {
+ // On its way, the panel is not where what it shows is laid out: the
+ // wheel moves nothing under the pointer.
+ if matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_))
+ && self.sidebar_panel_moving(crate::termwindow::sidebar_slide::Side::Right)
+ && self.right_sidebar_rect().is_some_and(|rect| {
+ let (x, y) = (event.coords.x, 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
+ })
+ {
+ return true;
+ }
if self.right_sidebar_mode == super::RightSidebarMode::Chat {
if let Some(rect) = self.right_sidebar_file_preview_rect() {
let x = event.coords.x;
@@ -1757,6 +1781,7 @@ impl super::TermWindow {
| UIItemType::WorkspaceSidebarSshHosts
| UIItemType::WorkspaceSidebarLiveOverview
| UIItemType::WorkspaceSidebarNotifications
+ | UIItemType::WorkspaceSidebarJump
| UIItemType::RightSidebarToggle
| UIItemType::WindowTabsPin
| UIItemType::WindowTabsTravelling
@@ -1935,6 +1960,7 @@ impl super::TermWindow {
| UIItemType::WorkspaceSidebarSshHosts
| UIItemType::WorkspaceSidebarLiveOverview
| UIItemType::WorkspaceSidebarNotifications
+ | UIItemType::WorkspaceSidebarJump
| UIItemType::RightSidebarToggle
| UIItemType::WindowTabsPin
| UIItemType::WindowTabsTravelling
@@ -4339,6 +4365,12 @@ impl super::TermWindow {
UIItemType::WorkspaceSidebarNotifications => {
self.mouse_event_workspace_sidebar_notifications(item.clone(), event, context);
}
+ UIItemType::WorkspaceSidebarJump => {
+ context.set_cursor(Some(MouseCursor::Hand));
+ if event.kind == WMEK::Press(MousePress::Left) {
+ self.activate_sidebar_jump();
+ }
+ }
UIItemType::ContextMenuBackdrop
| UIItemType::SharePanel
| UIItemType::CommandPalette => {
@@ -4801,6 +4833,12 @@ impl super::TermWindow {
UIItemType::WorkspaceSidebarNotifications => {
self.mouse_event_workspace_sidebar_notifications(item.clone(), event, context);
}
+ UIItemType::WorkspaceSidebarJump => {
+ context.set_cursor(Some(MouseCursor::Hand));
+ if event.kind == WMEK::Press(MousePress::Left) {
+ self.activate_sidebar_jump();
+ }
+ }
UIItemType::RightSidebarToggle => {
self.mouse_event_right_sidebar_toggle(event, context);
}
diff --git a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
index 2229ea2d..e2440cbe 100644
--- a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
+++ b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
@@ -312,19 +312,24 @@ impl crate::TermWindow {
let mut ui_items = Vec::new();
let mut action_right = row_right.saturating_sub(self.ui_px(WINDOW_TAB_INSET) + 2);
// Over an open right sidebar the window's buttons are the sidebar's:
- // see `paint_right_sidebar_window_buttons`.
+ // see `paint_right_sidebar_window_buttons`. One sliding away holds
+ // them where they are, which is where the row's go once it is gone.
if self.fancy_tab_bar_shows_window_buttons() && self.right_sidebar_width() == 0 {
- action_right = self.paint_window_tab_window_buttons(
- layers,
- &mut ui_items,
- action_right,
- content_row_y,
- content_row_height,
- button_size,
- icon_size,
- foreground,
- muted_fg,
- )?;
+ action_right = if self.right_sidebar_holds_window_buttons() {
+ action_right.saturating_sub(self.window_tab_window_buttons_width(button_size))
+ } else {
+ self.paint_window_tab_window_buttons(
+ layers,
+ &mut ui_items,
+ action_right,
+ content_row_y,
+ content_row_height,
+ button_size,
+ icon_size,
+ foreground,
+ muted_fg,
+ )?
+ };
}
// An auto-hiding row's pin takes the new-tab button's slot, just
@@ -465,10 +470,7 @@ impl crate::TermWindow {
layers: &mut TripleLayerQuadAllocator,
) -> anyhow::Result<Vec<UIItem>> {
let row_height = self.tab_bar_pixel_height()?.ceil() as usize;
- if row_height == 0
- || self.right_sidebar_width() == 0
- || !self.fancy_tab_bar_shows_window_buttons()
- {
+ if row_height == 0 || !self.right_sidebar_holds_window_buttons() {
return Ok(Vec::new());
}
let border = self.get_os_border();
@@ -520,17 +522,22 @@ impl crate::TermWindow {
let chrome = self.chrome();
let mut x = bar_right.saturating_sub(self.ui_px(WINDOW_TAB_INSET) + 2);
if parts.window_buttons {
- x = self.paint_window_tab_window_buttons(
- layers,
- ui_items,
- x,
- bar_y,
- bar_height,
- button_size,
- icon_size,
- chrome.text,
- chrome.secondary_text,
- )?;
+ // A right sidebar sliding away holds them until it is gone.
+ x = if self.right_sidebar_holds_window_buttons() {
+ x.saturating_sub(self.window_tab_window_buttons_width(button_size))
+ } else {
+ self.paint_window_tab_window_buttons(
+ layers,
+ ui_items,
+ x,
+ bar_y,
+ bar_height,
+ button_size,
+ icon_size,
+ chrome.text,
+ chrome.secondary_text,
+ )?
+ };
}
if parts.right_sidebar_toggle {
x = x.saturating_sub(button_size);
@@ -575,7 +582,7 @@ impl crate::TermWindow {
) -> usize {
let gap = self.ui_px(WINDOW_TAB_LEADING_ACTION_GAP);
let window_buttons = if parts.window_buttons {
- self.config.integrated_title_buttons.len() * (button_size + gap / 2) + gap / 2
+ self.window_tab_window_buttons_width(button_size)
} else {
0
};
@@ -652,6 +659,16 @@ impl crate::TermWindow {
&& !self.config.integrated_title_buttons.is_empty()
}
+ /// Whether the window's buttons are the right sidebar's, at its top
+ /// (see `paint_right_sidebar_window_buttons`): while it is docked, and
+ /// while it slides back into the edge after, the row and the pane bars
+ /// leaving them room where they go once it is gone.
+ pub(crate) fn right_sidebar_holds_window_buttons(&self) -> bool {
+ self.fancy_tab_bar_shows_window_buttons()
+ && !self.right_sidebar_floats()
+ && self.right_sidebar_docked_width() > 0
+ }
+
#[allow(clippy::too_many_arguments)]
fn paint_window_tab_leading_actions(
&self,
@@ -819,6 +836,12 @@ impl crate::TermWindow {
Ok(action_right.saturating_sub(self.ui_px(WINDOW_TAB_LEADING_ACTION_GAP) / 2))
}
+ /// What `paint_window_tab_window_buttons` takes from the right.
+ fn window_tab_window_buttons_width(&self, button_size: usize) -> usize {
+ let gap = self.ui_px(WINDOW_TAB_LEADING_ACTION_GAP);
+ self.config.integrated_title_buttons.len() * (button_size + gap / 2) + gap / 2
+ }
+
#[allow(clippy::too_many_arguments)]
fn paint_window_tab_window_button(
&self,
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index f270047d..2c75cfa0 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -16,6 +16,7 @@ use crate::termwindow::render::split_slide::{
self, ClosedNav, Drawn, Leaving, MovingPane, Nav, NavMorph, OtherPane, Placed, SlideFrame,
TabLayout,
};
+use crate::termwindow::sidebar_slide::{EndBar, Side, SidebarSlideFrame};
use mux::tab::{PositionedPane, PositionedSplit, SplitDirection, TabId};
use smol::Timer;
use std::collections::hash_map::DefaultHasher;
@@ -491,6 +492,44 @@ fn clip_right_sidebar_hover_items(items: &mut Vec<UIItem>, top: usize, bottom: u
});
}
+/// While a sidebar is on its way, nothing in it is where it looks to be: one
+/// inert item over the part of it on screen stands for what it registers,
+/// and keeps the pointer off what lies under it. Beside the left one the
+/// same goes for what is between the sidebars, going along with its edge:
+/// the panes and the tab row, but for what the row keeps where it is (see
+/// `paint_tab_row_between_sliding_sidebars`), registered after these.
+fn sliding_sidebar_items(slide: &SidebarSlideFrame) -> Vec<UIItem> {
+ let mut items = vec![];
+ let between = (slide.terminal.shift.0 != 0.).then_some(slide.terminal.clip);
+ // A panel drawn where it docks keeps its own (see
+ // `record_sliding_sidebar`).
+ let moving = |drawn: Option<Drawn>| {
+ drawn
+ .filter(|drawn| drawn.shift != (0., 0.))
+ .map(|drawn| drawn.clip)
+ };
+ for (clip, item_type) in [
+ (moving(slide.left), UIItemType::WorkspaceSidebarBackground),
+ // Taking no click, as a travelling tab row's does.
+ (between, UIItemType::WindowTabsTravelling),
+ (moving(slide.right), UIItemType::RightSidebarBackground),
+ ] {
+ let Some(clip) = clip else {
+ continue;
+ };
+ if clip.width() >= 1.0 {
+ items.push(UIItem {
+ x: clip.min_x() as usize,
+ y: 0,
+ width: clip.width() as usize,
+ height: clip.max_y() as usize,
+ item_type,
+ });
+ }
+ }
+ items
+}
+
fn quad_clip_rect(rect: RectF, dimensions: &Dimensions) -> QuadClipRect {
QuadClipRect::from_top_left_pixels(
rect.min_x(),
@@ -1460,6 +1499,7 @@ impl crate::TermWindow {
}
if present_frame {
self.split_slides.shown();
+ self.sidebar_slides.shown();
}
let draw_result = if present_frame {
self.call_draw(frame).map(|_| true)
@@ -1730,6 +1770,18 @@ impl crate::TermWindow {
)
}
+ /// How far past the card it lands in the travelling terminal has gone as
+ /// it settles, and where it set off; `None` but while it is past one.
+ fn content_view_landing_settle(&self, now: Instant) -> Option<(RectF, f32)> {
+ let fade = self.content_view_fade.as_ref()?;
+ let flight = fade.flight.as_ref().filter(|flight| flight.lands_in_card)?;
+ if fade.travel.target() < 0.5 || fade.landing.is_some() {
+ return None;
+ }
+ let past = fade.travel.value(now) - 1.0;
+ (past > 0.0).then_some((flight.source, past))
+ }
+
/// Where the recorded terminal was recorded, and where its travel has
/// taken it now; `None` while there is no flight to paint.
fn content_view_flight_rects(&self, now: Instant) -> Option<(RectF, RectF)> {
@@ -2254,7 +2306,22 @@ impl crate::TermWindow {
}
}
let source = self.terminal_content_rect();
+ let overshoot = crate::termwindow::content_view::flight_overshoot(
+ source,
+ destination,
+ self.ui_f32(crate::termwindow::content_view::FLIGHT_MOST_OVERSHOOT),
+ );
if let Some(fade) = self.content_view_fade.as_mut() {
+ // Into its card, the terminal goes a little past and comes back,
+ // carrying the card (`content_view_landing_settle`), as a sidebar
+ // does. Its way is known only now, on the first frame, before the
+ // travel's clock starts. Back out of it, it does not.
+ if lands_in_card && fade.travel.target() >= 0.5 {
+ fade.travel.reshape(
+ crate::ui::anim::Easing::settling(overshoot),
+ crate::termwindow::content_view::FLIGHT_SETTLE_STRETCH,
+ );
+ }
fade.flight = Some(crate::termwindow::content_view::ContentViewFlight {
surface,
source,
@@ -2325,6 +2392,11 @@ impl crate::TermWindow {
// reading it as "a heap is being recorded", as it must.
let mut heap = std::mem::take(&mut self.content_view_frame_scratch);
heap.recycle();
+ // The card the terminal lands in goes past and back with it.
+ let settle = self.content_view_landing_settle(Instant::now());
+ if let Some(view) = self.active_content_view_mut() {
+ view.set_terminal_landing_settle(settle);
+ }
{
let mut recorded = TripleLayerQuadAllocator::Heap(&mut heap);
self.paint_content_view(&mut recorded)?;
@@ -4087,8 +4159,9 @@ impl crate::TermWindow {
/// Step the hover-reveal machine from the frame loop, so a motionless
/// pointer still reveals at dwell expiry and a departed one still
- /// retreats at grace expiry.
+ /// retreats at grace expiry; and pace a travelling panel by the frame.
fn advance_workspace_sidebar_hover(&mut self, now: Instant) {
+ self.workspace_sidebar_hover.pace(now);
let input = self.workspace_sidebar_hover_input();
match self.workspace_sidebar_hover.step(input, now) {
crate::termwindow::sidebar_hover::HoverFrame::None => {}
@@ -4108,6 +4181,7 @@ impl crate::TermWindow {
/// The right sidebar's counterpart of `advance_workspace_sidebar_hover`.
fn advance_right_sidebar_hover(&mut self, now: Instant) {
+ self.right_sidebar_hover.pace(now);
match self.step_right_sidebar_hover(now) {
crate::termwindow::sidebar_hover::HoverFrame::None => {}
crate::termwindow::sidebar_hover::HoverFrame::Now => {
@@ -4121,6 +4195,186 @@ impl crate::TermWindow {
}
}
+ /// A sidebar on its way out of its edge or back, painted where it is
+ /// docked into a recording to replay where the slide has it, `drawn`.
+ /// While it moves nothing in it is where it looks to be, so what it
+ /// registers for the pointer is dropped (see `sliding_sidebar_items`).
+ /// Drawn where it docks -- a hover reveal docked, with only the
+ /// terminal beside it moving -- it keeps it.
+ fn record_sliding_sidebar(
+ &mut self,
+ drawn: Drawn,
+ paint: impl FnOnce(&mut Self, &mut TripleLayerQuadAllocator) -> anyhow::Result<()>,
+ ) -> anyhow::Result<RecordedPane> {
+ let ui_items = self.ui_items.len();
+ let images = self.image_composites.borrow().mark();
+ let mut quads = HeapQuadAllocator::default();
+ let painted = paint(self, &mut TripleLayerQuadAllocator::Heap(&mut quads));
+ let images = self.image_composites.borrow_mut().take_since(images);
+ if drawn.shift != (0., 0.) {
+ self.ui_items.truncate(ui_items);
+ }
+ painted?;
+ Ok(RecordedPane { quads, images })
+ }
+
+ /// Room between the sidebars the terminal does not reach yet while one
+ /// slides, filled as the panes along the terminal's right edge fill
+ /// their own. Recorded with the terminal, where the slide's shift takes
+ /// it to the room.
+ fn paint_sidebar_slide_room(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ panes: &[PositionedPane],
+ slide: &SidebarSlideFrame,
+ ) -> anyhow::Result<()> {
+ let Some(room) = slide.room else {
+ return Ok(());
+ };
+ let left = room.min_x() - slide.terminal.shift.0;
+ let right_edge = self.terminal_viewport_right();
+ for pos in panes {
+ let place = self.split_slide_place(pos)?;
+ if place.max_x() < right_edge - 1.0 {
+ continue;
+ }
+ let rect = euclid::rect(left, place.min_y(), room.width(), place.height());
+ self.paint_room_of(layers, pos, rect, 0.)?;
+ }
+ Ok(())
+ }
+
+ /// The bars of the panes along the terminal's right edge, which does
+ /// not move as a sidebar slides: the buttons at their ends stay with it
+ /// (see `SidebarSlideFrame::terminal_pieces`).
+ fn sidebar_slide_end_bars(&self, panes: &[PositionedPane]) -> anyhow::Result<Vec<EndBar>> {
+ let right_edge = self.terminal_viewport_right();
+ let mut bars = vec![];
+ for pos in panes {
+ if self.split_slide_place(pos)?.max_x() < right_edge - 1.0 {
+ continue;
+ }
+ if let Some((band, buttons)) = self.pane_nav_band(pos)? {
+ bars.push(EndBar { band, buttons });
+ }
+ }
+ Ok(bars)
+ }
+
+ /// The tab row while a sidebar slides: painted where it is laid out into
+ /// a recording, and drawn in two parts with the rest of what is between
+ /// the sidebars. The buttons at its end stay where they are, as the
+ /// terminal's right edge does, and those at the ends of the pane bars
+ /// along it. What leads it goes along with the terminal's left edge, but
+ /// no further left than it stands with the sidebar collapsed: the
+ /// window's own buttons are there, which the tabs would run under coming
+ /// out from beneath the sidebar, and jump clear of as it leaves. Room
+ /// neither part reaches is the row's colour. Returns what of the row
+ /// takes clicks meanwhile: what is where it is drawn.
+ fn paint_tab_row_between_sliding_sidebars(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator,
+ slide: SidebarSlideFrame,
+ defer_trailing_actions: bool,
+ ) -> anyhow::Result<Vec<UIItem>> {
+ let images = self.image_composites.borrow().mark();
+ let mut quads = HeapQuadAllocator::default();
+ let items = {
+ let mut row_layers = TripleLayerQuadAllocator::Heap(&mut quads);
+ match self.window_tab_row_travel_shift() {
+ Some(shift) => self.paint_window_tab_row_travelling(&mut row_layers, shift),
+ None => self.paint_fancy_tab_bar(&mut row_layers, defer_trailing_actions),
+ }
+ };
+ let row = RecordedPane {
+ quads,
+ images: self.image_composites.borrow_mut().take_since(images),
+ };
+ let items = items?;
+
+ let between = slide.terminal.clip;
+ let shift = slide.terminal.shift.0;
+ let row_left = self.tab_bar_left_edge() as f32;
+ let row_right = self.terminal_viewport_right();
+ let trail_left = row_right - self.window_tab_trailing_action_reserved_width() as f32;
+ let lead_shift = if slide.left.is_some() {
+ // Docked, the tabs start right at the sidebar's edge.
+ let collapsed = self.get_os_border().left.get() as f32
+ + crate::termwindow::ui::platform_chrome::WindowTabChromeParams {
+ workspace_sidebar_width: 0,
+ ..self.window_tab_chrome_params()
+ }
+ .left_padding_pixels();
+ collapsed.max(row_left + shift) - (row_left + self.window_tab_left_padding_pixels())
+ } else {
+ 0.
+ };
+ let window_button = |item: &UIItem| {
+ matches!(
+ item.item_type,
+ UIItemType::TabBar(crate::tabbar::TabBarItem::WindowButton(_))
+ )
+ };
+ let trail = trail_left.clamp(between.min_x(), between.max_x());
+ let lead_end = (trail_left + lead_shift).min(trail);
+ let height = self.dimensions.pixel_height as f32;
+ let span = |left: f32, right: f32| euclid::rect(left, 0., (right - left).max(0.), height);
+
+ let row_height = self.tab_bar_pixel_height().unwrap_or(0.0).ceil();
+ if row_height > 0.0 && self.window_tab_row_in_place() {
+ let top = self.get_os_border().top.get() as f32;
+ 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 [
+ (between.min_x(), row_left + lead_shift),
+ (lead_end, trail),
+ (row_right, between.max_x()),
+ ] {
+ let (left, right) = (left.max(between.min_x()), right.min(between.max_x()));
+ if right > left {
+ self.filled_rectangle(
+ layers,
+ 0,
+ euclid::rect(left, top, right - left, row_height),
+ color,
+ )
+ .context("tab bar room")?;
+ }
+ }
+ }
+ let lead = Drawn {
+ shift: (lead_shift, 0.),
+ clip: span(between.min_x(), lead_end),
+ };
+ let trail = Drawn {
+ shift: (0., 0.),
+ clip: span(trail, between.max_x()),
+ };
+ self.replay_pane(&row, layers, lead)?;
+ self.replay_pane(&row, layers, trail)?;
+
+ // Going along with the left sidebar's edge, the frame's item between
+ // the sidebars stands for the row: only the window's buttons take a
+ // click. Beside the right one it stays put: what of it is on screen
+ // takes clicks as usual.
+ let moving = shift != 0. || lead_shift != 0.;
+ Ok(items
+ .into_iter()
+ .filter(|item| !moving || window_button(item))
+ .filter_map(|mut item| {
+ let left = (item.x as f32).max(between.min_x());
+ let right = ((item.x + item.width) as f32).min(between.max_x());
+ (right > left).then(|| {
+ item.x = left as usize;
+ item.width = (right - left) as usize;
+ item
+ })
+ })
+ .collect())
+ }
+
/// The left sidebar's hover shadow, mirrored: it falls off the revealed
/// right panel's LEFT edge, onto the terminal it floats over.
fn paint_right_sidebar_hover_shadow(
@@ -4160,7 +4414,9 @@ impl crate::TermWindow {
&mut self,
now: Instant,
) -> anyhow::Result<Option<(HeapQuadAllocator, f32, Vec<UIItem>)>> {
- if !self.right_sidebar_collapsed {
+ // Docked, or on its way back as docked: what it shows is let go of
+ // once it is gone.
+ if !self.right_sidebar_collapsed || self.sidebar_slides.closing(Side::Right) {
return Ok(None);
}
let Some(progress) = self.right_sidebar_hover.progress(now) else {
@@ -4713,6 +4969,9 @@ impl crate::TermWindow {
let panes = self.get_panes_to_render();
let splits = self.get_splits();
let slides = self.advance_split_slide(&panes, &splits, frame_now);
+ // Where the sidebars on their way are drawn this frame, and what is
+ // between them.
+ let sidebar_slide = self.sidebar_slide_frame(frame_now);
let focused = self.focused.is_some();
let window_is_transparent =
!self.window_background.is_empty() || self.config.window_background_opacity != 1.0;
@@ -4810,6 +5069,20 @@ impl crate::TermWindow {
.context("filled_rectangle for chrome header background")?;
}
+ // While a sidebar slides, what is between the sidebars is painted
+ // where it is laid out into a recording, the pictures it puts on
+ // textures of their own taken back with it, and drawn where the
+ // slide has it before the sidebars are painted.
+ let mut slid_terminal = HeapQuadAllocator::default();
+ let slid_images = self.image_composites.borrow().mark();
+ let mut layers = match sidebar_slide {
+ Some(_) => {
+ drop(layers);
+ TripleLayerQuadAllocator::Heap(&mut slid_terminal)
+ }
+ None => layers,
+ };
+
// When a content view is the foreground it takes over the content area,
// so skip painting the terminal panes / splits -- except while one is
// arriving or leaving, when both have to be on screen at once for the
@@ -4859,6 +5132,14 @@ impl crate::TermWindow {
// let a click land on a pane the user is looking at through a
// half-drawn overview.
let ui_items_before_terminal = self.ui_items.len();
+ // The buttons at the bars' ends stay where they stand while a
+ // sidebar slides, the terminal's right edge staying too.
+ let sidebar_slide_bars = match sidebar_slide {
+ Some(_) => self
+ .sidebar_slide_end_bars(&panes)
+ .context("sidebar slide end bars")?,
+ _ => vec![],
+ };
let mut takeover_badge = false;
if paint_terminal_world && !frontend_blocked {
@@ -4880,6 +5161,10 @@ impl crate::TermWindow {
)),
_ => None,
};
+ if let Some(slide) = sidebar_slide.as_ref() {
+ self.paint_sidebar_slide_room(&mut layers, &panes, slide)
+ .context("sidebar slide room")?;
+ }
// Room no pane is in yet looks like the pane it belongs to: the
// window's own ground is lighter than a pane dimmed for not
// being active.
@@ -5112,6 +5397,23 @@ impl crate::TermWindow {
// 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);
+ if let Some(slide) = sidebar_slide.as_ref() {
+ let recorded = RecordedPane {
+ quads: slid_terminal,
+ images: self.image_composites.borrow_mut().take_since(slid_images),
+ };
+ let (pieces, bare) = slide.terminal_pieces(&sidebar_slide_bars);
+ let mut terminal_layers = layer.quad_allocator();
+ for drawn in pieces {
+ self.replay_pane(&recorded, &mut terminal_layers, drawn)
+ .context("replay terminal between sliding sidebars")?;
+ }
+ let bar = self.tab_bar_surface(self.chrome().header_bg);
+ for rect in bare {
+ self.filled_rectangle(&mut terminal_layers, 0, rect, bar)
+ .context("bar between its tabs and buttons")?;
+ }
+ }
self.capture_workspace_space_swipe_target(frame_now)?;
@@ -5354,13 +5656,33 @@ impl crate::TermWindow {
let mut chrome_layers = layer.quad_allocator();
// A hover-revealed right sidebar was recorded above and is
// composited after the tab bar instead.
- if !self.right_sidebar_collapsed {
+ if let Some(drawn) = sidebar_slide.and_then(|slide| slide.right) {
+ let recorded = self
+ .record_sliding_sidebar(drawn, |term_window, layers| {
+ term_window.paint_right_sidebar(layers)
+ })
+ .context("record sliding right sidebar")?;
+ self.replay_pane(&recorded, &mut chrome_layers, drawn)
+ .context("replay sliding right sidebar")?;
+ if let Some(sliver) = sidebar_slide.and_then(|slide| slide.right_sliver) {
+ self.replay_pane(&recorded, &mut chrome_layers, sliver)
+ .context("replay sliding right sidebar's edge")?;
+ }
+ } else if !self.right_sidebar_collapsed {
self.paint_right_sidebar(&mut chrome_layers)
.context("paint_right_sidebar")?;
}
let defer_trailing_actions = !cfg!(target_os = "macos") && right_hover_overlay.is_some();
- let tab_items = if let Some(shift) = self.window_tab_row_travel_shift() {
+ let tab_items = if let Some(slide) = sidebar_slide {
+ // With the rest of what is between the sidebars.
+ self.paint_tab_row_between_sliding_sidebars(
+ &mut chrome_layers,
+ slide,
+ defer_trailing_actions,
+ )
+ .context("paint tab bar between sliding sidebars")?
+ } else if let Some(shift) = self.window_tab_row_travel_shift() {
// On its way down from the top edge or back up: nothing on
// it takes a click until it lands.
self.paint_window_tab_row_travelling(&mut chrome_layers, shift)
@@ -5369,6 +5691,11 @@ impl crate::TermWindow {
self.paint_fancy_tab_bar(&mut chrome_layers, defer_trailing_actions)
.context("paint_tab_bar")?
};
+ if let Some(slide) = sidebar_slide.as_ref() {
+ // Under what the row keeps where it is: the row hands back
+ // nothing that is under the sidebars.
+ self.ui_items.extend(sliding_sidebar_items(slide));
+ }
self.ui_items.extend(tab_items);
// Over an open right sidebar, whatever the row is doing.
let window_buttons = self
@@ -5554,6 +5881,73 @@ mod tests {
}
}
+ #[test]
+ fn nothing_between_sliding_sidebars_takes_a_click_while_it_moves() {
+ use crate::termwindow::sidebar_slide::{Out, Panel};
+ let frame = |left: Option<f32>, right: Option<f32>| {
+ SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ Panel {
+ docked: 200.,
+ laid_out: 200.,
+ out: left.map(Out::along),
+ },
+ Panel {
+ docked: 300.,
+ laid_out: 300.,
+ out: right.map(Out::along),
+ },
+ )
+ .unwrap()
+ };
+ let under = |items: &[UIItem], x| {
+ items
+ .iter()
+ .rev()
+ .find(|item| item.hit_test(x, 300))
+ .map(|item| item.item_type.clone())
+ };
+ // Beside the left one, what is between goes along with its edge.
+ let items = sliding_sidebar_items(&frame(Some(0.5), None));
+ assert_eq!(
+ under(&items, 50),
+ Some(UIItemType::WorkspaceSidebarBackground)
+ );
+ assert_eq!(under(&items, 500), Some(UIItemType::WindowTabsTravelling));
+ assert_eq!(under(&items, 800), None);
+ // Beside the right one alone it stays put, and keeps its own.
+ let items = sliding_sidebar_items(&frame(None, Some(0.5)));
+ assert_eq!(under(&items, 500), None);
+ assert_eq!(under(&items, 950), Some(UIItemType::RightSidebarBackground));
+ // Docked from a hover reveal, the panel stays where it docks and
+ // keeps its own: only the terminal coming out from under it is
+ // inert.
+ let docking = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ Panel {
+ docked: 200.,
+ laid_out: 200.,
+ out: Some(Out {
+ panel: 1.0,
+ clear: 0.25,
+ }),
+ },
+ Panel {
+ docked: 300.,
+ laid_out: 300.,
+ out: None,
+ },
+ )
+ .unwrap();
+ let items = sliding_sidebar_items(&docking);
+ assert_eq!(under(&items, 50), None);
+ assert_eq!(under(&items, 500), Some(UIItemType::WindowTabsTravelling));
+ }
+
fn test_preview(area: RectF) -> TerminalPreviewRequest {
TerminalPreviewRequest {
tab_id: 1,
diff --git a/wezterm-gui/src/termwindow/render/split_slide.rs b/wezterm-gui/src/termwindow/render/split_slide.rs
index d5a716b6..a7408958 100644
--- a/wezterm-gui/src/termwindow/render/split_slide.rs
+++ b/wezterm-gui/src/termwindow/render/split_slide.rs
@@ -58,14 +58,14 @@ const LEAVE_DURATION: Duration = Duration::from_millis(140);
/// optimisation -- the slide takes longer rather than skip most of its way:
/// timed on the clock alone it got one frame in, at a third of the way,
/// and was then found at its end.
-const MIN_FRAMES: u32 = 8;
+pub(crate) const MIN_FRAMES: u32 = 8;
/// The first frame is drawn as if one had already passed, so the pane is
/// on its way in that frame rather than still all outside its place.
const FIRST_FRAME: Duration = Duration::from_micros(16_667);
/// A slide painted this many times and still not at its end is let go of.
/// Frames that are painted but never shown -- a pass that fails every time
/// -- would otherwise have it ask for frames for ever.
-const MOST_PAINTS: u32 = 8 * MIN_FRAMES;
+pub(crate) const MOST_PAINTS: u32 = 8 * MIN_FRAMES;
/// The edge of its place a new pane comes in from, or a closed one goes
/// out by.
@@ -805,7 +805,12 @@ impl Rearranging {
/// How far through a slide lasting `duration` is, from 0 to 1, in the
/// frame after `shown` frames; `None` once it is over.
-fn progress(started: Instant, shown: u32, duration: Duration, now: Instant) -> Option<f32> {
+pub(crate) fn progress(
+ started: Instant,
+ shown: u32,
+ duration: Duration,
+ now: Instant,
+) -> Option<f32> {
let elapsed = now.saturating_duration_since(started) + FIRST_FRAME;
let by_clock = elapsed.as_secs_f32() / duration.as_secs_f32();
let by_frames = (shown + 1) as f32 / MIN_FRAMES as f32;
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index 71c5a028..25153ff9 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -2322,7 +2322,7 @@ impl super::TermWindow {
pixel_cell: self.render_metrics.cell_size.height as f32,
};
let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as usize
- + self.workspace_sidebar_width();
+ + self.workspace_sidebar_sizing_width();
let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as usize;
let padding_bottom =
config.window_padding.bottom.evaluate_as_pixels(v_context) as usize;
@@ -2370,7 +2370,7 @@ impl super::TermWindow {
pixel_cell: self.render_metrics.cell_size.height as f32,
};
let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as usize
- + self.workspace_sidebar_width();
+ + self.workspace_sidebar_sizing_width();
let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as usize;
let padding_bottom =
config.window_padding.bottom.evaluate_as_pixels(v_context) as usize;
diff --git a/wezterm-gui/src/termwindow/sidebar_hover.rs b/wezterm-gui/src/termwindow/sidebar_hover.rs
index b6163c75..1a150992 100644
--- a/wezterm-gui/src/termwindow/sidebar_hover.rs
+++ b/wezterm-gui/src/termwindow/sidebar_hover.rs
@@ -7,6 +7,7 @@
//! terminal, which is why nothing in here touches `workspace_sidebar_width`
//! or `workspace_sidebar_collapsed`.
+use crate::termwindow::render::split_slide::MIN_FRAMES;
use crate::termwindow::ui::tokens::{SIDEBAR_HOVER_DWELL_MS, SIDEBAR_HOVER_GRACE_MS};
use crate::ui::anim::{self, Easing, Timeline};
use std::time::{Duration, Instant};
@@ -233,6 +234,20 @@ impl SidebarHoverReveal {
frame
}
+ /// Pace a travelling panel by the frame being painted: it goes no more
+ /// than its share of the way in one, as a split's slide does, so a slow
+ /// few frames -- its contents drawn for the first time, in a build
+ /// without optimisation -- do not see it out or away in one. Call once
+ /// per frame painted, before `step`.
+ pub(crate) fn pace(&mut self, now: Instant) {
+ if let Phase::Revealing { travel }
+ | Phase::Departing { travel, .. }
+ | Phase::Retreating { travel } = &mut self.phase
+ {
+ travel.pace(now, REVEAL / MIN_FRAMES);
+ }
+ }
+
/// `None` = nothing presented; `Some(0.0..=1.0)` = how far out the panel
/// is.
pub(crate) fn progress(&self, now: Instant) -> Option<f32> {
@@ -394,6 +409,29 @@ mod tests {
panic!("panel never settled");
}
+ #[test]
+ fn slow_frames_still_see_the_panel_on_its_way() {
+ let start = Instant::now();
+ let mut machine = SidebarHoverReveal::default();
+ machine.step(input(PointerZone::HotZone), start);
+ let mut now = at(start, SIDEBAR_HOVER_DWELL_MS);
+ let mut seen = vec![];
+ loop {
+ machine.pace(now);
+ machine.step(input(PointerZone::HotZone), now);
+ let progress = machine.progress(now).unwrap();
+ seen.push(progress);
+ if progress >= 1.0 {
+ break;
+ }
+ assert!(seen.len() < 50, "{:?}", seen);
+ // Each frame takes longer than the whole reveal.
+ now += Duration::from_millis(200);
+ }
+ let on_its_way = seen.iter().filter(|&&out| out > 0.0 && out < 1.0).count();
+ assert!(on_its_way as u32 >= MIN_FRAMES - 1, "{:?}", seen);
+ }
+
#[test]
fn a_dwell_counts_up_while_it_runs_and_only_then() {
let start = Instant::now();
diff --git a/wezterm-gui/src/termwindow/sidebar_slide.rs b/wezterm-gui/src/termwindow/sidebar_slide.rs
new file mode 100644
index 00000000..52a61838
--- /dev/null
+++ b/wezterm-gui/src/termwindow/sidebar_slide.rs
@@ -0,0 +1,1066 @@
+//! A docked sidebar slides out of its edge as it opens, and back in as it
+//! closes.
+//!
+//! Only the picture moves, as with a split's slide. The terminal is laid out
+//! for where the sidebar ends up the moment it is toggled, so its programs
+//! hear of a single resize; each frame after, the panel is drawn shifted
+//! towards its edge by the part of it still to come, or already gone. Beside
+//! the left panel the terminal -- tab row, panes, dividers -- goes along with
+//! the panel's edge rather than waiting under it or beside a gap. The right
+//! panel moves alone: the terminal keeps its left edge, and is narrower or
+//! wider at once. Room the terminal does not reach yet looks like the panes
+//! beside it. Its right edge stays where it is either way, and so do the
+//! buttons along it, at the ends of the tab row and of the panes' bars.
+//!
+//! A panel a hover reveal has out over the terminal, docked, comes the rest
+//! of the way out, and the terminal beside the left one comes out from
+//! under it to make way.
+//!
+//! Either way a panel goes a little past where it goes and comes back: out,
+//! it is off its edge by a sliver for a moment, which is drawn from what it
+//! has at that edge; back, the terminal beside the left one touches the
+//! window's edge and comes back off it. But for a hover reveal docked: that
+//! eases the rest of the way, as the reveal eased out.
+//!
+//! A sidebar on its way back is collapsed already -- the terminal is laid out
+//! without it -- but it is still on screen, as a hover reveal is while it
+//! retreats: it is painted, and counts as presented, until it is gone, and
+//! what it shows is let go of then.
+
+use crate::termwindow::render::split_slide::{progress, Drawn, MOST_PAINTS};
+use crate::ui::anim::{settle, tension, MOST_OVERSHOOT, OVERSHOOT};
+use ::window::{RectF, WindowOps};
+use std::time::{Duration, Instant};
+
+/// A slide's length. A panel gets where it goes in under two thirds of it,
+/// and spends the rest just past there and coming back.
+const DURATION: Duration = Duration::from_millis(240);
+
+/// One of the two sidebars.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(crate) enum Side {
+ Left,
+ Right,
+}
+
+/// How far a sidebar on its way is: from 0 to 1, and a little past either
+/// end on the way to it.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub(crate) struct Out {
+ /// How much of the panel is out...
+ pub(crate) panel: f32,
+ /// ...and how much of it the terminal beside it is clear of: as much,
+ /// but for a hover reveal docked, which the terminal comes out from
+ /// under.
+ pub(crate) clear: f32,
+}
+
+impl Out {
+ /// `out` of the panel out, the terminal along with its edge.
+ pub(crate) fn along(out: f32) -> Self {
+ Self {
+ panel: out,
+ clear: out,
+ }
+ }
+}
+
+/// A sidebar on its way out of its edge, or back in.
+#[derive(Clone, Copy, Debug)]
+struct Slide {
+ opening: bool,
+ /// Where it was as it set off.
+ from: Out,
+ /// See `settle`.
+ tension: f32,
+ started: Instant,
+ /// Frames shown with it so far.
+ shown: u32,
+ /// Times painted with it so far, shown or not.
+ paints: u32,
+}
+
+impl Slide {
+ /// On its way from `from`, going `overshoot` of the way past its end.
+ fn new(opening: bool, from: Out, overshoot: f32, now: Instant) -> Self {
+ Self {
+ opening,
+ from,
+ tension: tension(overshoot),
+ started: now,
+ shown: 0,
+ paints: 0,
+ }
+ }
+
+ /// Where it is; `None` once it is where it goes.
+ fn out(&self, now: Instant) -> Option<Out> {
+ let to = if self.opening { 1.0 } else { 0.0 };
+ progress(self.started, self.shown, DURATION, now).map(|t| {
+ let along = settle(t, self.tension);
+ let clear = self.from.clear + (to - self.from.clear) * along;
+ Out {
+ // The terminal is never clear of more of the panel than is
+ // out.
+ panel: (self.from.panel + (to - self.from.panel) * along).max(clear),
+ clear,
+ }
+ })
+ }
+}
+
+/// Which sidebars went back into their edges.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub(crate) struct Gone {
+ pub(crate) left: bool,
+ pub(crate) right: bool,
+}
+
+/// The sidebars on their way, each one at most.
+#[derive(Debug, Default)]
+pub(crate) struct SidebarSlides {
+ left: Option<Slide>,
+ right: Option<Slide>,
+}
+
+impl SidebarSlides {
+ fn slide(&self, side: Side) -> Option<&Slide> {
+ match side {
+ Side::Left => self.left.as_ref(),
+ Side::Right => self.right.as_ref(),
+ }
+ }
+
+ fn slot(&mut self, side: Side) -> &mut Option<Slide> {
+ match side {
+ Side::Left => &mut self.left,
+ Side::Right => &mut self.right,
+ }
+ }
+
+ /// Set `side` on its way out (`opening`) or back, going `overshoot` of
+ /// the way past its end. One on its way the other way turns round where
+ /// it is, rather than from its end.
+ pub(crate) fn start(&mut self, side: Side, opening: bool, overshoot: f32, now: Instant) {
+ let slot = self.slot(side);
+ if slot.is_some_and(|slide| slide.opening == opening) {
+ return;
+ }
+ let from = slot
+ .and_then(|slide| slide.out(now))
+ .unwrap_or(Out::along(if opening { 0.0 } else { 1.0 }));
+ *slot = Some(Slide::new(opening, from, overshoot, now));
+ }
+
+ /// Set `side` on its way out from `revealed` of it out over the
+ /// terminal, as a hover reveal docked: the rest of it comes out, and the
+ /// terminal beside it out from under it, easing there as the reveal did
+ /// rather than going past.
+ pub(crate) fn dock(&mut self, side: Side, revealed: f32, now: Instant) {
+ let from = Out {
+ panel: revealed,
+ clear: 0.0,
+ };
+ *self.slot(side) = Some(Slide::new(true, from, 0.0, now));
+ }
+
+ /// Where `side` is while it is on its way (see `Out`).
+ pub(crate) fn out(&self, side: Side, now: Instant) -> Option<Out> {
+ let slide = self.slide(side)?;
+ // Past its end and not yet let go of: where it goes.
+ Some(
+ slide
+ .out(now)
+ .unwrap_or(Out::along(if slide.opening { 1.0 } else { 0.0 })),
+ )
+ }
+
+ /// Whether `side` is on its way back: collapsed, and still on screen.
+ pub(crate) fn closing(&self, side: Side) -> bool {
+ self.slide(side).is_some_and(|slide| !slide.opening)
+ }
+
+ /// Whether `side` is on its way, either way.
+ pub(crate) fn sliding(&self, side: Side) -> bool {
+ self.slide(side).is_some()
+ }
+
+ /// Whether `side`'s panel is on its way, rather than out where it docks
+ /// while only the terminal beside it moves.
+ pub(crate) fn panel_moving(&self, side: Side, now: Instant) -> bool {
+ self.out(side, now).is_some_and(|out| out.panel != 1.0)
+ }
+
+ pub(crate) fn is_running(&self) -> bool {
+ self.left.is_some() || self.right.is_some()
+ }
+
+ /// Take a frame's paint: those where they go by now are done. A frame
+ /// painted again -- the quads ran out, a font came in -- is counted
+ /// again, so one that is never shown still comes to an end.
+ pub(crate) fn advance(&mut self, now: Instant) -> Gone {
+ let ended = |slot: &mut Option<Slide>| -> Option<bool> {
+ let slide = slot.as_mut()?;
+ slide.paints += 1;
+ if slide.paints <= MOST_PAINTS && slide.out(now).is_some() {
+ return None;
+ }
+ slot.take().map(|slide| !slide.opening)
+ };
+ Gone {
+ left: ended(&mut self.left).unwrap_or(false),
+ right: ended(&mut self.right).unwrap_or(false),
+ }
+ }
+
+ /// The frame painted with the slides was shown: they are a frame on.
+ pub(crate) fn shown(&mut self) {
+ for slide in [&mut self.left, &mut self.right] {
+ if let Some(slide) = slide.as_mut() {
+ slide.shown += 1;
+ }
+ }
+ }
+
+ /// Put both where they go at once.
+ pub(crate) fn finish(&mut self) -> Gone {
+ Gone {
+ left: self.left.take().is_some_and(|slide| !slide.opening),
+ right: self.right.take().is_some_and(|slide| !slide.opening),
+ }
+ }
+}
+
+/// One sidebar's part in a frame, in window pixels.
+#[derive(Clone, Copy, Debug)]
+pub(crate) struct Panel {
+ /// Its width when it is out.
+ pub(crate) docked: f32,
+ /// The width the terminal is laid out to leave it.
+ pub(crate) laid_out: f32,
+ /// Where it is, while it is on its way.
+ pub(crate) out: Option<Out>,
+}
+
+impl Panel {
+ /// Its width on screen this frame, in whole pixels.
+ fn drawn(&self) -> f32 {
+ match self.out {
+ Some(out) => (out.panel * self.docked).round(),
+ None => self.laid_out,
+ }
+ }
+
+ /// How much of that the terminal beside it is clear of this frame.
+ fn cleared(&self) -> f32 {
+ match self.out {
+ Some(out) => (out.clear * self.docked).round(),
+ None => self.laid_out,
+ }
+ }
+}
+
+/// The bar along the top of a pane at the terminal's right edge, as laid
+/// out: the band it runs along, and where along that the buttons at its
+/// end start.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub(crate) struct EndBar {
+ pub(crate) band: RectF,
+ pub(crate) buttons: f32,
+}
+
+/// How a frame draws the sidebars on their way and the terminal between
+/// them.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub(crate) struct SidebarSlideFrame {
+ /// The left panel, painted where it is docked: drawn towards the
+ /// window's edge by the part of it not out, and cut to the rest.
+ pub(crate) left: Option<Drawn>,
+ /// The right one, likewise.
+ pub(crate) right: Option<Drawn>,
+ /// Past where it docks, a panel is off its window edge by a sliver,
+ /// drawn from what it has at that edge, where it docks.
+ pub(crate) left_sliver: Option<Drawn>,
+ /// The right one's, likewise.
+ pub(crate) right_sliver: Option<Drawn>,
+ /// The terminal, painted where it is laid out: along with the left
+ /// panel's edge, or on its way out from under it, and cut to what is
+ /// between the panels.
+ pub(crate) terminal: Drawn,
+ /// Room between the panels the terminal does not reach yet.
+ pub(crate) room: Option<RectF>,
+}
+
+impl SidebarSlideFrame {
+ /// The frame for `left` and `right` in a window whose panels go out from
+ /// `left_edge` and `right_edge` across `height`; `None` while neither is
+ /// on its way.
+ pub(crate) fn new(
+ left_edge: f32,
+ right_edge: f32,
+ height: f32,
+ left: Panel,
+ right: Panel,
+ ) -> Option<Self> {
+ if left.out.is_none() && right.out.is_none() {
+ return None;
+ }
+ let (left_drawn, right_drawn) = (left.drawn(), right.drawn());
+ let shift = left.cleared() - left.laid_out;
+ // Gone past its edge, a panel is nothing on screen.
+ let (left_on, right_on) = (left_drawn.max(0.), right_drawn.max(0.));
+ let between_left = left_edge + left_on;
+ let between_right = (right_edge - right_on).max(between_left);
+ let terminal = Drawn {
+ shift: (shift, 0.),
+ clip: euclid::rect(between_left, 0., between_right - between_left, height),
+ };
+ // Where the terminal laid out against the right panel ends, drawn.
+ let reach = (right_edge - right.laid_out + shift).max(between_left);
+ let room =
+ (reach < between_right).then(|| euclid::rect(reach, 0., between_right - reach, height));
+ let sliver = |panel: &Panel, drawn: f32, edge: f32| {
+ let past = drawn - panel.docked;
+ (panel.out.is_some() && past > 0.).then(|| Drawn {
+ shift: (0., 0.),
+ clip: euclid::rect(edge, 0., past, height),
+ })
+ };
+ let left_sliver = sliver(&left, left_drawn, left_edge);
+ let right_sliver = sliver(
+ &right,
+ right_drawn,
+ right_edge - (right_drawn - right.docked),
+ );
+ let left = left.out.map(|_| Drawn {
+ shift: (left_drawn - left.docked, 0.),
+ clip: euclid::rect(left_edge, 0., left_on, height),
+ });
+ let right = right.out.map(|_| Drawn {
+ shift: (right.docked - right_drawn, 0.),
+ clip: euclid::rect(right_edge - right_on, 0., right_on, height),
+ });
+ Some(Self {
+ left,
+ right,
+ left_sliver,
+ right_sliver,
+ terminal,
+ room,
+ })
+ }
+
+ /// The pieces the terminal is drawn in, `bars` those along its right
+ /// edge: as `terminal` has it, but for the buttons at the bars' ends,
+ /// which stay where they are, with the bars' tabs cut short of them.
+ /// With them, what of the bars neither covers, to be filled in their
+ /// colour.
+ pub(crate) fn terminal_pieces(&self, bars: &[EndBar]) -> (Vec<Drawn>, Vec<RectF>) {
+ let between = self.terminal.clip;
+ let shift = self.terminal.shift;
+ if shift.0 == 0. {
+ return (vec![self.terminal], vec![]);
+ }
+ let mut bands: Vec<_> = bars
+ .iter()
+ .filter_map(|bar| {
+ let top = bar.band.min_y().max(between.min_y());
+ let bottom = bar.band.max_y().min(between.max_y());
+ (bottom > top).then_some((top, bottom, bar.buttons))
+ })
+ .collect();
+ bands.sort_by(|a, b| a.0.total_cmp(&b.0));
+ let (left, right) = (between.min_x(), between.max_x());
+ let span = |top: f32, bottom: f32, from: f32, to: f32| {
+ euclid::rect(from, top, to - from, bottom - top)
+ };
+ let mut pieces = vec![];
+ let mut bare = vec![];
+ let mut y = between.min_y();
+ for (top, bottom, buttons) in bands {
+ let top = top.max(y);
+ if top >= bottom {
+ continue;
+ }
+ pieces.push(Drawn {
+ shift,
+ clip: span(y, top, left, right),
+ });
+ let ends = buttons.clamp(left, right);
+ // Drawn further left than they stand, the tabs would show the
+ // buttons again.
+ let tabs = (buttons + shift.0.min(0.)).clamp(left, ends);
+ pieces.push(Drawn {
+ shift,
+ clip: span(top, bottom, left, tabs),
+ });
+ pieces.push(Drawn {
+ shift: (0., 0.),
+ clip: span(top, bottom, ends, right),
+ });
+ if ends > tabs {
+ bare.push(span(top, bottom, tabs, ends));
+ }
+ y = bottom;
+ }
+ pieces.push(Drawn {
+ shift,
+ clip: span(y, between.max_y(), left, right),
+ });
+ pieces.retain(|drawn| !drawn.clip.is_empty());
+ (pieces, bare)
+ }
+}
+
+impl crate::TermWindow {
+ /// Set `side` on its way out of its edge (`opening`) or back, unless the
+ /// window draws nothing a slide can move: then the sidebars are where
+ /// they go at once. Returns whether it is on its way.
+ pub(crate) fn slide_sidebar(&mut self, side: Side, opening: bool) -> bool {
+ if !self.sidebar_slides_drawable() {
+ self.finish_sidebar_slides();
+ return false;
+ }
+ let overshoot = self.sidebar_overshoot(side);
+ self.sidebar_slides
+ .start(side, opening, overshoot, Instant::now());
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ true
+ }
+
+ /// Set `side`, docked from a hover reveal `revealed` of the way out, on
+ /// its way the rest of the way, and the terminal beside the left one
+ /// out from under it -- as `slide_sidebar` does, unless the window draws
+ /// nothing a slide can move. Returns whether it is on its way.
+ pub(crate) fn dock_revealed_sidebar(&mut self, side: Side, revealed: f32) -> bool {
+ // All the way out, the right one has nothing to move.
+ if side == Side::Right && revealed >= 1.0 {
+ return false;
+ }
+ if !self.sidebar_slides_drawable() {
+ self.finish_sidebar_slides();
+ return false;
+ }
+ self.sidebar_slides.dock(side, revealed, Instant::now());
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ true
+ }
+
+ /// Whether `side`'s panel is on its way rather than where it docks: what
+ /// it shows is not where it is laid out, so it takes no wheel, as it
+ /// takes no click.
+ pub(crate) fn sidebar_panel_moving(&self, side: Side) -> bool {
+ self.sidebar_slides.panel_moving(side, Instant::now())
+ }
+
+ /// How far past its end `side`'s panel goes, as a share of its width.
+ fn sidebar_overshoot(&self, side: Side) -> f32 {
+ let docked = match side {
+ Side::Left => self.workspace_sidebar_docked_width(),
+ Side::Right => self.right_sidebar_docked_width(),
+ } as f32;
+ OVERSHOOT.min(self.ui_f32(MOST_OVERSHOOT) / docked.max(1.0))
+ }
+
+ /// Whether a frame would draw the sidebars and the terminal between them
+ /// from recordings a slide can move: not while hidden, nor while a view
+ /// holds the terminal's place or is on its way to it, nor when panes are
+ /// painted straight to the window.
+ fn sidebar_slides_drawable(&self) -> bool {
+ self.occluded.is_none()
+ && !self.config.use_box_model_render
+ && !self.content_view_foreground()
+ && self.content_view_fade.is_none()
+ }
+
+ /// Have the sidebars on their way get there now.
+ pub(crate) fn finish_sidebar_slides(&mut self) {
+ let gone = self.sidebar_slides.finish();
+ self.sidebar_slides_gone(gone);
+ }
+
+ /// What a sidebar that went back showed is let go of, as it would have
+ /// been had it collapsed at once.
+ fn sidebar_slides_gone(&mut self, gone: Gone) {
+ if gone.right && self.right_sidebar_collapsed {
+ self.let_go_of_right_sidebar();
+ }
+ }
+
+ /// Take this frame's paint: the slides under way move on, and ask for
+ /// the next frame.
+ pub(crate) fn advance_sidebar_slides(&mut self, now: Instant) {
+ if !self.sidebar_slides.is_running() {
+ return;
+ }
+ if !self.sidebar_slides_drawable() {
+ self.finish_sidebar_slides();
+ return;
+ }
+ let gone = self.sidebar_slides.advance(now);
+ self.sidebar_slides_gone(gone);
+ if self.sidebar_slides.is_running() {
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ }
+ }
+
+ /// How this frame draws the sidebars on their way.
+ pub(crate) fn sidebar_slide_frame(&self, now: Instant) -> Option<SidebarSlideFrame> {
+ let left_out = self.sidebar_slides.out(Side::Left, now);
+ let right_out = self.sidebar_slides.out(Side::Right, now);
+ if left_out.is_none() && right_out.is_none() {
+ return None;
+ }
+ let border = self.get_os_border();
+ SidebarSlideFrame::new(
+ border.left.get() as f32,
+ self.dimensions
+ .pixel_width
+ .saturating_sub(border.right.get()) as f32,
+ self.dimensions.pixel_height as f32,
+ Panel {
+ docked: self.workspace_sidebar_docked_width() as f32,
+ laid_out: self.workspace_sidebar_width() as f32,
+ out: left_out,
+ },
+ Panel {
+ docked: self.right_sidebar_docked_width() as f32,
+ laid_out: self.right_sidebar_width() as f32,
+ out: right_out,
+ },
+ )
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::termwindow::render::split_slide::MIN_FRAMES;
+
+ const FRAME: Duration = Duration::from_micros(16_667);
+ /// How far past its end each slide here goes, as a panel's would.
+ const PAST: f32 = OVERSHOOT;
+
+ /// Where each frame has `side` from `now` on, a frame at a time, until
+ /// it is where it goes, and which sides went back then.
+ fn play_out(slides: &mut SidebarSlides, side: Side, now: &mut Instant) -> (Vec<Out>, Gone) {
+ let mut seen = vec![];
+ loop {
+ let gone = slides.advance(*now);
+ match slides.out(side, *now) {
+ Some(out) => seen.push(out),
+ None => return (seen, gone),
+ }
+ slides.shown();
+ *now += FRAME;
+ assert!(seen.len() < 100, "never got there: {:?}", seen);
+ }
+ }
+
+ /// What each frame shows of `side`'s panel, as `play_out`.
+ fn play(slides: &mut SidebarSlides, side: Side, now: &mut Instant) -> (Vec<f32>, Gone) {
+ let (seen, gone) = play_out(slides, side, now);
+ (seen.iter().map(|out| out.panel).collect(), gone)
+ }
+
+ /// Where `seen` is furthest along `towards` (1 out, 0 back): it goes
+ /// that way up to there, and only back from there on.
+ fn turn_of(seen: &[f32], towards: f32) -> usize {
+ let along = |out: f32| (out - (1.0 - towards)).abs();
+ let top = (0..seen.len())
+ .max_by(|&a, &b| along(seen[a]).total_cmp(&along(seen[b])))
+ .unwrap();
+ assert!(
+ seen[..=top]
+ .windows(2)
+ .all(|pair| along(pair[0]) < along(pair[1])),
+ "{:?}",
+ seen
+ );
+ assert!(
+ seen[top..]
+ .windows(2)
+ .all(|pair| along(pair[0]) >= along(pair[1])),
+ "{:?}",
+ seen
+ );
+ top
+ }
+
+ #[test]
+ fn opening_comes_out_quickly_goes_a_little_past_and_settles() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Left, true, PAST, now);
+ let (seen, gone) = play(&mut slides, Side::Left, &mut now);
+ assert!(seen.len() as u32 >= MIN_FRAMES - 1, "{:?}", seen);
+ // On its way in the first frame, but not most of the way there.
+ assert!(seen[0] > 0.0 && seen[0] < 0.5, "{:?}", seen);
+ // Past where it goes, by no more than it was to, and back.
+ let top = seen[turn_of(&seen, 1.0)];
+ assert!(top > 1.0 && top <= 1.0 + PAST + 1e-3, "{:?}", seen);
+ assert!((seen.last().unwrap() - 1.0).abs() < 0.005, "{:?}", seen);
+ assert_eq!(gone, Gone::default());
+ assert!(!slides.is_running());
+ }
+
+ #[test]
+ fn closing_goes_back_a_little_past_and_says_so_when_it_is_gone() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Right, false, PAST, now);
+ assert!(slides.closing(Side::Right));
+ assert!(!slides.closing(Side::Left));
+ let (seen, gone) = play(&mut slides, Side::Right, &mut now);
+ assert!(seen.len() as u32 >= MIN_FRAMES - 1, "{:?}", seen);
+ // Still most of the way out in the first frame.
+ assert!(seen[0] > 0.5 && seen[0] < 1.0, "{:?}", seen);
+ let bottom = seen[turn_of(&seen, 0.0)];
+ assert!((-PAST - 1e-3..0.0).contains(&bottom), "{:?}", seen);
+ assert_eq!(
+ gone,
+ Gone {
+ left: false,
+ right: true
+ }
+ );
+ assert!(!slides.closing(Side::Right));
+ }
+
+ #[test]
+ fn told_to_go_no_further_it_stops_where_it_goes() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Left, true, 0.0, now);
+ let (seen, _) = play(&mut slides, Side::Left, &mut now);
+ assert!(seen.windows(2).all(|pair| pair[0] < pair[1]), "{:?}", seen);
+ assert!(seen.iter().all(|&out| out <= 1.0), "{:?}", seen);
+ }
+
+ #[test]
+ fn turned_round_it_goes_back_from_where_it_was() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Left, true, PAST, now);
+ let mut last = 0.0;
+ for _ in 0..3 {
+ slides.advance(now);
+ last = slides.out(Side::Left, now).unwrap().panel;
+ slides.shown();
+ now += FRAME;
+ }
+ slides.start(Side::Left, false, PAST, now);
+ let (seen, gone) = play(&mut slides, Side::Left, &mut now);
+ // No jump: the next frame is about a frame's travel from the last.
+ assert!((seen[0] - last).abs() < 0.3, "{} then {:?}", last, seen);
+ assert!(seen[0] < last, "{} then {:?}", last, seen);
+ let bottom = seen[turn_of(&seen, 0.0)];
+ assert!(bottom >= -PAST - 1e-3, "{:?}", seen);
+ assert!(gone.left);
+ }
+
+ #[test]
+ fn asked_the_same_way_again_it_keeps_going() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Right, true, PAST, now);
+ slides.advance(now);
+ slides.shown();
+ now += FRAME;
+ let before = slides.out(Side::Right, now).unwrap();
+ slides.start(Side::Right, true, PAST, now);
+ assert_eq!(slides.out(Side::Right, now), Some(before));
+ }
+
+ #[test]
+ fn one_never_shown_still_ends() {
+ let now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Right, false, PAST, now);
+ let mut paints = 0;
+ while slides.is_running() {
+ // Painted again and again within the same instant, never shown.
+ let gone = slides.advance(now);
+ paints += 1;
+ assert!(paints <= MOST_PAINTS + 1, "{}", paints);
+ if !slides.is_running() {
+ assert!(gone.right);
+ }
+ }
+ }
+
+ #[test]
+ fn finishing_puts_both_where_they_go() {
+ let now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.start(Side::Left, true, PAST, now);
+ slides.start(Side::Right, false, PAST, now);
+ assert_eq!(
+ slides.finish(),
+ Gone {
+ left: false,
+ right: true
+ }
+ );
+ assert!(!slides.is_running());
+ assert_eq!(slides.out(Side::Left, now), None);
+ }
+
+ #[test]
+ fn docked_from_a_reveal_the_terminal_comes_out_from_under_it() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.dock(Side::Left, 1.0, now);
+ assert!(!slides.closing(Side::Left));
+ let (seen, gone) = play_out(&mut slides, Side::Left, &mut now);
+ assert!(seen.len() as u32 >= MIN_FRAMES - 1, "{:?}", seen);
+ // From under the panel, which is out already and stays out...
+ assert!(seen[0].clear > 0.0 && seen[0].clear < 0.5, "{:?}", seen);
+ assert!(seen.iter().all(|out| out.panel == 1.0), "{:?}", seen);
+ // ...easing to where it goes, and no further.
+ assert!(
+ seen.windows(2).all(|pair| pair[0].clear < pair[1].clear),
+ "{:?}",
+ seen
+ );
+ assert!(seen.iter().all(|out| out.clear <= 1.0), "{:?}", seen);
+ let last = seen.last().unwrap();
+ assert!((last.clear - 1.0).abs() < 0.005, "{:?}", seen);
+ assert_eq!(gone, Gone::default());
+ }
+
+ #[test]
+ fn docked_all_the_way_out_the_panel_stays_put() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.dock(Side::Left, 1.0, now);
+ slides.advance(now);
+ assert!(slides.sliding(Side::Left));
+ assert!(!slides.panel_moving(Side::Left, now));
+ slides.dock(Side::Left, 0.4, now);
+ assert!(slides.panel_moving(Side::Left, now));
+ slides.start(Side::Right, true, PAST, now);
+ slides.advance(now);
+ slides.shown();
+ now += FRAME;
+ assert!(slides.panel_moving(Side::Right, now));
+ play_out(&mut slides, Side::Right, &mut now);
+ assert!(!slides.sliding(Side::Right));
+ assert!(!slides.panel_moving(Side::Right, now));
+ }
+
+ #[test]
+ fn docked_part_way_out_the_rest_of_the_panel_comes_out_too() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.dock(Side::Left, 0.4, now);
+ let (seen, _) = play_out(&mut slides, Side::Left, &mut now);
+ // On from where it was, ahead of the terminal coming out from under
+ // it until both get there, and no further.
+ assert!(seen[0].panel > 0.4 && seen[0].panel < 0.8, "{:?}", seen);
+ assert!(seen.iter().all(|out| out.panel >= out.clear), "{:?}", seen);
+ assert!(
+ seen.windows(2).all(|pair| pair[0].panel < pair[1].panel),
+ "{:?}",
+ seen
+ );
+ assert!(seen.iter().all(|out| out.panel <= 1.0), "{:?}", seen);
+ let last = seen.last().unwrap();
+ assert!((last.panel - 1.0).abs() < 0.005, "{:?}", seen);
+ }
+
+ #[test]
+ fn turned_round_coming_out_from_under_it_both_go_back_from_where_they_were() {
+ let mut now = Instant::now();
+ let mut slides = SidebarSlides::default();
+ slides.dock(Side::Left, 1.0, now);
+ let mut last = Out::along(0.0);
+ for _ in 0..2 {
+ slides.advance(now);
+ last = slides.out(Side::Left, now).unwrap();
+ slides.shown();
+ now += FRAME;
+ }
+ slides.start(Side::Left, false, PAST, now);
+ let (seen, gone) = play_out(&mut slides, Side::Left, &mut now);
+ assert!((seen[0].panel - last.panel).abs() < 0.3, "{:?}", seen);
+ assert!((seen[0].clear - last.clear).abs() < 0.3, "{:?}", seen);
+ assert!(seen.iter().all(|out| out.panel >= out.clear), "{:?}", seen);
+ assert!(gone.left);
+ }
+
+ fn panel(docked: f32, laid_out: f32, out: Option<f32>) -> Panel {
+ Panel {
+ docked,
+ laid_out,
+ out: out.map(Out::along),
+ }
+ }
+
+ #[test]
+ fn out_of_a_reveal_the_terminal_is_drawn_from_under_the_panel() {
+ // A quarter of the way out from under a 200 wide panel that is all
+ // the way out, beside a docked 300 wide right one.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ Panel {
+ docked: 200.,
+ laid_out: 200.,
+ out: Some(Out {
+ panel: 1.0,
+ clear: 0.25,
+ }),
+ },
+ panel(300., 300., None),
+ )
+ .unwrap();
+ let left = frame.left.unwrap();
+ assert_eq!(left.shift, (0., 0.));
+ assert_eq!(left.clip, euclid::rect(0., 0., 200., 600.));
+ assert_eq!(frame.left_sliver, None);
+ // Laid out beside all of the panel, and drawn 150 short of there:
+ // under it, but for what is past its edge.
+ assert_eq!(frame.terminal.shift, (-150., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(200., 0., 500., 600.));
+ assert_eq!(frame.room, Some(euclid::rect(550., 0., 150., 600.)));
+ }
+
+ fn bar(top: f32, buttons: f32) -> EndBar {
+ EndBar {
+ band: euclid::rect(200., top, 500., 30.),
+ buttons,
+ }
+ }
+
+ #[test]
+ fn the_buttons_at_the_ends_of_the_bars_stay_where_they_are() {
+ // Going back, the terminal beside the left panel 100 right of where
+ // it is laid out.
+ let terminal = |shift| SidebarSlideFrame {
+ left: None,
+ right: None,
+ left_sliver: None,
+ right_sliver: None,
+ terminal: Drawn {
+ shift: (shift, 0.),
+ clip: euclid::rect(100., 0., 600., 600.),
+ },
+ room: None,
+ };
+ let bars = [bar(300., 600.), bar(40., 620.)];
+ let (pieces, bare) = terminal(100.).terminal_pieces(&bars);
+ let moved = (100., 0.);
+ let expected = [
+ (moved, euclid::rect(100., 0., 600., 40.)),
+ (moved, euclid::rect(100., 40., 520., 30.)),
+ ((0., 0.), euclid::rect(620., 40., 80., 30.)),
+ (moved, euclid::rect(100., 70., 600., 230.)),
+ (moved, euclid::rect(100., 300., 500., 30.)),
+ ((0., 0.), euclid::rect(600., 300., 100., 30.)),
+ (moved, euclid::rect(100., 330., 600., 270.)),
+ ];
+ assert_eq!(
+ pieces
+ .iter()
+ .map(|drawn| (drawn.shift, drawn.clip))
+ .collect::<Vec<_>>(),
+ expected
+ );
+ assert!(bare.is_empty());
+
+ // Coming out, drawn 100 left of there: the tabs stop that much short
+ // of the buttons, the bar's colour between.
+ let (pieces, bare) = terminal(-100.).terminal_pieces(&bars[..1]);
+ assert_eq!(pieces[1].clip, euclid::rect(100., 300., 400., 30.));
+ assert_eq!(pieces[2].shift, (0., 0.));
+ assert_eq!(pieces[2].clip, euclid::rect(600., 300., 100., 30.));
+ assert_eq!(bare, vec![euclid::rect(500., 300., 100., 30.)]);
+
+ // Nothing moving beside the left panel, it is all one piece.
+ let still = terminal(0.);
+ assert_eq!(still.terminal_pieces(&bars), (vec![still.terminal], vec![]));
+ }
+
+ #[test]
+ fn nothing_on_its_way_draws_as_laid_out() {
+ assert_eq!(
+ SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., None),
+ panel(300., 0., None)
+ ),
+ None
+ );
+ }
+
+ #[test]
+ fn the_terminal_rides_the_left_panel_out_and_the_room_behind_is_filled() {
+ // A quarter out of a 200 wide panel, the terminal laid out beside
+ // all of it and a docked 300 wide right panel.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., Some(0.25)),
+ panel(300., 300., None),
+ )
+ .unwrap();
+ let left = frame.left.unwrap();
+ assert_eq!(left.shift, (-150., 0.));
+ assert_eq!(left.clip, euclid::rect(0., 0., 50., 600.));
+ assert_eq!(frame.right, None);
+ assert_eq!(frame.terminal.shift, (-150., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(50., 0., 650., 600.));
+ // Laid out to end at 700, it is drawn to end at 550.
+ assert_eq!(frame.room, Some(euclid::rect(550., 0., 150., 600.)));
+ }
+
+ #[test]
+ fn the_terminal_rides_the_left_panel_back_and_is_cut_short_of_the_right() {
+ let frame = SidebarSlideFrame::new(
+ 10.,
+ 990.,
+ 600.,
+ panel(200., 0., Some(0.5)),
+ panel(300., 0., None),
+ )
+ .unwrap();
+ let left = frame.left.unwrap();
+ assert_eq!(left.shift, (-100., 0.));
+ assert_eq!(left.clip, euclid::rect(10., 0., 100., 600.));
+ assert_eq!(frame.terminal.shift, (100., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(110., 0., 880., 600.));
+ assert_eq!(frame.room, None);
+ }
+
+ #[test]
+ fn the_right_panel_moves_alone() {
+ // Coming out: the terminal is laid out narrower at once, and what
+ // the panel has not covered yet is room.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., None),
+ panel(300., 300., Some(0.5)),
+ )
+ .unwrap();
+ assert_eq!(frame.left, None);
+ let right = frame.right.unwrap();
+ assert_eq!(right.shift, (150., 0.));
+ assert_eq!(right.clip, euclid::rect(850., 0., 150., 600.));
+ assert_eq!(frame.terminal.shift, (0., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(200., 0., 650., 600.));
+ assert_eq!(frame.room, Some(euclid::rect(700., 0., 150., 600.)));
+
+ // Going back: laid out wider at once, and cut where the panel is.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., None),
+ panel(300., 0., Some(0.5)),
+ )
+ .unwrap();
+ assert_eq!(frame.terminal.clip, euclid::rect(200., 0., 650., 600.));
+ assert_eq!(frame.room, None);
+ }
+
+ #[test]
+ fn a_panel_is_drawn_in_whole_pixels() {
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(201., 201., Some(1.0 / 3.0)),
+ panel(0., 0., None),
+ )
+ .unwrap();
+ assert_eq!(frame.left.unwrap().clip.width(), 67.);
+ assert_eq!(frame.terminal.shift, (-134., 0.));
+ }
+
+ #[test]
+ fn past_where_it_docks_a_panel_is_off_its_edge_by_a_sliver() {
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., Some(1.02)),
+ panel(300., 300., Some(1.02)),
+ )
+ .unwrap();
+ let left = frame.left.unwrap();
+ assert_eq!(left.shift, (4., 0.));
+ assert_eq!(left.clip, euclid::rect(0., 0., 204., 600.));
+ let sliver = frame.left_sliver.unwrap();
+ assert_eq!(sliver.shift, (0., 0.));
+ assert_eq!(sliver.clip, euclid::rect(0., 0., 4., 600.));
+ let right = frame.right.unwrap();
+ assert_eq!(right.shift, (-6., 0.));
+ assert_eq!(right.clip, euclid::rect(694., 0., 306., 600.));
+ let sliver = frame.right_sliver.unwrap();
+ assert_eq!(sliver.shift, (0., 0.));
+ assert_eq!(sliver.clip, euclid::rect(994., 0., 6., 600.));
+ // Along with the left one's edge, the terminal is past its place.
+ assert_eq!(frame.terminal.shift, (4., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(204., 0., 490., 600.));
+ assert_eq!(frame.room, None);
+
+ // Short of it, there is none.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., Some(0.98)),
+ panel(300., 300., None),
+ )
+ .unwrap();
+ assert_eq!(frame.left_sliver, None);
+ assert_eq!(frame.right_sliver, None);
+ }
+
+ #[test]
+ fn past_its_edge_a_panel_is_nothing_and_the_terminal_meets_the_window_edge() {
+ // The left one back, and a little past: the terminal beside it is
+ // drawn a little left of its place, room behind it.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 0., Some(-0.02)),
+ panel(300., 0., None),
+ )
+ .unwrap();
+ assert_eq!(frame.left.unwrap().clip.width(), 0.);
+ assert_eq!(frame.left_sliver, None);
+ assert_eq!(frame.terminal.shift, (-4., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(0., 0., 1000., 600.));
+ assert_eq!(frame.room, Some(euclid::rect(996., 0., 4., 600.)));
+
+ // The right one: nothing moves but it.
+ let frame = SidebarSlideFrame::new(
+ 0.,
+ 1000.,
+ 600.,
+ panel(200., 200., None),
+ panel(300., 0., Some(-0.02)),
+ )
+ .unwrap();
+ assert_eq!(frame.right.unwrap().clip.width(), 0.);
+ assert_eq!(frame.right_sliver, None);
+ assert_eq!(frame.terminal.shift, (0., 0.));
+ assert_eq!(frame.terminal.clip, euclid::rect(200., 0., 800., 600.));
+ assert_eq!(frame.room, None);
+ }
+}
diff --git a/wezterm-gui/src/termwindow/space_swipe.rs b/wezterm-gui/src/termwindow/space_swipe.rs
index cbb47caa..f4e2a67a 100644
--- a/wezterm-gui/src/termwindow/space_swipe.rs
+++ b/wezterm-gui/src/termwindow/space_swipe.rs
@@ -422,6 +422,16 @@ impl SidebarSpaceSwipeState {
!matches!(self.phase, Phase::Idle)
}
+ /// Whether the pages are moving sideways: following the finger, waiting
+ /// on a commit, or settling. A gesture still making up its mind, or one
+ /// that went vertical, leaves the list where it is.
+ pub(crate) fn is_sliding(&self) -> bool {
+ matches!(
+ self.phase,
+ Phase::Tracking(_) | Phase::AwaitingCommit(_) | Phase::Settling(_)
+ )
+ }
+
pub(crate) fn is_committing_or_committed(&self) -> bool {
matches!(
&self.phase,
@@ -536,6 +546,26 @@ mod tests {
);
}
+ /// Things drawn over the list -- the jump-to-thread pill -- hide while
+ /// the pages slide, not while the list scrolls.
+ #[test]
+ fn only_a_sideways_gesture_counts_as_sliding() {
+ let start = Instant::now();
+ let mut swipe = SidebarSpaceSwipeState::default();
+ swipe.begin("source".into(), None, Some("next".into()), 0.0, start);
+ assert!(swipe.is_active() && !swipe.is_sliding(), "still deciding");
+ swipe.update(2.0, -20.0, at(start, 16));
+ assert!(swipe.is_active() && !swipe.is_sliding(), "scrolling");
+ swipe.finish(at(start, 40), 300.0);
+
+ 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));
+ assert!(swipe.is_sliding(), "following the finger");
+ swipe.finish(at(start, 32), 300.0);
+ assert!(swipe.is_sliding(), "travelling back or on to the next page");
+ }
+
#[test]
fn the_pages_report_an_offset_while_the_finger_is_still_down() {
// The whole point of following the finger: an offset exists from the
diff --git a/wezterm-gui/src/termwindow/ui/mod.rs b/wezterm-gui/src/termwindow/ui/mod.rs
index 2d024075..4bd21069 100644
--- a/wezterm-gui/src/termwindow/ui/mod.rs
+++ b/wezterm-gui/src/termwindow/ui/mod.rs
@@ -8,6 +8,7 @@ pub mod plugin_panel;
pub mod right_sidebar;
pub mod recording_overlay;
pub mod sidebar;
+pub mod sidebar_jump;
pub mod status_icon;
pub mod tokens;
diff --git a/wezterm-gui/src/termwindow/ui/right_sidebar.rs b/wezterm-gui/src/termwindow/ui/right_sidebar.rs
index 5115b817..7ebd1eef 100644
--- a/wezterm-gui/src/termwindow/ui/right_sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/right_sidebar.rs
@@ -2185,7 +2185,7 @@ impl crate::TermWindow {
/// preview pane and the Note pane; both keep a terminal reserve.
fn right_sidebar_pane_total_max_width(&self) -> usize {
let available_width = self.right_sidebar_available_width();
- let content_width = available_width.saturating_sub(self.workspace_sidebar_width());
+ let content_width = available_width.saturating_sub(self.workspace_sidebar_sizing_width());
let min_preview_total =
self.ui_px(RIGHT_SIDEBAR_MIN_WIDTH) + self.ui_px(FILE_PREVIEW_PANE_MIN_WIDTH);
let terminal_reserve = content_width / 5;
@@ -2321,7 +2321,7 @@ impl crate::TermWindow {
}
/// The width the panel has when it is on screen, docked or not.
- fn right_sidebar_docked_width(&self) -> usize {
+ pub(crate) fn right_sidebar_docked_width(&self) -> usize {
if !self.right_sidebar_has_panels() {
return 0;
}
@@ -2343,7 +2343,7 @@ impl crate::TermWindow {
}
/// The width the panel is DRAWN and HIT-TESTED at: the docked width while
- /// it is docked or hover-revealed, zero otherwise.
+ /// it is docked, hover-revealed or sliding away, zero otherwise.
pub(crate) fn right_sidebar_presented_width(&self) -> usize {
if self.right_sidebar_presented() {
self.right_sidebar_docked_width()
@@ -2352,10 +2352,24 @@ impl crate::TermWindow {
}
}
- /// Whether the panel is on screen at all, docked or by a hover reveal.
- /// What the panel shows follows this; the terminal's layout does not.
+ /// Whether the panel is on screen at all: docked, by a hover reveal, or
+ /// on its way back into the edge. What the panel shows follows this; the
+ /// terminal's layout does not.
pub(crate) fn right_sidebar_presented(&self) -> bool {
- !self.right_sidebar_collapsed || self.right_sidebar_hover.is_presented()
+ !self.right_sidebar_collapsed
+ || self.right_sidebar_hover.is_presented()
+ || self
+ .sidebar_slides
+ .closing(crate::termwindow::sidebar_slide::Side::Right)
+ }
+
+ /// Whether the panel, when it is on screen, is a hover reveal. One on its
+ /// way back from being docked is not: it keeps its shape until it is gone.
+ pub(crate) fn right_sidebar_floats(&self) -> bool {
+ self.right_sidebar_collapsed
+ && !self
+ .sidebar_slides
+ .closing(crate::termwindow::sidebar_slide::Side::Right)
}
pub fn right_sidebar_max_width(&self) -> usize {
@@ -2465,6 +2479,9 @@ impl crate::TermWindow {
}
pub fn toggle_right_sidebar(&mut self) {
+ // Docking a hover reveal moves nothing but what of the panel is not
+ // out yet.
+ let revealed = self.right_sidebar_hover.progress(Instant::now());
// Collapsing must not instantly re-reveal under a pointer still on the
// button, and docking makes a reveal moot.
self.right_sidebar_hover.suppress_until_pointer_leaves();
@@ -2472,16 +2489,31 @@ impl crate::TermWindow {
self.right_sidebar_collapsed = !self.right_sidebar_collapsed;
crate::native_settings::save_right_sidebar_shown(!self.right_sidebar_collapsed);
if self.right_sidebar_collapsed {
- self.right_sidebar_contents_scratch.clear();
if self.right_sidebar_mode == RightSidebarMode::Tasks {
self.clear_right_sidebar_text_focus();
}
- self.drop_hidden_right_sidebar_markdown_preview_focus();
- self.close_plugin_panel();
- self.schedule_right_sidebar_file_memory_release();
- self.release_right_sidebar_remote_files_if_hidden();
- self.schedule_right_sidebar_note_memory_release();
+ if self.slide_sidebar(crate::termwindow::sidebar_slide::Side::Right, false) {
+ // Painted from what it shows until it is gone, but no longer
+ // typed into meanwhile.
+ self.unfocus_right_sidebar_markdown_preview();
+ if self.plugin_panel_has_keyboard() {
+ self.release_plugin_panel_keyboard();
+ }
+ } else {
+ self.let_go_of_right_sidebar();
+ }
} else {
+ match revealed {
+ Some(revealed) => {
+ self.dock_revealed_sidebar(
+ crate::termwindow::sidebar_slide::Side::Right,
+ revealed,
+ );
+ }
+ None => {
+ self.slide_sidebar(crate::termwindow::sidebar_slide::Side::Right, true);
+ }
+ }
self.kick_right_sidebar_file_rescan_cycle();
self.request_right_sidebar_remote_files_connect(false);
if self.right_sidebar_mode == RightSidebarMode::Tasks {
@@ -2491,11 +2523,27 @@ impl crate::TermWindow {
}
}
+ /// Let go of what the collapsed panel showed: as it collapses, or once it
+ /// has slid out of sight.
+ pub(crate) fn let_go_of_right_sidebar(&mut self) {
+ self.right_sidebar_contents_scratch.clear();
+ self.drop_hidden_right_sidebar_markdown_preview_focus();
+ self.close_plugin_panel();
+ self.schedule_right_sidebar_file_memory_release();
+ self.release_right_sidebar_remote_files_if_hidden();
+ self.schedule_right_sidebar_note_memory_release();
+ }
+
pub fn expand_right_sidebar(&mut self) {
+ // Out of nothing it slides out; docked or revealed, it is out already.
+ let hidden = self.right_sidebar_collapsed && !self.right_sidebar_hover.is_presented();
self.right_sidebar_hover.suppress_until_pointer_leaves();
self.right_sidebar_hover_was_presented = false;
self.right_sidebar_collapsed = false;
crate::native_settings::save_right_sidebar_shown(true);
+ if hidden {
+ self.slide_sidebar(crate::termwindow::sidebar_slide::Side::Right, true);
+ }
self.kick_right_sidebar_file_rescan_cycle();
self.request_right_sidebar_remote_files_connect(false);
if self.right_sidebar_mode == RightSidebarMode::Tasks {
@@ -8418,8 +8466,9 @@ impl crate::TermWindow {
// Off macOS the panel has no toggle of its own and the tab bar keeps
// the window buttons at its right end; a hover-revealed panel stays
// below the tab bar so both remain reachable -- below as much of it
- // as is out, when it hides, or below the pane bar holding them.
- if !cfg!(target_os = "macos") && self.right_sidebar_collapsed {
+ // as is out, when it hides, or below the pane bar holding them. A
+ // docked one sliding away keeps its shape.
+ if !cfg!(target_os = "macos") && self.right_sidebar_floats() {
let tab_bar = self.window_top_right_chrome_height().ceil() as usize;
let top = rect.y.saturating_add(tab_bar);
rect.height = rect.height.saturating_sub(top - rect.y);
@@ -8977,7 +9026,7 @@ impl crate::TermWindow {
let y = rect.y + self.ui_px(SIDEBAR_INSET) * 2;
// A non-macOS hover panel already sits below the window buttons and
// has no toggle of its own, so it needs no additional button row.
- let height = if !cfg!(target_os = "macos") && self.right_sidebar_collapsed {
+ let height = if !cfg!(target_os = "macos") && self.right_sidebar_floats() {
0
} else {
self.ui_px(RIGHT_SIDEBAR_TOP_BAR_HEIGHT).min(
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 33211d5e..9c8d4afd 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -5,6 +5,7 @@ use crate::termwindow::render::corners::{
};
use crate::termwindow::ui::icons::{distro_to_icon, BrandIcon, MaterialIcon, SvgIcon};
use crate::termwindow::ui::platform_chrome;
+use crate::termwindow::ui::sidebar_jump::{CurrentRow, Fold, JumpList};
use crate::termwindow::ui::status_icon::UiStatusKind;
use crate::termwindow::ui::tokens::{
CAPSULE_BORDER_WIDTH, SIDEBAR_ICON_GAP, SIDEBAR_INSET, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH,
@@ -32,7 +33,7 @@ use window::color::LinearRgba;
use window::{MouseEventKind as WMEK, RectF, WindowOps};
const SIDEBAR_SCROLLBAR_VISIBLE_MS: u64 = 900;
-const SIDEBAR_SETTINGS_FOOTER_HEIGHT: usize = 72;
+pub(crate) const SIDEBAR_SETTINGS_FOOTER_HEIGHT: usize = 72;
const SIDEBAR_SETTINGS_FADE_HEIGHT: usize = 52;
const SIDEBAR_LIST_BOTTOM_PADDING: usize = 65;
const SIDEBAR_SETTINGS_ROW_TOP_PADDING: usize = 4;
@@ -232,7 +233,7 @@ impl crate::TermWindow {
/// The docked width, clamped. Not "the width right now": ask
/// `workspace_sidebar_width` for what the terminal is laid out against
/// and `workspace_sidebar_presented_width` for what is on screen.
- fn workspace_sidebar_docked_width(&self) -> usize {
+ pub(crate) fn workspace_sidebar_docked_width(&self) -> usize {
let min_width = scale_ui_usize(SIDEBAR_MIN_WIDTH, self.dimensions.dpi);
self.workspace_sidebar_width
.clamp(min_width, self.workspace_sidebar_max_width())
@@ -243,6 +244,14 @@ impl crate::TermWindow {
/// Every consumer that decides where the terminal, the tab bar or a pane
/// lives asks this one.
pub fn workspace_sidebar_width(&self) -> usize {
+ self.workspace_sidebar_sizing_width()
+ }
+
+ /// The width the terminal's SIZE is worked out against: the sidebar's,
+ /// the Library open or not. The Library pushes the terminal aside, past
+ /// the window's edge, rather than making it narrower, so its programs
+ /// hear of no resize.
+ pub(crate) fn workspace_sidebar_sizing_width(&self) -> usize {
if self.workspace_sidebar_collapsed {
0
} else {
@@ -253,22 +262,24 @@ impl crate::TermWindow {
/// The width the panel is DRAWN and HIT-TESTED at. Equal to
/// `workspace_sidebar_width` while docked; the full docked width while a
/// hover reveal is on screen, at which point the terminal behind it has
- /// not moved. Presentation and pointer routing only.
+ /// not moved, and while it slides away after collapsing. Presentation
+ /// and pointer routing only.
pub(crate) fn workspace_sidebar_presented_width(&self) -> usize {
- if self.workspace_sidebar_collapsed {
- if self.workspace_sidebar_hover.is_presented() {
- self.workspace_sidebar_docked_width()
- } else {
- 0
- }
- } else {
+ if self.workspace_sidebar_is_presented() {
self.workspace_sidebar_docked_width()
+ } else {
+ 0
}
}
- /// Whether the panel is on screen at all, by either route.
+ /// Whether the panel is on screen at all, by any route: docked, a hover
+ /// reveal, or on its way back into the edge.
pub(crate) fn workspace_sidebar_is_presented(&self) -> bool {
- !self.workspace_sidebar_collapsed || self.workspace_sidebar_hover.is_presented()
+ !self.workspace_sidebar_collapsed
+ || self.workspace_sidebar_hover.is_presented()
+ || self
+ .sidebar_slides
+ .closing(crate::termwindow::sidebar_slide::Side::Left)
}
pub fn workspace_sidebar_max_width(&self) -> usize {
@@ -304,17 +315,33 @@ impl crate::TermWindow {
/// setting, brushing the left edge and clicking "close" would re-dock the
/// sidebar for every window from then on.
pub fn toggle_workspace_sidebar(&mut self) {
- let shown = workspace_sidebar_toggle_target(
- self.workspace_sidebar_collapsed,
- self.workspace_sidebar_hover.is_presented(),
- );
+ let revealed = self.workspace_sidebar_hover.progress(Instant::now());
+ let shown =
+ workspace_sidebar_toggle_target(self.workspace_sidebar_collapsed, revealed.is_some());
self.workspace_sidebar_swipe.cancel_immediately();
self.clear_workspace_space_swipe_frame_transition();
self.set_workspace_sidebar_shown(shown);
+ match revealed.filter(|_| shown) {
+ // Out over the terminal already, or on its way: the terminal
+ // comes out from under it.
+ Some(revealed) => {
+ self.dock_revealed_sidebar(crate::termwindow::sidebar_slide::Side::Left, revealed);
+ }
+ None => {
+ self.slide_sidebar(crate::termwindow::sidebar_slide::Side::Left, shown);
+ }
+ }
}
pub fn expand_workspace_sidebar(&mut self) {
self.set_workspace_sidebar_shown(true);
+ // Docked while on its way back: it comes out again from there.
+ if self
+ .sidebar_slides
+ .closing(crate::termwindow::sidebar_slide::Side::Left)
+ {
+ self.slide_sidebar(crate::termwindow::sidebar_slide::Side::Left, true);
+ }
}
/// Dock or collapse the panel and persist that choice.
@@ -1110,7 +1137,7 @@ impl crate::TermWindow {
self.window_tab_chrome_params().sidebar_toggle_button_size()
}
- fn workspace_sidebar_content_top(&self, panel_y: usize) -> usize {
+ pub(crate) fn workspace_sidebar_content_top(&self, panel_y: usize) -> usize {
let tab_row_height = self.tab_bar_pixel_height().unwrap_or(0.0).ceil() as usize;
platform_chrome::workspace_sidebar_content_top(
panel_y,
@@ -2006,6 +2033,9 @@ impl crate::TermWindow {
);
total_height.saturating_sub(viewport_height) as f32
};
+ if self.workspace_sidebar_preview_space_id.is_none() {
+ self.advance_sidebar_jump_scroll(Instant::now());
+ }
let scroll_offset = self.workspace_sidebar_scroll_offset.clamp(0.0, max_scroll);
if self.workspace_sidebar_preview_space_id.is_none() {
// Writing the clamp back is what stops the sidebar staying scrolled
@@ -2022,6 +2052,15 @@ impl crate::TermWindow {
.as_ref()
.is_some_and(|event| matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_)));
let mut virtual_y = 0usize;
+ // The row of the thread this window shows, wherever it is, for the
+ // pill that brings it back into sight.
+ let mut current_row: Option<CurrentRow> = None;
+ let thread_icon = |session: &workspace_threads::WorkspaceThreadView| {
+ row_marks
+ .icons(&session.id, session.is_materialized)
+ .first()
+ .cloned()
+ };
// Everything from here until the end of the project loop scrolls with
// `virtual_y`. A space-swipe slides exactly this stretch and leaves the
// chrome painted before and after it standing.
@@ -2073,6 +2112,11 @@ impl crate::TermWindow {
let hit_y = row_top.max(list_top_f).floor().max(0.0) as usize;
let hit_bottom = row_bottom.min(content_bottom_f).ceil().max(hit_y as f32) as usize;
let hit_height = hit_bottom.saturating_sub(hit_y).max(1);
+ if current_row.is_none()
+ && self.is_workspace_sidebar_thread_selected(session, suppress_own_active)
+ {
+ current_row = Some(CurrentRow::new(virtual_y, None, thread_icon(session)));
+ }
if row_is_visible {
self.ui_items.push(UIItem {
@@ -2520,6 +2564,10 @@ impl crate::TermWindow {
let is_selected =
self.is_workspace_sidebar_thread_selected(session, suppress_own_active);
+ if is_selected && current_row.is_none() {
+ current_row =
+ Some(CurrentRow::new(virtual_y, None, thread_icon(session)));
+ }
if row_is_visible && is_selected {
let row_rect = euclid::rect(
session_x as f32,
@@ -2684,6 +2732,22 @@ impl crate::TermWindow {
virtual_y += session_row_height + row_gap;
}
+ } else if current_row.is_none() {
+ // Folded away: where it would be once its folder opens.
+ if let Some((index, session)) =
+ project.threads.iter().enumerate().find(|(_, session)| {
+ self.is_workspace_sidebar_thread_selected(session, suppress_own_active)
+ })
+ {
+ current_row = Some(CurrentRow::new(
+ virtual_y + index * (session_row_height + row_gap),
+ Some((
+ Fold::Project(project.id.clone()),
+ virtual_y.saturating_sub(session_row_height + row_gap),
+ )),
+ thread_icon(session),
+ ));
+ }
}
}
@@ -2865,6 +2929,22 @@ impl crate::TermWindow {
virtual_y += session_row_height + row_gap;
if group.collapsed {
+ if current_row.is_none() {
+ if let Some((index, reference)) =
+ group.threads.iter().enumerate().find(|(_, reference)| {
+ self.is_workspace_sidebar_thread_selected(&reference.thread, false)
+ })
+ {
+ current_row = Some(CurrentRow::new(
+ virtual_y + index * (session_row_height + row_gap),
+ Some((
+ Fold::RefGroup(format!("{group_space_id}::{}", group.key)),
+ virtual_y.saturating_sub(session_row_height + row_gap),
+ )),
+ thread_icon(&reference.thread),
+ ));
+ }
+ }
continue;
}
let session_x =
@@ -2883,6 +2963,11 @@ impl crate::TermWindow {
let hit_bottom =
row_bottom.min(content_bottom_f).ceil().max(hit_y as f32) as usize;
let hit_height = hit_bottom.saturating_sub(hit_y).max(1);
+ if current_row.is_none()
+ && self.is_workspace_sidebar_thread_selected(session, false)
+ {
+ current_row = Some(CurrentRow::new(virtual_y, None, thread_icon(session)));
+ }
if row_is_visible {
// A dangling ref has nothing to activate; it paints
@@ -3606,9 +3691,9 @@ impl crate::TermWindow {
let settings_body_width = overview_action_x
.saturating_sub(settings_row_x)
.saturating_sub(self.ui_px(SIDEBAR_INSET) / 2);
- // When the label cannot fit, the whole row collapses to an
- // icon-sized pill: a full-width hover capsule around a lone gear
- // reads as a broken button.
+ // The Library's button, an icon on its own: settings live in the
+ // Library now. Sized as the settings button was once its label
+ // no longer fit, so the row keeps its shape.
let settings_icon_probe = icon_size.min(settings_row_height.saturating_sub(8));
let settings_label = crate::i18n::tr("sidebar-settings");
let settings_label_x_inset = self.ui_px(SIDEBAR_SETTINGS_ICON_EXTRA_INSET)
@@ -3851,23 +3936,6 @@ impl crate::TermWindow {
)
.context("sidebar update dot")?;
}
- // A truncated "S…" reads worse than no label: when the sidebar is
- // too narrow for the whole word, the gear icon stands alone (and
- // the row shrank to an icon pill above).
- if settings_label_fits {
- self.paint_sidebar_text(
- layers,
- &ui_font,
- ui_metrics,
- &settings_label,
- settings_text_x,
- settings_text_y,
- settings_body_width
- .saturating_sub(settings_text_x.saturating_sub(settings_row_x))
- .saturating_sub(self.ui_px(SIDEBAR_INSET)),
- foreground,
- )?;
- }
if SHOW_SIDEBAR_VIEW_OPTIONS {
let settings_action_icon_size = settings_icon_size;
self.paint_sidebar_icon(
@@ -3887,6 +3955,33 @@ impl crate::TermWindow {
}
}
+ // Over everything that covers the list, and not for a neighbouring
+ // Space painted only to slide in.
+ if self.workspace_sidebar_preview_space_id.is_none() {
+ // Clear of the Settings row, which is lifted over the list.
+ let list_bottom = if settings_footer_height > 0 {
+ (settings_footer_y + self.ui_px(SIDEBAR_SETTINGS_ROW_TOP_PADDING))
+ .saturating_sub(self.ui_px(SIDEBAR_SETTINGS_ROW_LIFT))
+ .min(content_bottom)
+ } else {
+ content_bottom
+ };
+ self.paint_sidebar_jump(
+ layers,
+ current_row,
+ JumpList {
+ x: panel_x,
+ width: panel_width,
+ top: list_top,
+ bottom: list_bottom.max(list_top),
+ scroll: scroll_offset,
+ max_scroll,
+ row_height: session_row_height,
+ },
+ &chrome,
+ )?;
+ }
+
if self.workspace_sidebar_scrollbar_visible() {
self.update_next_frame_time(self.workspace_sidebar_scrollbar_visible_until);
}
diff --git a/wezterm-gui/src/termwindow/ui/sidebar_jump.rs b/wezterm-gui/src/termwindow/ui/sidebar_jump.rs
new file mode 100644
index 00000000..d651ebf4
--- /dev/null
+++ b/wezterm-gui/src/termwindow/ui/sidebar_jump.rs
@@ -0,0 +1,478 @@
+//! The pill that floats at an edge of the left sidebar's thread list while
+//! the thread the window is showing is out of sight -- scrolled away, or
+//! folded into its project. It carries that thread's icon and an arrow
+//! pointing where it is; a click unfolds its folder if need be and scrolls
+//! the list back to it.
+
+use crate::quad::TripleLayerQuadAllocator;
+use crate::tab_icons::ResolvedIcon;
+use crate::termwindow::ui::icons::SvgIcon;
+use crate::termwindow::ui::sidebar::over;
+use crate::termwindow::{UIItem, UIItemType};
+use crate::ui::anim::{self, Easing, Timeline};
+use crate::ui::draw::DrawContext;
+use crate::ui::UiPalette;
+use anyhow::Context;
+use std::time::{Duration, Instant};
+use window::color::LinearRgba;
+use window::{RectF, WindowOps};
+
+/// The pill's height, and the icon and arrow in it, in sidebar pixels.
+const HEIGHT: usize = 56;
+const ICON: usize = 36;
+const ARROW: usize = 28;
+const GAP: usize = 6;
+const PAD_RIGHT: usize = 14;
+/// How far in from the list's edge it floats.
+const MARGIN: usize = 14;
+/// How far it travels in from the edge as it comes.
+const TRAVEL: f32 = 10.0;
+/// How far the arrow leans the way it points under the pointer.
+const NUDGE: f32 = 2.5;
+/// A click presses it in and lets it back out over this long.
+const PRESS: Duration = Duration::from_millis(200);
+const PRESSED_SCALE: f32 = 0.94;
+const FRAME: Duration = Duration::from_millis(16);
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+enum Edge {
+ #[default]
+ Top,
+ Bottom,
+}
+
+/// The folder a thread is folded away in.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub(crate) enum Fold {
+ Project(String),
+ /// A reference group, by its key in `thread_ref_groups_collapsed`.
+ RefGroup(String),
+}
+
+/// Where the paint walking the list found the thread the window shows.
+pub(crate) struct CurrentRow {
+ /// Its top in the list, unscrolled; for a folded one, where it would
+ /// be once its folder opens.
+ pub(crate) top: usize,
+ /// The top of what stands for it on screen: the row itself, or the
+ /// row of the folder it is folded in.
+ pub(crate) anchor: usize,
+ pub(crate) fold: Option<Fold>,
+ pub(crate) icon: Option<ResolvedIcon>,
+}
+
+impl CurrentRow {
+ /// A row at `top`; `folder` is the folder it is folded in, and the top
+ /// of that folder's row.
+ pub(crate) fn new(
+ top: usize,
+ folder: Option<(Fold, usize)>,
+ icon: Option<ResolvedIcon>,
+ ) -> Self {
+ let (fold, anchor) = match folder {
+ Some((fold, folder_top)) => (Some(fold), folder_top),
+ None => (None, top),
+ };
+ Self {
+ top,
+ anchor,
+ fold,
+ icon,
+ }
+ }
+}
+
+/// The list the pill floats over, as this paint laid it out.
+pub(crate) struct JumpList {
+ pub(crate) x: usize,
+ pub(crate) width: usize,
+ /// The part of the list nothing covers: under the header, above the
+ /// Settings row.
+ pub(crate) top: usize,
+ pub(crate) bottom: usize,
+ pub(crate) scroll: f32,
+ pub(crate) max_scroll: f32,
+ pub(crate) row_height: usize,
+}
+
+/// One window's pill, and the scroll a click starts, between frames.
+#[derive(Default)]
+pub(crate) struct SidebarJump {
+ edge: Edge,
+ /// Whether the arrow points up, at the thread or its folder.
+ up: bool,
+ /// How far in it is, 0 to 1.
+ shown: Option<Timeline>,
+ showing: bool,
+ /// How far the hover look has come, 0 to 1.
+ hover: Option<Timeline>,
+ hovered: bool,
+ pressed_at: Option<Instant>,
+ /// What it shows, kept so it can fade out showing it.
+ icon: Option<ResolvedIcon>,
+ /// The folder the last paint found the thread folded in, for a click.
+ fold: Option<Fold>,
+ /// A click asked for the thread: the next paint, which knows where its
+ /// row is once its folder is open, starts the scroll.
+ reveal: bool,
+ scroll: Option<Timeline>,
+ /// The offset the scroll last wrote. Anything else found there is the
+ /// user scrolling meanwhile, and the hand wins.
+ scroll_wrote: f32,
+}
+
+/// Where the pill goes, and whether its arrow points up, for a row centred
+/// at `centre` over a list showing `top..bottom`; `anchor` is the centre of
+/// what stands for the row on screen -- the row itself, or the row of the
+/// folder it is `folded` in. `None` while the row is in sight.
+fn place(centre: f32, anchor: f32, folded: bool, top: f32, bottom: f32) -> Option<(Edge, bool)> {
+ if !folded && centre >= top && centre <= bottom {
+ return None;
+ }
+ Some(if anchor < top {
+ (Edge::Top, true)
+ } else if anchor > bottom {
+ (Edge::Bottom, false)
+ } else if anchor < (top + bottom) / 2.0 {
+ // A folder in sight: the far edge, clear of it, pointing back.
+ (Edge::Bottom, true)
+ } else {
+ (Edge::Top, false)
+ })
+}
+
+/// The offset that puts the row at `row_top` in the middle of a list
+/// `viewport` high, clear of both edges, as far as the list goes.
+fn scroll_target(row_top: usize, row_height: usize, viewport: f32, max_scroll: f32) -> f32 {
+ (row_top as f32 + row_height as f32 / 2.0 - viewport / 2.0).clamp(0.0, max_scroll.max(0.0))
+}
+
+impl crate::TermWindow {
+ /// Move the list on along a scroll a click started. Called before the
+ /// paint reads the offset.
+ pub(crate) fn advance_sidebar_jump_scroll(&mut self, now: Instant) {
+ let jump = &mut self.sidebar_jump;
+ let Some(scroll) = jump.scroll.as_mut() else {
+ return;
+ };
+ if (self.workspace_sidebar_scroll_offset - jump.scroll_wrote).abs() > 0.5 {
+ jump.scroll = None;
+ return;
+ }
+ let running = scroll.advance(now);
+ let offset = scroll.value(now);
+ self.workspace_sidebar_scroll_offset = offset;
+ jump.scroll_wrote = offset;
+ if running {
+ self.update_next_frame_time(Some(now + FRAME));
+ } else {
+ jump.scroll = None;
+ }
+ }
+
+ /// The pill was clicked.
+ pub(crate) fn activate_sidebar_jump(&mut self) {
+ let jump = &mut self.sidebar_jump;
+ if !jump.showing {
+ return;
+ }
+ jump.pressed_at = Some(Instant::now());
+ jump.reveal = true;
+ match jump.fold.take() {
+ Some(Fold::Project(project_id)) => {
+ crate::workspace_threads::expand_project_threads(&project_id);
+ }
+ Some(Fold::RefGroup(key)) => {
+ self.thread_ref_groups_collapsed.remove(&key);
+ }
+ None => {}
+ }
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ }
+
+ /// Paint the pill over the list, after everything that covers the list:
+ /// shown while `current` is out of sight, fading in and out.
+ pub(crate) fn paint_sidebar_jump(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator,
+ current: Option<CurrentRow>,
+ list: JumpList,
+ chrome: &UiPalette,
+ ) -> anyhow::Result<()> {
+ let now = Instant::now();
+ let reveal = std::mem::take(&mut self.sidebar_jump.reveal);
+ // A swipe slides the list out from under it, and the pill would
+ // stand still over the wrong Space. Scrolling the list up and down
+ // is the gesture's other way and keeps it.
+ if self.workspace_sidebar_swipe.is_sliding() || self.workspace_space_swipe_push_active {
+ let jump = &mut self.sidebar_jump;
+ jump.shown = None;
+ jump.showing = false;
+ return Ok(());
+ }
+
+ let (top, bottom) = (list.top as f32, list.bottom as f32);
+ let row_height = list.row_height as f32;
+ let mut want = None;
+ if let Some(row) = current.as_ref() {
+ // Centres on screen, against the uncovered list.
+ let centre = top + row.top as f32 + row_height / 2.0 - list.scroll;
+ let anchor = top + row.anchor as f32 + row_height / 2.0 - list.scroll;
+ let place = place(centre, anchor, row.fold.is_some(), top, bottom);
+ if reveal && row.fold.is_none() && place.is_some() {
+ let from = self.workspace_sidebar_scroll_offset;
+ let to = scroll_target(row.top, list.row_height, bottom - top, list.max_scroll);
+ let duration = if (to - from).abs() > bottom - top {
+ anim::LONG
+ } else {
+ anim::STANDARD
+ };
+ let jump = &mut self.sidebar_jump;
+ jump.scroll = Some(Timeline::running(now, from, to, duration, Easing::OutCubic));
+ jump.scroll_wrote = from;
+ self.show_workspace_sidebar_scrollbar();
+ self.update_next_frame_time(Some(now + FRAME));
+ }
+ let dragging = self
+ .sidebar_row_drag
+ .as_ref()
+ .is_some_and(|drag| drag.active);
+ if !dragging && self.sidebar_jump.scroll.is_none() {
+ want = place;
+ }
+ }
+
+ let jump = &mut self.sidebar_jump;
+ if want.is_none() && jump.shown.is_none() {
+ return Ok(());
+ }
+ if let Some((edge, up)) = want {
+ if (jump.edge, jump.up) != (edge, up) {
+ // Another place is another pill: it comes in from its edge.
+ jump.edge = edge;
+ jump.up = up;
+ jump.shown = None;
+ jump.showing = false;
+ }
+ jump.icon = current.as_ref().and_then(|row| row.icon.clone());
+ jump.fold = current.as_ref().and_then(|row| row.fold.clone());
+ }
+ let shown = jump
+ .shown
+ .get_or_insert_with(|| Timeline::settled(now, 0.0));
+ if want.is_some() != jump.showing {
+ jump.showing = want.is_some();
+ let (to, duration) = if jump.showing {
+ (1.0, anim::SHORT)
+ } else {
+ (0.0, anim::MICRO)
+ };
+ shown.retarget(now, to, duration, Easing::OutCubic);
+ }
+ let mut animating = shown.advance(now);
+ let shown_value = shown.value(now).clamp(0.0, 1.0);
+ // A click outlasts the fade: it holds the pill's place until its
+ // press is over (see the hit area below).
+ let pressing = jump
+ .pressed_at
+ .is_some_and(|at| now.saturating_duration_since(at) < PRESS);
+ if !jump.showing && !animating && !pressing {
+ *jump = SidebarJump {
+ scroll: jump.scroll.take(),
+ scroll_wrote: jump.scroll_wrote,
+ ..SidebarJump::default()
+ };
+ return Ok(());
+ }
+ let Some(icon) = jump.icon.clone() else {
+ return Ok(());
+ };
+ let edge = jump.edge;
+ let up = jump.up;
+ let showing = jump.showing;
+
+ let height = self.ui_px(HEIGHT) as f32;
+ let icon_size = self.ui_px(ICON) as f32;
+ let arrow_size = self.ui_px(ARROW) as f32;
+ let pad = (height - icon_size) / 2.0;
+ let width =
+ pad + icon_size + self.ui_px(GAP) as f32 + arrow_size + self.ui_px(PAD_RIGHT) as f32;
+ let x = (list.x as f32 + (list.width as f32 - width) / 2.0).round();
+ let travel = (1.0 - shown_value) * self.ui_f32(TRAVEL);
+ let y = match edge {
+ Edge::Top => list.top as f32 + self.ui_px(MARGIN) as f32 - travel,
+ Edge::Bottom => list.bottom as f32 - self.ui_px(MARGIN) as f32 - height + travel,
+ }
+ .round();
+ let rest: RectF = euclid::rect(x, y, width, height);
+
+ // Only one that is coming takes the pointer: one on its way out has
+ // done its job.
+ let hovered = showing
+ && self.is_pointer_over_ui_rect(
+ rest.origin.x as usize,
+ rest.origin.y as usize,
+ rest.size.width as usize,
+ rest.size.height as usize,
+ );
+ let jump = &mut self.sidebar_jump;
+ let hover = jump
+ .hover
+ .get_or_insert_with(|| Timeline::settled(now, 0.0));
+ if hovered != jump.hovered {
+ jump.hovered = hovered;
+ hover.retarget(
+ now,
+ if hovered { 1.0 } else { 0.0 },
+ anim::MICRO,
+ Easing::Smooth,
+ );
+ }
+ animating |= hover.advance(now);
+ let hover_value = hover.value(now).clamp(0.0, 1.0);
+ // How far in the click has it, 0 to 1 and back.
+ let press = match jump.pressed_at {
+ Some(at) if now.saturating_duration_since(at) < PRESS => {
+ animating = true;
+ let t = now.saturating_duration_since(at).as_secs_f32() / PRESS.as_secs_f32();
+ (std::f32::consts::PI * t).sin()
+ }
+ Some(_) => {
+ jump.pressed_at = None;
+ 0.0
+ }
+ None => 0.0,
+ };
+
+ let scale = 1.0 - (1.0 - PRESSED_SCALE) * press;
+ let rect: RectF = euclid::rect(
+ rest.center().x - width * scale / 2.0,
+ rest.center().y - height * scale / 2.0,
+ width * scale,
+ height * scale,
+ );
+ let alpha = shown_value;
+ // The selected row's grey, solid over the sidebar: rows pass under it.
+ let base = over(chrome.sidebar_row_active_bg, chrome.workspace_sidebar_bg);
+ let fill = crate::ui::color::mix(base, chrome.text, 0.07 * hover_value + 0.08 * press);
+ let dark = chrome.is_dark();
+ let shadow = LinearRgba::with_components(0.0, 0.0, 0.0, if dark { 0.5 } else { 0.22 });
+ let arrow_color = crate::ui::color::mix(chrome.secondary_text, chrome.text, hover_value);
+ let lean = hover_value * self.ui_f32(NUDGE);
+ let (arrow, lean) = if up {
+ (SvgIcon::ArrowUp, -lean)
+ } else {
+ (SvgIcon::ArrowDown, lean)
+ };
+
+ if alpha > 0.0 {
+ let gl_state = self
+ .render_state
+ .as_ref()
+ .context("sidebar jump render state")?;
+ let ctx = DrawContext::new(gl_state, self.dimensions, &self.render_metrics);
+ ctx.draw_elevated_surface(
+ layers,
+ 2,
+ rect,
+ fill.mul_alpha(alpha),
+ chrome.sidebar_row_active_border.mul_alpha(alpha),
+ shadow.mul_alpha(alpha),
+ rect.size.height / 2.0,
+ )
+ .context("sidebar jump pill")?;
+ let icon_d = (icon_size * scale).round();
+ let cy = rect.center().y;
+ crate::thread_marks::draw_alone(
+ &ctx,
+ layers,
+ &icon,
+ (rect.origin.x + pad * scale).round(),
+ (cy - icon_d / 2.0).round(),
+ icon_d,
+ dark,
+ alpha,
+ )
+ .context("sidebar jump icon")?;
+ let arrow_d = (arrow_size * scale).round();
+ ctx.draw_svg_icon(
+ layers,
+ arrow,
+ (rect.origin.x + (pad + icon_size + self.ui_px(GAP) as f32) * scale).round(),
+ (cy - arrow_d / 2.0 + lean).round(),
+ arrow_d,
+ arrow_color.mul_alpha(alpha),
+ )
+ .context("sidebar jump arrow")?;
+ }
+
+ // Held for as long as it is drawn and through its press, even on its
+ // way out: a click there -- a double click's second press -- would
+ // otherwise land on the row under it. Only a pill that is coming
+ // acts on it (`activate_sidebar_jump`).
+ self.ui_items.push(UIItem {
+ x: rest.origin.x as usize,
+ y: rest.origin.y as usize,
+ width: rest.size.width as usize,
+ height: rest.size.height as usize,
+ item_type: UIItemType::WorkspaceSidebarJump,
+ });
+ if animating {
+ self.update_next_frame_time(Some(now + FRAME));
+ }
+ Ok(())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn a_row_in_sight_needs_no_pill() {
+ assert_eq!(place(300.0, 300.0, false, 100.0, 500.0), None);
+ }
+
+ #[test]
+ fn a_row_out_of_sight_is_pointed_at_from_its_side() {
+ assert_eq!(
+ place(40.0, 40.0, false, 100.0, 500.0),
+ Some((Edge::Top, true))
+ );
+ assert_eq!(
+ place(700.0, 700.0, false, 100.0, 500.0),
+ Some((Edge::Bottom, false))
+ );
+ }
+
+ #[test]
+ fn a_folded_row_points_at_its_folder_from_clear_of_it() {
+ // Its folder scrolled away: the folder's side.
+ assert_eq!(
+ place(300.0, 40.0, true, 100.0, 500.0),
+ Some((Edge::Top, true))
+ );
+ assert_eq!(
+ place(800.0, 700.0, true, 100.0, 500.0),
+ Some((Edge::Bottom, false))
+ );
+ // Its folder in sight: the far edge, pointing back at it.
+ assert_eq!(
+ place(250.0, 200.0, true, 100.0, 500.0),
+ Some((Edge::Bottom, true))
+ );
+ assert_eq!(
+ place(450.0, 400.0, true, 100.0, 500.0),
+ Some((Edge::Top, false))
+ );
+ }
+
+ #[test]
+ fn the_scroll_centres_the_row_as_far_as_the_list_goes() {
+ assert_eq!(scroll_target(1000, 60, 400.0, 5000.0), 830.0);
+ assert_eq!(scroll_target(50, 60, 400.0, 5000.0), 0.0);
+ assert_eq!(scroll_target(1000, 60, 400.0, 600.0), 600.0);
+ }
+}
diff --git a/wezterm-gui/src/thread_marks.rs b/wezterm-gui/src/thread_marks.rs
index eb1ba854..3b8fc6de 100644
--- a/wezterm-gui/src/thread_marks.rs
+++ b/wezterm-gui/src/thread_marks.rs
@@ -304,6 +304,44 @@ fn draw_icon(
Ok(())
}
+/// One icon on its own, `alpha` of the way in: the sidebar's jump pill
+/// fades the icon of the thread it stands for in and out with itself.
+#[allow(clippy::too_many_arguments)]
+pub(crate) fn draw_alone(
+ ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator,
+ icon: &ResolvedIcon,
+ x: f32,
+ y: f32,
+ d: f32,
+ dark: bool,
+ alpha: f32,
+) -> Result<()> {
+ crate::ui::tile::draw_tile(
+ ctx,
+ layers,
+ LAYER,
+ x,
+ y,
+ d,
+ d / 2.0,
+ icon.circle.linear().mul_alpha(alpha),
+ dark,
+ &tab_icons::PLATE,
+ )?;
+ let size = (d * TAB_ICON_GLYPH_RATIO).round();
+ tab_icons::draw_glyph(
+ ctx,
+ layers,
+ LAYER,
+ &icon.glyph,
+ x + (d - size) / 2.0,
+ y + (d - size) / 2.0,
+ size,
+ icon.glyph_color.linear().mul_alpha(alpha),
+ )
+}
+
/// A neutral disc saying how many more programs there are.
#[allow(clippy::too_many_arguments)]
fn draw_count(
diff --git a/wezterm-gui/src/ui/anim.rs b/wezterm-gui/src/ui/anim.rs
index ff217205..3142ef02 100644
--- a/wezterm-gui/src/ui/anim.rs
+++ b/wezterm-gui/src/ui/anim.rs
@@ -34,12 +34,22 @@ pub(crate) const LONG: Duration = Duration::from_millis(300);
/// keep asking for frames forever.
const PRESENT_GRACE: Duration = Duration::from_millis(120);
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+/// How far past its target a move that settles goes, as a share of its
+/// way...
+pub(crate) const OVERSHOOT: f32 = 0.0125;
+/// ...and never further than this, at the design scale: a long way's share
+/// would be a lurch.
+pub(crate) const MOST_OVERSHOOT: f32 = 4.0;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum Easing {
/// Decelerate into the target. The default for anything that moves: the
/// destination is already on screen, so slowing into it reads as the thing
/// arriving. Accelerating away from the start reads as a stall instead.
OutCubic,
+ /// `OutCubic` that goes a little past the target and comes back, as a
+ /// sidebar set sliding does: see [`settle`]. Made by [`Self::settling`].
+ Settle(f32),
/// Symmetric. For opacity, where there is no position for the eye to
/// track and a hard start is what looks wrong.
Smooth,
@@ -47,16 +57,45 @@ pub(crate) enum Easing {
}
impl Easing {
+ /// Settling at most `overshoot` of the way past the target.
+ pub(crate) fn settling(overshoot: f32) -> Self {
+ Self::Settle(tension(overshoot))
+ }
+
pub(crate) fn apply(self, t: f32) -> f32 {
let t = t.clamp(0.0, 1.0);
match self {
Self::OutCubic => 1.0 - (1.0 - t).powi(3),
+ Self::Settle(tension) => settle(t, tension),
Self::Smooth => t * t * (3.0 - 2.0 * t),
Self::Linear => t,
}
}
}
+/// From 0 to 1: quick, then a little past 1 and back. A back-out curve, its
+/// tension from `tension`; none is a plain cubic ease out.
+pub(crate) fn settle(t: f32, tension: f32) -> f32 {
+ let u = t.clamp(0.0, 1.0) - 1.0;
+ 1.0 + (tension + 1.0) * u.powi(3) + tension * u.powi(2)
+}
+
+/// The tension that takes `settle` `overshoot` past 1 at most. It goes
+/// 4s³/27(s+1)² past, which grows with s.
+pub(crate) fn tension(overshoot: f32) -> f32 {
+ let past = |s: f32| 4.0 * s.powi(3) / (27.0 * (s + 1.0).powi(2));
+ let (mut low, mut high) = (0.0f32, 4.0f32);
+ for _ in 0..24 {
+ let mid = (low + high) / 2.0;
+ if past(mid) < overshoot {
+ low = mid;
+ } else {
+ high = mid;
+ }
+ }
+ low
+}
+
/// One value travelling from `from` to `to` over `duration`.
///
/// Drive it by calling [`Self::advance`] once per frame and asking for
@@ -66,6 +105,8 @@ pub(crate) struct Timeline {
from: f32,
to: f32,
duration: Duration,
+ /// How long it was made to take, which [`Self::reshape`] stretches.
+ unstretched: Duration,
easing: Easing,
/// When the clock actually started, which is later than construction --
/// see [`Self::advance`]. `None` while still waiting.
@@ -78,6 +119,8 @@ pub(crate) struct Timeline {
/// timeline has that its opening frame was drawn. A `Cell` so painting can
/// keep taking `&self`.
presented: Cell<bool>,
+ /// The frame [`Self::pace`] last saw, if it is being paced.
+ paced_at: Option<Instant>,
finished: bool,
}
@@ -87,11 +130,13 @@ impl Timeline {
from,
to,
duration,
+ unstretched: duration,
easing,
started_at: None,
armed_at: now,
delay: Duration::ZERO,
presented: Cell::new(false),
+ paced_at: None,
finished: from == to || duration.is_zero(),
}
}
@@ -177,6 +222,20 @@ impl Timeline {
true
}
+ /// Let the clock have run no more than `most` since the last frame:
+ /// one that took longer has the rest held back, so the travel takes
+ /// longer rather than skip most of its way. A busy window or a build
+ /// without optimisation can take several such frames in a row, past the
+ /// opening one [`Self::advance`] already waits out.
+ ///
+ /// Call this once per frame painted, before `advance`.
+ pub(crate) fn pace(&mut self, now: Instant, most: Duration) {
+ if let (Some(started_at), Some(paced_at)) = (self.started_at.as_mut(), self.paced_at) {
+ *started_at += now.saturating_duration_since(paced_at).saturating_sub(most);
+ }
+ self.paced_at = Some(now);
+ }
+
pub(crate) fn value(&self, now: Instant) -> f32 {
self.presented.set(true);
if self.finished {
@@ -196,6 +255,18 @@ impl Timeline {
self.from + (self.to - self.from) * self.easing.apply(t)
}
+ /// Ease with `easing` instead, taking `by` times as long as it was made
+ /// to: for a value whose way is only known once it is set going. Only
+ /// before the clock starts, so it does not jump; asked again by then, it
+ /// is as if asked once.
+ pub(crate) fn reshape(&mut self, easing: Easing, by: f32) {
+ if self.started_at.is_some() {
+ return;
+ }
+ self.easing = easing;
+ self.duration = self.unstretched.mul_f32(by);
+ }
+
/// Send the value somewhere else, departing from wherever it is right now.
///
/// The current position is the only correct origin for a redirection. A
@@ -317,6 +388,88 @@ mod tests {
assert_eq!(timeline.arrives_at(), Some(at(start, 300)));
}
+ #[test]
+ fn the_tension_found_goes_as_far_past_as_asked() {
+ assert_eq!(tension(0.0), 0.0);
+ for overshoot in [0.01, OVERSHOOT, 0.1] {
+ let tension = tension(overshoot);
+ let top = (0..=1000)
+ .map(|step| settle(step as f32 / 1000.0, tension))
+ .fold(0.0, f32::max);
+ assert!(
+ (top - 1.0 - overshoot).abs() < 1e-3,
+ "{} went {} past",
+ overshoot,
+ top - 1.0
+ );
+ }
+ }
+
+ #[test]
+ fn settling_goes_a_little_past_and_lands_on_the_target() {
+ let start = Instant::now();
+ let mut timeline = Timeline::new(
+ start,
+ 100.0,
+ 0.0,
+ Duration::from_millis(200),
+ Easing::settling(OVERSHOOT),
+ );
+ timeline.advance(at(start, 0));
+ timeline.value(at(start, 0));
+ timeline.advance(at(start, 0));
+ let seen: Vec<f32> = (0..=200)
+ .map(|millis| timeline.value(at(start, millis)))
+ .collect();
+ let lowest = seen.iter().copied().fold(f32::MAX, f32::min);
+ assert!(
+ lowest < 0.0 && lowest >= -100.0 * OVERSHOOT - 1e-3,
+ "{}",
+ lowest
+ );
+ assert_eq!(seen.last(), Some(&0.0));
+ }
+
+ #[test]
+ fn reshaped_before_it_starts_it_takes_as_much_longer_and_no_more() {
+ let start = Instant::now();
+ let mut timeline = armed(start);
+ timeline.reshape(Easing::OutCubic, 1.5);
+ // Asked again before it starts -- its picture recorded again -- it
+ // is not stretched twice.
+ timeline.reshape(Easing::OutCubic, 1.5);
+ timeline.advance(at(start, 0));
+ timeline.value(at(start, 0));
+ timeline.advance(at(start, 0));
+ assert_eq!(timeline.arrives_at(), Some(at(start, 300)));
+ assert!(timeline.value(at(start, 200)) < 100.0);
+ // Under way, it is left as it goes.
+ let before = timeline.value(at(start, 100));
+ timeline.reshape(Easing::Linear, 3.0);
+ assert_eq!(timeline.value(at(start, 100)), before);
+ assert_eq!(timeline.arrives_at(), Some(at(start, 300)));
+ }
+
+ #[test]
+ fn paced_a_slow_frame_moves_it_no_further_than_a_quick_one() {
+ let start = Instant::now();
+ let mut timeline = armed(start);
+ let frame = |timeline: &mut Timeline, millis| {
+ timeline.pace(at(start, millis), Duration::from_millis(20));
+ timeline.advance(at(start, millis));
+ timeline.value(at(start, millis))
+ };
+ let near = |value: f32, expected: f32| (value - expected).abs() < 1e-3;
+ assert_eq!(frame(&mut timeline, 0), 0.0);
+ assert_eq!(frame(&mut timeline, 10), 0.0);
+ // Two frames of 100ms go 20ms each...
+ assert!(near(frame(&mut timeline, 110), 10.0));
+ assert!(near(frame(&mut timeline, 210), 20.0));
+ // ...and quick ones after them carry on from there.
+ assert!(near(frame(&mut timeline, 220), 25.0));
+ assert_eq!(timeline.arrives_at(), Some(at(start, 370)));
+ }
+
#[test]
fn finishing_early_lands_on_the_target() {
let start = Instant::now();
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 84e2a191..f9008284 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -6099,6 +6099,16 @@ pub fn toggle_project_threads_collapsed(project_id: &str) -> bool {
changed
}
+/// Open a project's folded thread list; false when it was open already.
+pub fn expand_project_threads(project_id: &str) -> bool {
+ let mut store = THREAD_STORE.lock();
+ let changed = store.expand_project_threads(project_id);
+ if changed {
+ persist_locked(&store);
+ }
+ changed
+}
+
fn thread_views_for_project(
project: &Project,
active_project_id: Option<&str>,
@@ -9356,6 +9366,18 @@ impl WorkspaceThreadStore {
true
}
+ fn expand_project_threads(&mut self, project_id: &str) -> bool {
+ let Some(project) = self
+ .projects
+ .iter_mut()
+ .find(|project| project.id == project_id && project.threads_collapsed)
+ else {
+ return false;
+ };
+ project.threads_collapsed = false;
+ true
+ }
+
/// Move a project so it renders directly before `before` in its Space
/// (or last when `before` is None). The projects Vec interleaves every
/// Space; only the relative order within this Space changes. Returns