A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
fix(gui): cut from the travelling terminal to its overview card
RoversXc27209ff03fd
diff --git a/wezterm-gui/src/termwindow/content_view.rs b/wezterm-gui/src/termwindow/content_view.rsindex 0240c707..0120d7cf 100644--- a/wezterm-gui/src/termwindow/content_view.rs+++ b/wezterm-gui/src/termwindow/content_view.rs@@ -55,10 +55,12 @@ pub(crate) struct ContentViewFade {/// already gone by the time the flight is resolved -- so a close records/// the answer while it still can.pub(crate) pending_destination: Option<RectF>,- /// The travelling terminal dissolving into the card's own thumbnail of it,- /// started once the two are close enough in size to overlap. `None` until+ /// The travelling terminal giving way to what it lands on: a cut to the+ /// card's own thumbnail once it has arrived and that thumbnail is recorded+ /// (`flight_lands_in_card`), or -- with no card to land in -- a dissolve+ /// started once it is close to the size of its destination. `None` until/// then, and for the whole of a closing transition -- growing back out of- /// a card, there is nothing on the far side to dissolve into.+ /// a card, there is nothing on the far side to give way to.pub(crate) landing: Option<crate::ui::anim::Timeline>,/// When this transition began, in wall-clock time.///@@ -86,6 +88,69 @@ pub(crate) fn transition_holds_input(elapsed: Duration) -> bool {elapsed < TRANSITION_INPUT_HOLD}+/// How long a terminal that has arrived at its card may wait there for the+/// card's own picture before giving way to the card regardless.+///+/// Counted from the arrival, not from the start of the transition: the travel's+/// clock only starts once the opening frame has been presented, and a slow+/// opening frame would otherwise spend the wait before the terminal got+/// anywhere. The picture is built while the terminal travels and is normally+/// there before it arrives; running out means one that could not be captured,+/// or a build still unfinished, which then appears as it completes.+pub(crate) const FLIGHT_LANDING_WAIT: Duration = Duration::from_millis(300);++/// Whether the terminal travelling into its card gives way to the card now.+///+/// Giving way is a cut, not a dissolve. The two are the same rows laid out+/// twice -- the terminal as the window drew it, tab strip and pane headers+/// included, and the card's own layout at its own scale -- so no glyph of one+/// lands on its counterpart in the other. Dissolving them showed both at+/// partial strength, and the thumbnail, still being built when the dissolve+/// began, not at all: the card went dark for a few frames and came back on+/// every open. A cut between two near pictures is a small shift the eye+/// forgives.+///+/// Only once the terminal has arrived: cutting while it is still larger than+/// the card would snap the picture down by the difference. And only once the+/// card has its own picture recorded, so the cut lands on that picture rather+/// than on an empty panel -- unless `waited` since the arrival has reached+/// [`FLIGHT_LANDING_WAIT`].+pub(crate) fn flight_lands_in_card(+ travel_running: bool,+ thumbnail_recorded: bool,+ waited: Duration,+) -> bool {+ !travel_running && (thumbnail_recorded || waited >= FLIGHT_LANDING_WAIT)+}++#[cfg(test)]+mod card_landing_tests {+ use super::*;++ #[test]+ fn a_travelling_terminal_does_not_cut_even_to_a_ready_card() {+ assert!(!flight_lands_in_card(true, true, Duration::ZERO));+ }++ #[test]+ fn an_arrived_terminal_cuts_to_its_recorded_card() {+ assert!(flight_lands_in_card(false, true, Duration::ZERO));+ }++ #[test]+ fn an_arrived_terminal_waits_for_its_card_but_not_for_ever() {+ assert!(!flight_lands_in_card(false, false, Duration::from_millis(100)));+ assert!(flight_lands_in_card(false, false, FLIGHT_LANDING_WAIT));+ }++ #[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+ );+ }+}+#[cfg(test)]mod flight_rect_tests {use super::*;@@ -266,26 +331,25 @@ pub(crate) struct ContentViewFlight {/// Which terminal is travelling, so the arriving view can be re-asked/// where it now keeps a place for it.pub(crate) tab_id: Option<TabId>,+ /// Whether the view had a card for this terminal when it was recorded, so+ /// the landing is a cut to that card rather than a dissolve. Decided once:+ /// asked again on a pass that stopped partway through the view's paint,+ /// the view could answer without the card and turn the cut into a+ /// dissolve.+ pub(crate) lands_in_card: bool,}-/// How much larger than its card the travelling terminal may still be when the-/// two are first allowed to overlap.-///-/// Loose, because the overlap itself is cheap: the eased opacity is still flat-/// at 1.0 for the first quarter of the dissolve, and by the time the recording-/// is visibly translucent the mismatch is already under 1%. What made the-/// earlier attempt read as two pictures was not the mismatch on its own but-/// the flat panel colour showing between them -- the card drew no thumbnail-/// while its terminal was in flight, so there was nothing to dissolve into.-/// With an aligned copy of the same picture underneath, a few percent of size-/// difference is not what the eye is looking at.+/// How much larger than its destination a terminal with no card to land in+/// may still be when it starts dissolving away. Landing in a card is a cut,+/// made once the terminal has arrived (`flight_lands_in_card`).///-/// Tightening this is what made the first version invisible: 3% left about two-/// usable frames, which is a cut with extra steps.+/// Loose, because a dissolve takes a while to show: the eased opacity is still+/// flat at 1.0 for its first quarter. Tightened to 3%, it left about two+/// usable frames -- a cut with extra steps.const FLIGHT_LANDING_OVERSIZE: f32 = 0.12;-/// Whether the travelling terminal has closed to within touching distance of-/// the card it is landing in.+/// Whether a terminal with no card to land in has closed to within touching+/// distance of its destination, where it starts dissolving away.////// Measured in size, not in time and not in distance already covered. The/// travel eases out, so a window written in either of those spends most of@@ -441,6 +505,10 @@ pub(crate) struct TerminalPreviewRequest {/// How opaque to draw it, 0 to 1. A card changing tab draws the old/// picture fading out under the new one fading in.pub opacity: f32,+ /// Build the picture but do not draw it: the card a terminal is flying+ /// into, which has to be ready when the terminal lands on it and must not+ /// show before then.+ pub prebuild: bool,}/// Progress of an SSH connection that a content view kicked off, pushed by thediff --git a/wezterm-gui/src/termwindow/live_overview.rs b/wezterm-gui/src/termwindow/live_overview.rsindex b9f84630..a07ea5b9 100644--- a/wezterm-gui/src/termwindow/live_overview.rs+++ b/wezterm-gui/src/termwindow/live_overview.rs@@ -534,6 +534,9 @@ pub(crate) struct LiveOverviewView {/// eye is following, and a second copy waiting in the slot is what made/// the transition look like two layers.terminal_in_flight: Option<TabId>,+ /// 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>,visible_panes: HashSet<PaneId>,live_resizing: bool,card_motion: HashMap<LiveThreadKey, CardMotion>,@@ -600,6 +603,7 @@ impl LiveOverviewView {preview_chrome: Vec::new(),card_preview_rects: HashMap::new(),terminal_in_flight: None,+ terminal_in_flight_since: None,visible_panes: HashSet::new(),live_resizing: false,card_motion: HashMap::new(),@@ -1015,6 +1019,7 @@ impl LiveOverviewView {// 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 {@@ -1022,16 +1027,42 @@ impl LiveOverviewView {.get(&card.tab_id).map(|cached| Arc::clone(&cached.snapshot))} else {- let fingerprint = terminal_preview_fingerprint(card.tab_id);- let (snapshot, refresh_due) = resolve_snapshot(- &mut self.snapshot_cache,- &card.tab_id,- fingerprint,- now,- refresh_interval,- &mut capture_budget,- || capture_terminal_snapshot(card.tab_id),- );+ // The card the terminal is landing in captures on+ // an allowance of its own: its picture has to be+ // built by the time the terminal arrives, and the+ // shared budget is spent from the top of the grid+ // down, so a card further down could wait out the+ // flight for its turn. Once captured it keeps that+ // picture until it lands: a terminal that keeps+ // printing would otherwise hand it a new snapshot+ // every refresh, each one restarting a build that+ // might never finish in between.+ let landing_capture = self+ .terminal_in_flight_since+ .filter(|_| in_flight)+ .and_then(|since| {+ self.snapshot_cache+ .get(&card.tab_id)+ .filter(|cached| cached.captured_at >= since)+ })+ .map(|cached| Arc::clone(&cached.snapshot));+ let mut landing_budget = 1;+ let (snapshot, refresh_due) = match landing_capture {+ Some(snapshot) => (Some(snapshot), None),+ None => resolve_snapshot(+ &mut self.snapshot_cache,+ &card.tab_id,+ terminal_preview_fingerprint(card.tab_id),+ now,+ refresh_interval,+ if in_flight {+ &mut landing_budget+ } else {+ &mut capture_budget+ },+ || capture_terminal_snapshot(card.tab_id),+ ),+ };if let Some(refresh_due) = refresh_due {// A `Some` here means the card's fingerprint no// longer matches what was captured. A future@@ -1139,7 +1170,6 @@ impl LiveOverviewView {preview_width,preview_width / self.host_preview_aspect,);- let in_flight = self.terminal_in_flight == Some(tab_id);// A card whose terminal is currently flying to it is left// empty, but not neutral: the panel takes that terminal's// own background so the arriving picture settles onto the@@ -1167,7 +1197,27 @@ impl LiveOverviewView {preview_fill,ctx.px(PREVIEW_RADIUS),)?;- if !in_flight {+ if in_flight {+ // Built, not shown. The terminal arriving here+ // gives way to this picture as it lands+ // (`flight_lands_in_card`), so it has to be+ // recorded by then -- and the renderer keeps+ // only the pictures a frame asks for. Left out+ // of the requests, the card lost its picture on+ // every open and the landing revealed a bare+ // panel while it was rebuilt.+ if let Some(snapshot) = snapshot.as_ref() {+ self.previews.push(TerminalPreviewRequest {+ tab_id,+ snapshot: Arc::clone(snapshot),+ area: preview,+ clip,+ hold_scale: self.live_resizing,+ opacity: 0.0,+ prebuild: true,+ });+ }+ } else {// A card that changed tab fades the old// picture out under the new one. The old// tab's snapshot is kept warm for the length@@ -1184,6 +1234,7 @@ impl LiveOverviewView {clip,hold_scale: self.live_resizing,opacity: 1.0 - arrived,+ prebuild: false,});}}@@ -1195,6 +1246,7 @@ impl LiveOverviewView {clip,hold_scale: self.live_resizing,opacity: arrived,+ prebuild: false,});self.visible_panes.extend(snapshot.panes.iter().map(|pane| pane.pane_id));@@ -2383,6 +2435,11 @@ impl ContentView for LiveOverviewView {}fn set_terminal_in_flight(&mut self, tab_id: Option<TabId>) {+ if tab_id.is_none() {+ self.terminal_in_flight_since = None;+ } else if tab_id != self.terminal_in_flight {+ self.terminal_in_flight_since = Some(Instant::now());+ }self.terminal_in_flight = tab_id;}diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 930fd3d5..00460b29 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -474,17 +474,15 @@ const CONTENT_VIEW_FADE: Duration = Duration::from_millis(140);/// registers as a jump rather than as travel.const CONTENT_VIEW_TRAVEL: Duration = Duration::from_millis(260);-/// How long the travelling terminal takes to dissolve into the card's own-/// thumbnail of it, once the two are close enough in size to overlap.+/// How long the travelling terminal takes to dissolve away when the arriving+/// view has no card for it to land in, once it is close to the size of its+/// destination.////// Long enough to be seen, which is a lower bound with real teeth: a timeline/// does not start its clock until the frame after it is armed, so a dissolve-/// budgeted at 45ms spent one frame arming and left two usable ones. That is a-/// cut with extra steps, and it is what the first version of this shipped as.+/// budgeted at 45ms spent one frame arming and left two usable ones.///-/// Deliberately outlasts the travel. The last stretch of it therefore runs-/// after the terminal has settled into the card, where the two pictures are-/// aligned exactly and the dissolve costs nothing at all.+/// Landing in a card is a cut instead (`content_view::flight_lands_in_card`).const CONTENT_VIEW_LANDING_FADE: Duration = Duration::from_millis(140);/// How long the window frame takes to clear its own edges. Shorter than thediff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex b39e74da..e2687f48 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -129,6 +129,20 @@ fn snapshot_has_content(.any(|pane| pane.lines.iter().any(|line| !line.is_whitespace()))}+/// When the fade-in of a card first seen with content starts: now, or -- for a+/// card being built out of sight (`TerminalPreviewRequest::prebuild`), the one+/// a terminal is flying into -- a whole ramp ago, so that it is settled when+/// it is shown. The ramp softens a blank card filling in on screen; one+/// started out of sight would still be running, at whatever point, when the+/// landing reveals the card.+fn preview_fade_start(now: Instant, prebuild: bool) -> Instant {+ if prebuild {+ now.checked_sub(PREVIEW_CONTENT_FADE).unwrap_or(now)+ } else {+ now+ }+}+/// Everything a card's recorded quads depend on.////// Equal keys mean the recorded heap still draws the right picture and can be@@ -1496,39 +1510,85 @@ impl crate::TermWindow {/// sidebar, below the tab bar)./// Advance a full-window view's arrival or departure.fn advance_content_view_fade(&mut self, now: Instant) {+ // Read before the fade is borrowed for advancing: whether the+ // travelling terminal lands in a card, and if so whether that card's+ // own picture is recorded yet.+ let card_recorded = self+ .content_view_landing_tab()+ .map(|tab_id| self.preview_thumbnail_recorded(tab_id));let Some(fade) = self.content_view_fade.as_mut() else {return;};- // Once the travelling terminal has closed to within touching distance- // of its card, hand the card back its own thumbnail and dissolve the- // recording into it. Both pictures are then on screen at the same- // rectangle, which is the only arrangement in which a dissolve reads as- // one thing settling rather than as two things overlapping.+ // Hand the card back its own thumbnail as the travelling terminal+ // reaches it. Into a card that is a cut, made once the terminal has+ // arrived and the card's picture is recorded underneath it+ // (`flight_lands_in_card`); until then the terminal holds at the card+ // and the frames keep coming. With no card to land in, the recording+ // dissolves away as it nears its destination.let mut landed = false;+ let mut awaiting_card = false;if fade.landing.is_none() && fade.travel.target() >= 0.5 {- if let Some(flight) = fade.flight.as_ref() {- if crate::termwindow::content_view::flight_is_landing(- flight.source,- flight.destination,- fade.travel.value(now),- ) {- fade.landing = Some(crate::ui::anim::Timeline::new(- now,- 1.0,- 0.0,- crate::termwindow::CONTENT_VIEW_LANDING_FADE,- crate::ui::anim::Easing::Smooth,- ));- landed = true;+ // How long the terminal has been sitting where it was going:+ // nothing while it is still on its way.+ let waited = fade+ .travel+ .arrives_at()+ .map_or(Duration::ZERO, |at| now.saturating_duration_since(at));+ match fade.flight.as_ref() {+ Some(flight) => {+ let landing = match card_recorded {+ Some(recorded) => crate::termwindow::content_view::flight_lands_in_card(+ fade.travel.is_running(),+ recorded,+ waited,+ )+ // Already over: the terminal is not drawn from this+ // frame on. Even a millisecond-long timeline left a+ // frame with the terminal half transparent over the+ // thumbnail, its clock having started less than a+ // millisecond before the terminal was drawn.+ .then(|| crate::ui::anim::Timeline::settled(now, 0.0)),+ None => crate::termwindow::content_view::flight_is_landing(+ flight.source,+ flight.destination,+ fade.travel.value(now),+ )+ .then(|| {+ crate::ui::anim::Timeline::new(+ now,+ 1.0,+ 0.0,+ crate::termwindow::CONTENT_VIEW_LANDING_FADE,+ crate::ui::anim::Easing::Smooth,+ )+ }),+ };+ match landing {+ Some(landing) => {+ fade.landing = Some(landing);+ landed = true;+ }+ None => awaiting_card = card_recorded.is_some(),+ }+ }+ // Discarded with the atlas it was drawn from+ // (`discard_content_view_captures_after_atlas_recreation`) and+ // recorded again on this pass. The transition must not end+ // underneath it meanwhile -- it had nothing left running and+ // ended in that same pass, cutting to whatever the card had --+ // but nor may it wait for ever.+ None => {+ awaiting_card = waited < crate::termwindow::content_view::FLIGHT_LANDING_WAIT;}}}let travelling = fade.travel.advance(now)| fade.chrome_travel.advance(now)- | fade.landing.as_mut().is_some_and(|fade| fade.advance(now));+ | fade.landing.as_mut().is_some_and(|fade| fade.advance(now))+ | awaiting_card;if landed {// Painted after this runs, so the thumbnail appears underneath the- // dissolve on this very frame rather than one frame late.+ // landing terminal on this very frame rather than one frame late.if let Some(view) = self.active_content_view_mut() {view.set_terminal_in_flight(None);}@@ -1583,10 +1643,10 @@ impl crate::TermWindow {/// Replay the recorded terminal at the size its travel has reached.////// It rides above the view: the terminal is shrinking *into* the card, so- /// it has to be seen crossing the grid that is arriving underneath it. The- /// last stretch is spent fading, because what it lands on is the card's- /// own thumbnail of the same terminal drawn from the same snapshot -- near- /// enough to blend into, not near enough to cut to.+ /// it has to be seen crossing the grid that is arriving underneath it.+ /// Once it has arrived it gives way to the card's own thumbnail of the same+ /// terminal in a cut (`content_view::flight_lands_in_card` says why not a+ /// dissolve); with no card to land in, it dissolves away instead.fn paint_content_view_flight(&self, now: Instant) -> anyhow::Result<()> {let Some(fade) = self.content_view_fade.as_ref() else {return Ok(());@@ -1597,20 +1657,11 @@ impl crate::TermWindow {let Some((source, target)) = self.content_view_flight_rects(now) else {return Ok(());};- // Opaque for all of the journey but the landing.- //- // An earlier version faded over the last tenth of the *distance*, and- // ease-out spends its time unevenly: that tenth is nearly half of the- // duration, so the fade ran translucent for seven frames at a size- // 3-18% off the card it was landing on. Worse, the card drew no- // thumbnail while its terminal was in flight, so there was nothing on- // the far side to dissolve into -- only the flat panel colour. Two- // misaligned pictures with a panel showing between them is exactly- // what "it looks like two layers" meant.- //- // Both of those are now addressed rather than avoided: the window is- // bounded by size instead of by distance, and the card is handed its- // thumbnail back as the window opens. See `flight_is_landing`.+ // Opaque for all of the journey but the landing, which into a card is+ // a cut over a thumbnail already recorded underneath it: the card's+ // picture is built out of sight during the flight+ // (`TerminalPreviewRequest::prebuild`) and the landing waits for it+ // (`flight_lands_in_card`).let opacity = fade.landing.as_ref().map_or(1.0, |fade| fade.value(now));let gl_state = self.render_state.as_ref().unwrap();@@ -2144,7 +2195,8 @@ impl crate::TermWindow {.unwrap_or_else(|| self.window_rect());// The view must not draw its own copy of a terminal that is currently// crossing the window towards it.- if destination != self.window_rect() {+ let lands_in_card = destination != self.window_rect();+ if lands_in_card {if let Some(view) = self.active_content_view_mut() {view.set_terminal_in_flight(tab_id);}@@ -2156,6 +2208,7 @@ impl crate::TermWindow {source,destination,tab_id,+ lands_in_card,recording_revision:crate::termwindow::ui::recording_overlay::recording_mask_revision(),});@@ -2474,19 +2527,48 @@ impl crate::TermWindow {if !previews.is_empty() {self.preview_cache_last_wanted = Some(Instant::now());let live: HashSet<TabId> = previews.iter().map(|preview| preview.tab_id).collect();+ // Nor is a card on screen that has not been captured yet. The view+ // is made anew on every open and captures a few cards a frame, so+ // on its first frames most cards ask for nothing -- and the+ // picture each had last time is what it shows until it has been+ // rebuilt.+ let kept = |tab_id: &TabId| {+ live.contains(tab_id)+ || self+ .active_content_view()+ .is_some_and(|view| view.terminal_landing_rect(*tab_id).is_some())+ };self.preview_quad_cache.borrow_mut()- .retain(|tab_id, _| live.contains(tab_id));+ .retain(|tab_id, _| kept(tab_id));self.preview_content_fade.borrow_mut()- .retain(|tab_id, _| live.contains(tab_id));- // Same policy for a rebuild sliced across frames: its card is gone.- let mut partial = self.preview_rebuild_partial.borrow_mut();- if partial+ .retain(|tab_id, _| kept(tab_id));+ // Same policy for a rebuild sliced across frames when its card is+ // gone, or when the card no longer wants the picture being built --+ // back at the size it already has a picture for, say. Nothing would+ // continue such a build, and while it held the slot, `continuing`+ // below kept every other card waiting on it.+ let obsolete = self+ .preview_rebuild_partial+ .borrow().as_ref()- .is_some_and(|partial| !live.contains(&partial.tab_id))- {- *partial = None;+ .is_some_and(|partial| {+ previews+ .iter()+ .find(|preview| preview.tab_id == partial.tab_id)+ .map_or(true, |preview| {+ partial.key+ != preview_quad_key(+ preview,+ &self.dimensions,+ self.shape_generation,+ self.preview_scale_estimate(preview),+ )+ })+ });+ if obsolete {+ *self.preview_rebuild_partial.borrow_mut() = None;}}let started = crate::perf::now();@@ -2501,8 +2583,19 @@ impl crate::TermWindow {// frame, so the picture is at worst one frame out of date and the cost// is spread instead of spiked.let mut budget = MAX_PREVIEW_QUAD_REBUILDS_PER_FRAME;+ // A card part of the way through a build sliced across frames goes+ // first. There is one slot for such a build, and a second card+ // claiming the budget took it and threw the first card's progress+ // away: two cards building at once restarted each other every frame,+ // and only one small enough to finish inside a single slice ever did.+ let continuing = self+ .preview_rebuild_partial+ .borrow()+ .as_ref()+ .map(|partial| partial.tab_id)+ .filter(|&tab_id| previews.iter().any(|preview| preview.tab_id == tab_id));for preview in previews {- if self.paint_terminal_preview(layers, preview, &mut budget)? {+ if self.paint_terminal_preview(layers, preview, &mut budget, continuing)? {rebuilt += 1;}}@@ -2532,6 +2625,21 @@ impl crate::TermWindow {Ok(())}+ /// Whether `tab_id`'s card has a finished picture of what its terminal+ /// shows now: a cached recording with something in it, and no rebuild of+ /// it still under way across frames.+ fn preview_thumbnail_recorded(&self, tab_id: TabId) -> bool {+ self.preview_quad_cache+ .borrow()+ .get(&tab_id)+ .is_some_and(|cached| cached.texture.is_some() || cached.heap.quad_count() > 0)+ && !self+ .preview_rebuild_partial+ .borrow()+ .as_ref()+ .is_some_and(|partial| partial.tab_id == tab_id)+ }+/// The opacity a card's picture should draw at this frame: 1.0 for a/// settled card, ramping 0->1 across [`PREVIEW_CONTENT_FADE`] from the/// moment its terminal first shows visible content. Requests further@@ -2542,7 +2650,7 @@ impl crate::TermWindow {let mut fades = self.preview_content_fade.borrow_mut();let entry = fades.entry(preview.tab_id).or_insert_with(|| {if snapshot_has_content(&preview.snapshot) {- PreviewContentFade::ContentSince(now)+ PreviewContentFade::ContentSince(preview_fade_start(now, preview.prebuild))} else {PreviewContentFade::Blank {snapshot: snapshot_ptr,@@ -2552,7 +2660,8 @@ impl crate::TermWindow {if let PreviewContentFade::Blank { snapshot } = entry {if *snapshot != snapshot_ptr {if snapshot_has_content(&preview.snapshot) {- *entry = PreviewContentFade::ContentSince(now);+ *entry =+ PreviewContentFade::ContentSince(preview_fade_start(now, preview.prebuild));} else {*snapshot = snapshot_ptr;}@@ -2594,6 +2703,7 @@ impl crate::TermWindow {layers: &mut TripleLayerQuadAllocator<'_>,preview: &TerminalPreviewRequest,budget: &mut usize,+ continuing: Option<TabId>,) -> anyhow::Result<bool> {let key = preview_quad_key(preview,@@ -2612,68 +2722,40 @@ impl crate::TermWindow {cached.invalidate_recording_masks(key.recording_revision);}let clip = quad_clip_rect(preview.clip, &self.dimensions);- let content_alpha = self.preview_content_alpha(preview) * preview.opacity.clamp(0.0, 1.0);-- // A hit replays. A miss replays too -- but only when the miss is the- // snapshot alone and the budget is spent, because then the recorded- // quads are merely a refresh out of date, which at thumbnail size is- // not a difference anyone can see. A geometry miss is never replayed:- // those quads are wrong, not old.- let mut deferred = false;- let recorded_area = self+ let shown = !preview.prebuild;+ let has_picture = self+ .preview_quad_cache+ .borrow()+ .contains_key(&preview.tab_id);+ // A hit replays. Otherwise one card builds per frame, and a card part+ // of the way through a sliced build goes first (`continuing`). Every+ // other card shows what it last recorded -- a refresh behind, or+ // stretched to a card that has changed size, as it is while its own+ // build is under way -- and asks for the next frame. Cards that had+ // never been built used to skip the queue: opening onto several of+ // them built them all in one frame.+ let hit = self.preview_quad_cache.borrow().get(&preview.tab_id)- .filter(|cached| {- if cached.key == key {- return true;- }- if cached.key.geometry == key.geometry && *budget == 0 {- deferred = true;- return true;- }- false- })- .map(|cached| cached.area);- if deferred {- // Come straight back rather than naming a time: this card owes a- // rebuild and should get it as soon as a frame has room.- self.update_next_frame_time(Some(Instant::now()));- }- if let Some(recorded_area) = recorded_area {- // Texture path: the card's picture already lives in its own- // texture; a single textured quad replaces the whole replay.- if self.card_texture_path_active()- && self.composite_cached_card(preview, content_alpha)?- {- return Ok(false);+ .is_some_and(|cached| cached.key == key);+ let may_build = *budget > 0 && continuing.map_or(true, |tab_id| tab_id == preview.tab_id);+ if hit || !may_build {+ if !hit {+ // Come straight back rather than naming a time: this card owes+ // a rebuild and should get it as soon as a frame has room.+ self.update_next_frame_time(Some(Instant::now()));}- let cache = self.preview_quad_cache.borrow();- let cached = cache- .get(&preview.tab_id)- .expect("entry was present a statement ago and nothing removes it");- // Scrolling moves a card without changing what it shows. The quads- // carry the position they were recorded at, so a card that has- // moved is replayed through the same source->target mapping the- // flight animation uses. The key carries the card's *size*, so a- // matching key guarantees the two rects are the same shape and the- // mapping degenerates to a translation -- none of the softening- // that a genuinely rescaled replay costs. A card that has not moved- // takes the plain path, which is bit-for-bit what this drew before- // the cache existed.- if recorded_area == preview.area {- cached.heap.apply_to_clipped(layers, clip, content_alpha)?;- } else {- let source = quad_clip_rect(recorded_area, &self.dimensions);- let target = quad_clip_rect(preview.area, &self.dimensions);- cached- .heap- .apply_to_scaled(layers, source, target, clip, content_alpha)?;+ if shown && has_picture {+ let content_alpha =+ self.preview_content_alpha(preview) * preview.opacity.clamp(0.0, 1.0);+ self.paint_cached_card_picture(layers, preview, clip, content_alpha)?;}return Ok(false);}*budget = budget.saturating_sub(1);+ let content_alpha = self.preview_content_alpha(preview) * preview.opacity.clamp(0.0, 1.0);// Continue the sliced rebuild when the slot holds this card and the// key still describes the same picture; anything else in the slot is@@ -2728,21 +2810,8 @@ impl crate::TermWindow {// stretches to the current rect even across a geometry change,// and a card that never had one simply stays background until// the first build lands.- if !(self.card_texture_path_active()- && self.composite_cached_card(preview, content_alpha)?)- {- let cache = self.preview_quad_cache.borrow();- if let Some(cached) = cache.get(&preview.tab_id) {- if cached.area == preview.area {- cached.heap.apply_to_clipped(layers, clip, content_alpha)?;- } else {- let source = quad_clip_rect(cached.area, &self.dimensions);- let target = quad_clip_rect(preview.area, &self.dimensions);- cached- .heap- .apply_to_scaled(layers, source, target, clip, content_alpha)?;- }- }+ if shown {+ self.paint_cached_card_picture(layers, preview, clip, content_alpha)?;}*self.preview_rebuild_partial.borrow_mut() = Some(partial);// The rest of this card's build should get the very next frame.@@ -2796,25 +2865,31 @@ impl crate::TermWindow {quad_count,area: preview.area,});- self.card_composites.borrow_mut().push(CardComposite {- texture: Rc::clone(&tex),- dest: preview.area,- clip: preview.clip,- opacity: content_alpha,- zindex: 0,- });+ if shown {+ self.card_composites.borrow_mut().push(CardComposite {+ texture: Rc::clone(&tex),+ dest: preview.area,+ clip: preview.clip,+ opacity: content_alpha,+ zindex: 0,+ });+ }texture = Some(tex);Ok(true)}Err(err) => {log::warn!("card texture unavailable, replaying quads: {err:#}");- heap.apply_to_clipped(layers, clip, content_alpha)- .map(|()| true)+ if shown {+ heap.apply_to_clipped(layers, clip, content_alpha)?;+ }+ Ok(true)}}} else {- heap.apply_to_clipped(layers, clip, content_alpha)- .map(|()| true)+ if shown {+ heap.apply_to_clipped(layers, clip, content_alpha)?;+ }+ Ok(true)};self.preview_quad_cache.borrow_mut().insert(preview.tab_id,@@ -2917,6 +2992,55 @@ impl crate::TermWindow {Ok(true)}+ /// The terminal flying into its card in the transition under way, if any.+ fn content_view_landing_tab(&self) -> Option<TabId> {+ self.content_view_fade+ .as_ref()+ .and_then(|fade| fade.flight.as_ref())+ .filter(|flight| flight.lands_in_card)+ .and_then(|flight| flight.tab_id)+ }++ /// Draw the picture a card last recorded, wherever the card is now: its+ /// texture stretched over the card's rectangle, or without one its quads+ /// remapped onto it -- a card that has only moved, as when the overview+ /// scrolls, takes the same mapping the flight uses and it degenerates to a+ /// translation. Quads carry positions relative to the centre of the window+ /// they were recorded in, so once the window itself has changed size they+ /// would land in the wrong place and are left out.+ fn paint_cached_card_picture(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ preview: &TerminalPreviewRequest,+ clip: QuadClipRect,+ content_alpha: f32,+ ) -> anyhow::Result<()> {+ if self.card_texture_path_active() && self.composite_cached_card(preview, content_alpha)? {+ return Ok(());+ }+ let cache = self.preview_quad_cache.borrow();+ let Some(cached) = cache.get(&preview.tab_id) else {+ return Ok(());+ };+ let geometry = cached.key.geometry;+ if geometry.pixel_width != self.dimensions.pixel_width+ || geometry.pixel_height != self.dimensions.pixel_height+ || geometry.dpi != self.dimensions.dpi+ {+ return Ok(());+ }+ if cached.area == preview.area {+ cached.heap.apply_to_clipped(layers, clip, content_alpha)?;+ } else {+ let source = quad_clip_rect(cached.area, &self.dimensions);+ let target = quad_clip_rect(preview.area, &self.dimensions);+ cached+ .heap+ .apply_to_scaled(layers, source, target, clip, content_alpha)?;+ }+ Ok(())+ }+/// Build one card's thumbnail into `layers`, whole.////// Everything here is laid out against `preview.area` -- the card's full@@ -5309,6 +5433,7 @@ mod tests {clip: area,hold_scale: false,opacity: 1.0,+ prebuild: false,}}@@ -5631,3 +5756,21 @@ mod atlas_policy_tests {assert_eq!(kept, None);}}++#[cfg(test)]+mod overview_landing_tests {+ use super::{preview_fade_start, PREVIEW_CONTENT_FADE};+ use std::time::Instant;++ #[test]+ fn a_card_seen_on_screen_fades_in_from_now() {+ let now = Instant::now();+ assert_eq!(preview_fade_start(now, false), now);+ }++ #[test]+ fn a_card_built_out_of_sight_is_settled_when_shown() {+ let now = Instant::now() + PREVIEW_CONTENT_FADE;+ assert_eq!(preview_fade_start(now, true), now - PREVIEW_CONTENT_FADE);+ }+}diff --git a/wezterm-gui/src/ui/anim.rs b/wezterm-gui/src/ui/anim.rsindex f064ca56..ff217205 100644--- a/wezterm-gui/src/ui/anim.rs+++ b/wezterm-gui/src/ui/anim.rs@@ -142,6 +142,13 @@ impl Timeline {Self::new(now, value, value, Duration::ZERO, Easing::Linear)}+ /// When the value reaches its target, or reached it: `None` while the+ /// clock has not started.+ pub(crate) fn arrives_at(&self) -> Option<Instant> {+ self.started_at+ .map(|started_at| started_at + self.delay + self.duration)+ }+/// Advance to `now`; returns whether another frame is still wanted.////// Call this once per frame, before painting. The first call does not@@ -298,6 +305,18 @@ mod tests {assert_eq!(timeline.value(at(start, 500)), 12.0);}+ #[test]+ fn arrival_is_known_once_the_clock_runs() {+ let start = Instant::now();+ let mut timeline = armed(start);+ timeline.advance(at(start, 0));+ timeline.value(at(start, 0));+ assert_eq!(timeline.arrives_at(), None);+ // The clock starts on the frame after the first presented one.+ timeline.advance(at(start, 100));+ assert_eq!(timeline.arrives_at(), Some(at(start, 300)));+ }+#[test]fn finishing_early_lands_on_the_target() {let start = Instant::now();