From 7782c47b38ddbbd290fbc8b9d7f44daad44f6ea0 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Tue, 17 Nov 2026 01:24:47 -0800 Subject: [PATCH] Animate tab and pane transitions with Neovide window easing --- README.md | 4 + THIRD_PARTY_NOTICES.md | 8 ++ src/main.rs | 1 + src/terminal.rs | 184 ++++++++++++++++++++++++++++++++++------- src/transition.rs | 81 ++++++++++++++++++ 5 files changed, 250 insertions(+), 28 deletions(-) create mode 100644 src/transition.rs diff --git a/README.md b/README.md index 54cfe29..9c47995 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,10 @@ Huayra, Attractor, and Sybil. Tabs retain violet accents; pane headers use teal, with a matching border around the active pane. The titlebar contains equal-width tabs and connection/window controls. `src/chrome.rs` records the theme sources. +Tab changes and new panes slide with Neovide's 150 ms exponential window-motion +curve. Outgoing content remains visible during the transition; only the incoming +view accepts input and controls the terminal size. + Cursor motion adapts Neovide's four independently sprung corners: leading corners move first and trailing corners stretch behind. The blink follows buzzlocker: 500 ms solid after input, 500 ms cubic fade-out, then an immediate diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 2b4c14f..e072571 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -27,3 +27,11 @@ reused at the author's explicit request: It holds at full opacity for 500 ms after input, fades out with a 500 ms cubic ease-out curve, then returns to full opacity for 500 ms. It does not fade in. + +## Neovide view transitions + +`src/transition.rs` adapts Neovide's `ease_out_expo` window-position curve +from `src/renderer/animation_utils.rs`, used by `rendered_window.rs` with +`position_animation_length = 0.15` in `renderer/mod.rs`. This is the same +Neovide revision and MIT license recorded above. Horizontal tab and pane +transitions use this curve; text scrolling has a separate spring in Neovide. diff --git a/src/main.rs b/src/main.rs index 13808d9..3f24b50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ mod render; mod server; mod session; mod terminal; +mod transition; use anyhow::{Result, bail}; use gpui::{prelude::*, *}; diff --git a/src/terminal.rs b/src/terminal.rs index ec635e3..15c2b4d 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -12,6 +12,7 @@ use crate::{ Snapshot, }, render::{FONT_SIZE, LINE_HEIGHT, RenderCell, Renderer}, + transition::Slide, }; use alacritty_terminal::{ term::{TermMode, color::Colors}, @@ -32,6 +33,9 @@ pub struct Workspace { snapshot: Option>, panes: HashMap>, error: Option, + outgoing: Vec>, + transition: Option, + transition_frame_pending: bool, _updates: Task<()>, } impl Workspace { @@ -54,6 +58,33 @@ impl Workspace { view.error = Some(error); } if let Some(snapshot) = update.snapshot { + if let Some(direction) = view + .snapshot + .as_ref() + .and_then(|old| scene_direction(old, &snapshot)) + { + view.outgoing = view + .snapshot + .as_ref() + .unwrap() + .panes + .iter() + .filter_map(|data| view.panes.get(&data.id).cloned()) + .collect(); + for pane in &view.outgoing { + pane.update(cx, |pane, cx| { + pane.read_only = true; + pane.transitioning = true; + pane.rename = None; + pane.selecting = false; + pane.preedit.clear(); + pane.blink_timer = None; + cx.notify(); + }); + } + view.panes.clear(); + view.transition = Some(Slide::new(direction, Instant::now())); + } let active = snapshot .tabs .iter() @@ -87,14 +118,16 @@ impl Workspace { let client = view.client.clone(); let frame = snapshot.clone(); let pane = cx.new(|cx| { - TerminalPane::new( + let mut pane = TerminalPane::new( client, frame, index, active == Some(data.id), window, cx, - ) + ); + pane.transitioning = view.transition.is_some(); + pane }); view.panes.insert(data.id, pane); } @@ -124,12 +157,37 @@ impl Workspace { snapshot: None, panes: HashMap::new(), error: None, + outgoing: Vec::new(), + transition: None, + transition_frame_pending: false, _updates: task, } } } impl Render for Workspace { - fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { + let now = Instant::now(); + if self + .transition + .as_ref() + .is_some_and(|transition| transition.finished(now)) + { + self.transition = None; + self.outgoing.clear(); + for pane in self.panes.values() { + pane.update(cx, |pane, cx| { + pane.transitioning = false; + cx.notify(); + }); + } + } + if self.transition.is_some() && !self.transition_frame_pending { + self.transition_frame_pending = true; + cx.on_next_frame(window, |view, _, cx| { + view.transition_frame_pending = false; + cx.notify(); + }); + } let tabs = self .snapshot .as_ref() @@ -157,21 +215,29 @@ impl Render for Workspace { }, move |window, _| window.remove_window(), ); + let (incoming_offset, outgoing_offset) = self + .transition + .as_ref() + .map(|transition| transition.offsets(now)) + .unwrap_or(([0., 0.], [0., 0.])); let mut body = div() - .flex() + .relative() .flex_1() .min_h_0() - .gap(px(6.)) - .p(px(chrome::CONTENT_INSET)) + .overflow_hidden() .bg(rgb(chrome::APP_BACKGROUND)); + if !self.outgoing.is_empty() { + body = body.child(scene(outgoing_offset).children(self.outgoing.iter().cloned())); + } + let mut incoming = scene(incoming_offset); if let Some(snapshot) = &self.snapshot { for data in &snapshot.panes { if let Some(pane) = self.panes.get(&data.id) { - body = body.child(pane.clone()); + incoming = incoming.child(pane.clone()); } } if snapshot.panes.is_empty() { - body = body.child( + incoming = incoming.child( div() .p_4() .text_color(rgb(chrome::MUTED)) @@ -179,13 +245,14 @@ impl Render for Workspace { ); } } else { - body = body.child( + incoming = incoming.child( div() .p_4() .text_color(rgb(chrome::MUTED)) .child("Connecting…"), ); } + body = body.child(incoming); let mut root = div() .size_full() .flex() @@ -208,11 +275,50 @@ impl Render for Workspace { } } +/// Absolute positioning translates the scene without changing its layout size. +fn scene(offset: [f32; 2]) -> Div { + div() + .absolute() + .left(relative(offset[0])) + .top(relative(offset[1])) + .size_full() + .flex() + .gap(px(6.)) + .p(px(chrome::CONTENT_INSET)) + .bg(rgb(chrome::APP_BACKGROUND)) +} + +fn scene_direction(old: &Snapshot, next: &Snapshot) -> Option<[f32; 2]> { + if old.panes.is_empty() || next.panes.is_empty() { + return None; + } + if old.active_tab != next.active_tab { + let previous = old + .tabs + .iter() + .position(|tab| tab.id == old.active_tab) + .unwrap_or(0); + let next_index = next + .tabs + .iter() + .position(|tab| tab.id == next.active_tab) + .unwrap_or(0); + return Some([if next_index > previous { 1. } else { -1. }, 0.]); + } + next.panes + .iter() + .any(|pane| !old.panes.iter().any(|old| old.id == pane.id)) + .then_some([1., 0.]) +} + struct TerminalPane { client: Client, snapshot: Arc, index: usize, active: bool, + // Frozen outgoing scenes are display-only; no PTY resize, focus or input. + read_only: bool, + transitioning: bool, focus: FocusHandle, font: Font, bounds: Bounds, @@ -260,6 +366,8 @@ impl TerminalPane { snapshot, index, active, + read_only: false, + transitioning: false, focus, font, bounds: Bounds::default(), @@ -282,6 +390,9 @@ impl TerminalPane { &self.snapshot.panes[self.index] } fn command(&self, command: ClientMessage) { + if self.read_only { + return; + } if let Err(error) = self.client.send(command) { log::warn!("{error:#}"); } @@ -295,7 +406,7 @@ impl TerminalPane { cx.notify(); } fn send(&mut self, bytes: Vec, cx: &mut Context) { - if bytes.is_empty() { + if self.read_only || bytes.is_empty() { return; } self.preedit.clear(); @@ -356,6 +467,9 @@ impl TerminalPane { MouseButton::Left, cx.listener(|pane, _, window, cx| { cx.stop_propagation(); + if pane.read_only { + return; + } if pane.rename.is_none() { window.focus(&pane.focus); } @@ -387,7 +501,7 @@ impl TerminalPane { } fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - if self.rename.is_some() { + if self.read_only || self.rename.is_some() { return; } let key = &event.keystroke; @@ -497,6 +611,9 @@ impl TerminalPane { ) } fn mouse_down(&mut self, event: &MouseDownEvent, window: &mut Window, cx: &mut Context) { + if self.read_only { + return; + } window.focus(&self.focus); self.activity(cx); let pane = self.data().id; @@ -528,6 +645,9 @@ impl TerminalPane { } } fn scroll(&mut self, event: &ScrollWheelEvent, _: &mut Window, cx: &mut Context) { + if self.read_only { + return; + } self.scroll_remainder += match event.delta { ScrollDelta::Lines(d) => d.y * 3., ScrollDelta::Pixels(d) => f32::from(d.y) / LINE_HEIGHT, @@ -562,7 +682,7 @@ impl TerminalPane { let lines = ((f32::from(bounds.size.height) - 2. * PADDING) / LINE_HEIGHT) .floor() .clamp(1., 500.) as u16; - if self.requested_size != Some((columns, lines)) { + if !self.read_only && self.requested_size != Some((columns, lines)) { self.requested_size = Some((columns, lines)); self.command(ClientMessage::Resize { pane: self.data().id, @@ -572,7 +692,9 @@ impl TerminalPane { cell_height: LINE_HEIGHT as u16, }); } - if self.prepared_revision == Some(self.snapshot.revision) && self.bounds == bounds { + let prepare_rows = self.prepared_revision != Some(self.snapshot.revision) + || self.bounds.size != bounds.size; + if !prepare_rows && self.bounds.origin == bounds.origin { return; } let started = Instant::now(); @@ -604,6 +726,23 @@ impl TerminalPane { px(LINE_HEIGHT), ), ); + let mut cursor_color = colors::resolve(Color::Named(NamedColor::Cursor), &palette); + cursor_color.a = 0.55; + self.cursor_bounds = cursor_bounds; + self.cursor.set_target( + cursor_bounds, + if hidden { + CursorShape::Hidden + } else { + cursor.shape.into() + }, + cursor_color, + Instant::now(), + ); + if !prepare_rows { + return; + } + let data = self.data(); let rows = data .cells .chunks(usize::from(data.columns)) @@ -628,19 +767,6 @@ impl TerminalPane { .collect() }) .collect(); - let mut cursor_color = colors::resolve(Color::Named(NamedColor::Cursor), &palette); - cursor_color.a = 0.55; - self.cursor_bounds = cursor_bounds; - self.cursor.set_target( - cursor_bounds, - if hidden { - CursorShape::Hidden - } else { - cursor.shape.into() - }, - cursor_color, - Instant::now(), - ); self.renderer .prepare(rows, &self.font, self.cell_width, window); self.prepared_revision = Some(self.snapshot.revision); @@ -691,7 +817,7 @@ impl Render for TerminalPane { move |bounds,(),window,cx| { paint.update(cx,|pane,cx| { let started=Instant::now(); - if pane.rename.is_none() { + if !pane.read_only && pane.rename.is_none() { window.handle_input(&pane.focus,ElementInputHandler::new(bounds,paint.clone()),cx); } let mut delay=None; @@ -699,7 +825,9 @@ impl Render for TerminalPane { let origin=bounds.origin+point(px(PADDING),px(PADDING)); let focused=window.is_window_active() && pane.active && pane.rename.is_none(); pane.renderer.paint_with_cursor(origin,window,cx,|window| { - delay=pane.cursor.paint(Instant::now(),focused,window); + if !pane.transitioning { + delay=pane.cursor.paint(Instant::now(),focused,window); + } }); if !pane.preedit.is_empty() { let run=TextRun{len:pane.preedit.len(),font:pane.font.clone(),color:rgb(chrome::TEXT).into(),background_color:Some(rgb(chrome::TERMINAL_BACKGROUND).into()), diff --git a/src/transition.rs b/src/transition.rs new file mode 100644 index 0000000..e89e71b --- /dev/null +++ b/src/transition.rs @@ -0,0 +1,81 @@ +//! Neovide's window-position easing, shared by horizontal and vertical views. +//! +//! Adapted from Neovide's renderer/animation_utils.rs (MIT). Its rendered_window +//! uses this curve with a default position_animation_length of 150 ms. +use std::time::{Duration, Instant}; + +pub const DURATION: Duration = Duration::from_millis(150); + +/// Neovide's exact exponential ease-out, including its exact final endpoint. +pub fn ease_out_expo(t: f32) -> f32 { + if (t - 1.0).abs() < f32::EPSILON { + 1.0 + } else { + 1.0 - 2.0f32.powf(-10.0 * t) + } +} + +/// Direction is a unit vector: [1, 0] enters from the right; [0, -1] from above. +pub struct Slide { + started: Instant, + direction: [f32; 2], +} + +impl Slide { + pub fn new(direction: [f32; 2], now: Instant) -> Self { + Self { + started: now, + direction, + } + } + + pub fn finished(&self, now: Instant) -> bool { + now.saturating_duration_since(self.started) >= DURATION + } + + /// Incoming and outgoing offsets expressed as fractions of the viewport. + pub fn offsets(&self, now: Instant) -> ([f32; 2], [f32; 2]) { + let t = (now.saturating_duration_since(self.started).as_secs_f32() + / DURATION.as_secs_f32()) + .clamp(0., 1.); + let progress = ease_out_expo(t); + ( + self.direction.map(|axis| axis * (1. - progress)), + self.direction.map(|axis| -axis * progress), + ) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn neovide_curve_is_monotonic_and_finishes_exactly() { + assert_eq!(ease_out_expo(0.), 0.); + assert_eq!(ease_out_expo(0.5), 0.96875); + assert_eq!(ease_out_expo(1.), 1.); + for step in 1..=100 { + assert!(ease_out_expo(step as f32 / 100.) >= ease_out_expo((step - 1) as f32 / 100.)); + } + } + + #[test] + fn horizontal_and_vertical_scenes_share_a_boundary_and_stop() { + let now = Instant::now(); + for direction in [[1., 0.], [-1., 0.], [0., 1.], [0., -1.]] { + let slide = Slide::new(direction, now); + assert_eq!(slide.offsets(now), (direction, [0., 0.])); + let (incoming, outgoing) = slide.offsets(now + DURATION / 2); + for axis in 0..2 { + assert_eq!(incoming[axis] - outgoing[axis], direction[axis]); + } + assert_eq!(slide.offsets(now + DURATION).0, [0., 0.]); + assert!(slide.finished(now + DURATION)); + assert_eq!( + slide.offsets(now + DURATION * 2), + slide.offsets(now + DURATION) + ); + } + } +}