A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(gui): slide a new split in from its edge
RoversX6e3174526d01
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftlindex 48a0e381..3dbdf7eb 100644--- a/thinkterm-i18n/i18n/de-DE.ftl+++ b/thinkterm-i18n/i18n/de-DE.ftl@@ -219,6 +219,8 @@ settings-text-contrast-45 = 4.5:1settings-text-contrast-7 = 7:1settings-overlay-scrollbar = Bildlaufleistesettings-overlay-scrollbar-description = Beim Scrollen erscheint am rechten Rand des Fensterbereichs eine schmale Bildlaufleiste, die danach ausblendet; sie lässt sich ziehen.+settings-split-animation = Teilungsanimation+settings-split-animation-description = Ein neu geteilter Bereich gleitet vom Rand herein.settings-bottom-quote = Zitat am unteren Randsettings-bottom-quote-description = Zeigt ein kurzes Zitat am unteren Rand des Terminalfensters.settings-quote-font-size = Schriftgröße des Zitatsdiff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftlindex fc636d0f..1b8fc6a8 100644--- a/thinkterm-i18n/i18n/en-US.ftl+++ b/thinkterm-i18n/i18n/en-US.ftl@@ -219,6 +219,8 @@ settings-text-contrast-45 = 4.5:1settings-text-contrast-7 = 7:1settings-overlay-scrollbar = Scrollbarsettings-overlay-scrollbar-description = A thin scrollbar appears over the right edge of a pane while it scrolls and fades out afterwards; it can be dragged.+settings-split-animation = Split animation+settings-split-animation-description = A new split slides in from the edge.settings-bottom-quote = Bottom Quotesettings-bottom-quote-description = Show a short quote at the bottom of the terminal window.settings-quote-font-size = Quote Font Sizediff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftlindex f2812849..df829d58 100644--- a/thinkterm-i18n/i18n/fr-FR.ftl+++ b/thinkterm-i18n/i18n/fr-FR.ftl@@ -219,6 +219,8 @@ settings-text-contrast-45 = 4.5:1settings-text-contrast-7 = 7:1settings-overlay-scrollbar = Barre de défilementsettings-overlay-scrollbar-description = Une fine barre de défilement apparaît sur le bord droit du volet pendant le défilement puis disparaît en fondu ; elle peut être glissée.+settings-split-animation = Animation de division+settings-split-animation-description = Un nouveau volet glisse depuis le bord.settings-bottom-quote = Citation inférieuresettings-bottom-quote-description = Affiche une courte citation en bas de la fenêtre du terminal.settings-quote-font-size = Taille de la citationdiff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftlindex 2eee8b74..8b5b1cfc 100644--- a/thinkterm-i18n/i18n/ja-JP.ftl+++ b/thinkterm-i18n/i18n/ja-JP.ftl@@ -216,6 +216,8 @@ settings-text-contrast-45 = 4.5:1settings-text-contrast-7 = 7:1settings-overlay-scrollbar = スクロールバーsettings-overlay-scrollbar-description = スクロール中はペインの右端に細いスクロールバーが表示され、その後フェードアウトします。ドラッグもできます。+settings-split-animation = 分割アニメーション+settings-split-animation-description = 新しく分割したペインが端からスライドして入ります。settings-bottom-quote = 下部の引用文settings-bottom-quote-description = ターミナルウィンドウの下部に短い引用文を表示します。settings-quote-font-size = 引用文のフォントサイズdiff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftlindex 1c99fc05..45c2d5a0 100644--- a/thinkterm-i18n/i18n/zh-CN.ftl+++ b/thinkterm-i18n/i18n/zh-CN.ftl@@ -216,6 +216,8 @@ settings-text-contrast-45 = 4.5:1settings-text-contrast-7 = 7:1settings-overlay-scrollbar = 滚动条settings-overlay-scrollbar-description = 滚动时在面板右侧显示一条细滚动条,停止后自动淡出;可以拖动。+settings-split-animation = 分屏动画+settings-split-animation-description = 新开分屏时从边上滑进来。settings-bottom-quote = 底部语录settings-bottom-quote-description = 在终端窗口底部显示一条简短语录。settings-quote-font-size = 语录字号diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rsindex 110bb35a..3c0be6c4 100644--- a/wezterm-gui/src/native_settings.rs+++ b/wezterm-gui/src/native_settings.rs@@ -590,6 +590,9 @@ pub(crate) struct NativeTerminalSettings {/// a separate, older thing and wins when it is on.#[serde(default = "default_true")]pub(crate) overlay_scrollbar: bool,+ /// A pane opened by a split slides in from the side it opened on.+ #[serde(default = "default_true")]+ pub(crate) split_animation: bool,pub(crate) font_size: Option<f64>,pub(crate) font_family: Option<String>,pub(crate) remote_pane_resize_mode: NativeRemotePaneResizeMode,@@ -621,6 +624,7 @@ impl Default for NativeTerminalSettings {fn default() -> Self {Self {overlay_scrollbar: true,+ split_animation: true,font_size: None,font_family: None,remote_pane_resize_mode: NativeRemotePaneResizeMode::default(),@@ -649,6 +653,11 @@ pub(crate) fn scroll_mode() -> NativeScrollMode {load_shared().terminal.scroll_mode}+/// Read every frame, through the shared handle.+pub(crate) fn split_animation() -> bool {+ load_shared().terminal.split_animation+}+/// Read whenever a selection is let go of, through the shared handle.pub(crate) fn copy_on_select() -> bool {load_shared().terminal.copy_on_selectdiff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex 210e17b5..602cd1fa 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -1140,6 +1140,8 @@ impl SettingsSection {"Copy","Copy Effect","Selection",+ "Split Animation",+ "Animation","Terminal",],Self::Workspaces => &[@@ -1312,6 +1314,7 @@ impl SettingsSection {"settings-right-click","settings-right-click-paste","settings-copy-effect",+ "settings-split-animation",].iter().any(|id| crate::i18n::tr(id).to_lowercase().contains(query)))@@ -1831,6 +1834,7 @@ enum SettingsAction {OpenColorSchemePicker,SetTextContrast(crate::native_settings::NativeTextContrast),ToggleOverlayScrollbar,+ ToggleSplitAnimation,SetBottomQuoteMode(NativeBottomQuoteMode),DecreaseBottomQuoteFontSize,IncreaseBottomQuoteFontSize,@@ -6176,6 +6180,19 @@ impl SettingsWindow {}}SettingsAction::SetScrollMode(mode) => self.apply_scroll_mode(mode),+ SettingsAction::ToggleSplitAnimation => {+ let on = !self.native_settings.terminal.split_animation;+ let done = settings_tr(+ "settings-status-value-now",+ &[+ ("setting", crate::i18n::tr("settings-split-animation")),+ ("value", crate::i18n::tr(if on { "common-on" } else { "common-off" })),+ ],+ );+ self.apply_terminal_change("settings-split-animation", done, |terminal| {+ terminal.split_animation = on+ })+ }SettingsAction::ToggleCopyOnSelect => {let on = !self.native_settings.terminal.copy_on_select;let done = crate::i18n::tr(if on {@@ -12698,6 +12715,26 @@ impl SettingsWindow {rows.rule(),)?);+ let (tx, tw) = this.paint_row_tile(+ layers,+ row_x,+ rows.y,+ row_width,+ SvgIcon::SplitHorizontal,+ TileColor::Indigo,+ )?;+ rows.add(this.paint_toggle_setting_row(+ layers,+ tx,+ rows.y,+ tw,+ &crate::i18n::tr("settings-split-animation"),+ &crate::i18n::tr("settings-split-animation-description"),+ this.native_settings.terminal.split_animation,+ SettingsAction::ToggleSplitAnimation,+ rows.rule(),+ )?);+let options: Vec<(String, SettingsAction)> = NativeTextContrast::ALL.iter().map(|mode| {diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 05113143..35a4de49 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -3054,6 +3054,8 @@ pub struct TermWindow {/// show up for one (see `render::edge_light`).edge_lights: Vec<render::edge_light::EdgeLight>,pending_paste: Option<render::edge_light::PendingPaste>,+ /// A pane just opened by a split, sliding in (see `render::split_slide`).+ split_slides: render::split_slide::SplitSlides,/// A mouse binding took the right button's press: its release does not/// run the built-in right click as well.right_press_claimed: bool,@@ -4810,6 +4812,7 @@ impl TermWindow {update_capsule: Default::default(),edge_lights: vec![],pending_paste: None,+ split_slides: Default::default(),right_press_claimed: false,recording_overlay: Default::default(),command_palette: None,diff --git a/wezterm-gui/src/termwindow/render/mod.rs b/wezterm-gui/src/termwindow/render/mod.rsindex cdd841ea..d54403a0 100644--- a/wezterm-gui/src/termwindow/render/mod.rs+++ b/wezterm-gui/src/termwindow/render/mod.rs@@ -52,6 +52,7 @@ pub mod pane;pub mod screen_line;pub mod selection_shape;pub mod split;+pub mod split_slide;pub mod tab_bar;pub mod update_capsule;pub mod window_buttons;diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex a823ca52..e0d390b7 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -11,6 +11,7 @@ use ::window::RectF;use ::window::WindowOps;use anyhow::Context;use mux::renderable::{RenderableDimensions, StableCursorPosition};+use crate::termwindow::render::split_slide::{self, SplitSlide, TabLayout};use mux::tab::{PositionedPane, SplitDirection, TabId};use smol::Timer;use std::collections::hash_map::DefaultHasher;@@ -1629,6 +1630,35 @@ impl crate::TermWindow {/// The terminal's ground across the window, as see-through as the window/// is: the dark interface's, a lone pane's own, or the palette's.+ /// See `render::split_slide`. Taken every frame, painted or not, so a+ /// pane that arrives behind a content view does not slide in later,+ /// when the view goes.+ fn advance_split_slide(+ &mut self,+ panes: &[PositionedPane],+ now: Instant,+ ) -> Option<(SplitSlide, f32)> {+ let layout = mux::Mux::get()+ .get_active_tab_for_window(self.mux_window_id)+ .map(|tab| TabLayout::of(tab.tab_id(), panes));+ let slide =+ self.split_slides+ .advance(layout, crate::native_settings::split_animation(), now);+ if slide.is_some() {+ if let Some(window) = self.window.as_ref() {+ window.invalidate();+ }+ }+ slide+ }++ /// Where a pane sliding in ends up: its ground and its nav bar, which+ /// is lifted above the ground along the top. The divider it comes with+ /// runs down the leading edge of its ground.+ fn split_slide_place(&self, pos: &PositionedPane) -> anyhow::Result<RectF> {+ Ok(self.pane_background_rect(pos).union(&self.pane_frame_rect(pos)?))+ }+fn window_terminal_ground(&mut self, panes: &[PositionedPane]) -> LinearRgba {let ground = if let Some(ground) = self.dark_terminal_ground() {ground@@ -4053,6 +4083,7 @@ impl crate::TermWindow {self.reconcile_active_mux_tab_size_before_paint();self.sync_pane_font_sizes();let panes = self.get_panes_to_render();+ let split_slide = self.advance_split_slide(&panes, frame_now);let focused = self.focused.is_some();let window_is_transparent =!self.window_background.is_empty() || self.config.window_background_opacity != 1.0;@@ -4202,6 +4233,14 @@ impl crate::TermWindow {let mut takeover_badge = false;if paint_terminal_world && !frontend_blocked {+ // Where the pane sliding in has to go, if one is.+ let mut sliding = None;+ let made_room = split_slide.and_then(|(slide, _)| {+ panes+ .iter()+ .find(|pos| pos.pane.pane_id() == slide.from_pane)+ .cloned()+ });for pos in panes {if pos.is_active {if focused {@@ -4209,9 +4248,45 @@ impl crate::TermWindow {mux::Mux::get().record_focus_for_current_identity(pos.pane.pane_id());}}- self.paint_pane(&pos, &mut layers).context("paint_pane")?;- if let Ok(frame) = self.pane_mask_frame(&pos) {- self.paint_pane_recording_masks(&pos, frame, &mut layers)?;+ match split_slide.filter(|(slide, _)| slide.pane_id == pos.pane.pane_id()) {+ Some((slide, remaining)) => {+ let place = self.split_slide_place(&pos)?;+ let shift = slide.offset(remaining, place.width(), place.height());+ // Until it gets there, its room still looks like+ // the pane that gave it up: the window's own ground+ // is lighter than a pane dimmed for not being active.+ if let Some(made_room) = made_room.as_ref() {+ self.paint_ground_of(+ &mut layers,+ made_room,+ split_slide::wake(place, shift),+ )+ .context("split slide ground")?;+ }+ let mut recorded = HeapQuadAllocator::default();+ {+ let mut pane_layers = TripleLayerQuadAllocator::Heap(&mut recorded);+ self.paint_pane(&pos, &mut pane_layers)+ .context("paint_pane")?;+ if let Ok(frame) = self.pane_mask_frame(&pos) {+ self.paint_pane_recording_masks(&pos, frame, &mut pane_layers)?;+ }+ }+ recorded.apply_to_clipped_at(+ &mut layers,+ shift.0,+ shift.1,+ self.clip_of(place),+ 1.0,+ )?;+ sliding = Some((slide, pos, place, shift));+ }+ None => {+ self.paint_pane(&pos, &mut layers).context("paint_pane")?;+ if let Ok(frame) = self.pane_mask_frame(&pos) {+ self.paint_pane_recording_masks(&pos, frame, &mut layers)?;+ }+ }}}@@ -4223,8 +4298,28 @@ impl crate::TermWindow {if let Some(pane) = self.get_active_pane_or_overlay() {let splits = self.get_splits();for split in &splits {- self.paint_split(&mut layers, split, &pane)- .context("paint_split")?;+ match sliding.as_ref().filter(|(slide, pos, ..)| slide.leads(pos, split)) {+ // The divider the split put in comes in with the pane.+ Some((_, _, place, shift)) => {+ let mut recorded = HeapQuadAllocator::default();+ self.paint_split(+ &mut TripleLayerQuadAllocator::Heap(&mut recorded),+ split,+ &pane,+ )+ .context("paint_split")?;+ recorded.apply_to_clipped_at(+ &mut layers,+ shift.0,+ shift.1,+ self.clip_of(*place),+ 1.0,+ )?;+ }+ None => self+ .paint_split(&mut layers, split, &pane)+ .context("paint_split")?,+ }}}self.paint_frontend_shared_unused_grid(&mut layers)diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rsindex 5468ef57..4029a029 100644--- a/wezterm-gui/src/termwindow/render/pane.rs+++ b/wezterm-gui/src/termwindow/render/pane.rs@@ -417,6 +417,36 @@ impl crate::TermWindow {Ok(rects)}+ /// Fill `rect` the way `pos` fills its own ground, dimmed with it when+ /// it is not the active pane, so the area reads as part of that pane.+ /// With a background image the panes leave their ground unfilled, and+ /// so does this.+ pub(crate) fn paint_ground_of(+ &self,+ layers: &mut TripleLayerQuadAllocator,+ pos: &PositionedPane,+ rect: RectF,+ ) -> anyhow::Result<()> {+ if !self.window_background.is_empty() || rect.is_empty() {+ return Ok(());+ }+ let palette = pos.pane.palette();+ let mut quad = self.filled_rectangle(+ layers,+ 0,+ rect,+ self.dark_terminal_ground()+ .unwrap_or_else(|| palette.background.to_linear())+ .mul_alpha(self.config.window_background_opacity),+ )?;+ quad.set_hsv(if pos.is_active {+ None+ } else {+ Some(self.config.inactive_pane_hsb_for_background(palette.background))+ });+ Ok(())+ }+/// The pane's rectangle without that lift. Recording masks are kept as/// fractions of it, so it has to move with the pane's rows when a/// terminal bar comes or goes, as the whole frame did before the lift.diff --git a/wezterm-gui/src/termwindow/render/split_slide.rs b/wezterm-gui/src/termwindow/render/split_slide.rsnew file mode 100644index 00000000..f85a09ef--- /dev/null+++ b/wezterm-gui/src/termwindow/render/split_slide.rs@@ -0,0 +1,453 @@+//! A pane opened by a split slides in from the side it was opened on.+//!+//! Only the picture moves. By the time the new pane is first painted the+//! split has already given every pane its final size, once, so the programs+//! in them see a single resize rather than one a frame. The new pane is+//! painted where it ends up, recorded, and replayed shifted out towards the+//! edge it comes from, cropped to its own place, the divider beside it going+//! along.+//!+//! Nothing says a pane came by a split, wherever the split was asked for+//! (a key, the menu, the CLI, another client). It is read off the layout:+//! one pane more than last frame, in the same tab, with nobody gone, next+//! to a pane that used to cover the ground it now stands on.++use ::window::RectF;+use mux::pane::PaneId;+use mux::tab::{PositionedPane, PositionedSplit, SplitDirection, TabId};+use std::time::{Duration, Instant};++const DURATION: Duration = Duration::from_millis(180);+/// A slide is shown in no fewer frames than this. Where a frame takes+/// longer than its share of `DURATION` -- a busy window, a build without+/// 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;+/// 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);++/// The edge of its place a new pane comes in from.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum Edge {+ Left,+ Right,+ Top,+ Bottom,+}++#[derive(Clone, Copy, Debug, PartialEq, Eq)]+struct CellRect {+ left: usize,+ top: usize,+ width: usize,+ height: usize,+}++impl CellRect {+ fn of(pos: &PositionedPane) -> Self {+ Self {+ left: pos.left,+ top: pos.top,+ width: pos.width,+ height: pos.height,+ }+ }++ fn right(&self) -> usize {+ self.left + self.width+ }++ fn bottom(&self) -> usize {+ self.top + self.height+ }++ fn overlaps(&self, other: &Self) -> bool {+ self.left < other.right()+ && other.left < self.right()+ && self.top < other.bottom()+ && other.top < self.bottom()+ }++ fn rows_overlap(&self, other: &Self) -> bool {+ self.top < other.bottom() && other.top < self.bottom()+ }++ fn cols_overlap(&self, other: &Self) -> bool {+ self.left < other.right() && other.left < self.right()+ }+}++/// The panes a tab showed in one frame.+#[derive(Debug, PartialEq, Eq)]+pub struct TabLayout {+ tab_id: TabId,+ zoomed: bool,+ panes: Vec<(PaneId, CellRect)>,+}++impl TabLayout {+ pub fn of(tab_id: TabId, panes: &[PositionedPane]) -> Self {+ Self {+ tab_id,+ zoomed: panes.iter().any(|pos| pos.is_zoomed),+ panes: panes+ .iter()+ .map(|pos| (pos.pane.pane_id(), CellRect::of(pos)))+ .collect(),+ }+ }++ fn rect(&self, pane_id: PaneId) -> Option<CellRect> {+ self.panes+ .iter()+ .find(|(id, _)| *id == pane_id)+ .map(|(_, rect)| *rect)+ }++ /// The pane `self` gained over `before` by a split, the edge it comes+ /// in from and a pane that made room for it. Anything else that adds a pane -- a tab switched to,+ /// a zoom let go of, an overlay closed -- also changes or removes one+ /// that was there, or leaves no neighbour that gave up the room.+ fn opened_by_split(&self, before: &Self) -> Option<(PaneId, Edge, PaneId)> {+ if self.tab_id != before.tab_id+ || self.zoomed+ || before.zoomed+ || before.panes.is_empty()+ || self.panes.len() != before.panes.len() + 1+ {+ return None;+ }+ let mut new = None;+ for (id, rect) in &self.panes {+ if before.rect(*id).is_none() {+ if new.is_some() {+ return None;+ }+ new = Some((*id, *rect));+ }+ }+ let (new_id, new) = new?;+ self.panes.iter().find_map(|(id, now)| {+ let was = before.rect(*id)?;+ // It stood where the new pane is now, and gave that up.+ if was == *now || !was.overlaps(&new) {+ return None;+ }+ let edge = if new.left == now.right() + 1 && new.rows_overlap(now) {+ Edge::Right+ } else if new.right() + 1 == now.left && new.rows_overlap(now) {+ Edge::Left+ } else if new.top == now.bottom() + 1 && new.cols_overlap(now) {+ Edge::Bottom+ } else if new.bottom() + 1 == now.top && new.cols_overlap(now) {+ Edge::Top+ } else {+ return None;+ };+ Some((new_id, edge, *id))+ })+ }+}++/// A slide under way.+#[derive(Clone, Copy, Debug)]+pub struct SplitSlide {+ pub pane_id: PaneId,+ pub edge: Edge,+ /// A pane that made room for it. Until the new pane gets there, the+ /// room still looks like this one's.+ pub from_pane: PaneId,+ started: Instant,+ /// Frames painted with it, this one included.+ frames: u32,+}++impl SplitSlide {+ /// How much of the way it still has to go, 1 at the start and 0 on+ /// arrival; `None` once it is there.+ fn remaining(&self, now: Instant) -> Option<f32> {+ let elapsed = now.saturating_duration_since(self.started) + FIRST_FRAME;+ let by_clock = elapsed.as_secs_f32() / DURATION.as_secs_f32();+ let by_frames = self.frames as f32 / MIN_FRAMES as f32;+ let t = by_clock.min(by_frames);+ if t >= 1.0 {+ return None;+ }+ Some(1.0 - ease_out(t))+ }++ /// The shift that puts the pane `remaining` of the way back out of a+ /// place `width` by `height` pixels.+ pub fn offset(&self, remaining: f32, width: f32, height: f32) -> (f32, f32) {+ match self.edge {+ Edge::Right => (remaining * width, 0.),+ Edge::Left => (-remaining * width, 0.),+ Edge::Bottom => (0., remaining * height),+ Edge::Top => (0., -remaining * height),+ }+ }++ /// The divider the split put along the pane's leading edge.+ pub fn leads(&self, pos: &PositionedPane, split: &PositionedSplit) -> bool {+ let pane = CellRect::of(pos);+ let rows = split.top < pane.bottom() && pane.top < split.top + split.size;+ let cols = split.left < pane.right() && pane.left < split.left + split.size;+ match (self.edge, split.direction) {+ (Edge::Right, SplitDirection::Horizontal) => split.left + 1 == pane.left && rows,+ (Edge::Left, SplitDirection::Horizontal) => split.left == pane.right() && rows,+ (Edge::Bottom, SplitDirection::Vertical) => split.top + 1 == pane.top && cols,+ (Edge::Top, SplitDirection::Vertical) => split.top == pane.bottom() && cols,+ _ => false,+ }+ }+}++/// What of `place` the pane, shifted by `shift`, has yet to cover.+pub fn wake(place: RectF, shift: (f32, f32)) -> RectF {+ let (dx, dy) = (+ shift.0.clamp(-place.width(), place.width()),+ shift.1.clamp(-place.height(), place.height()),+ );+ if dx > 0. {+ euclid::rect(place.min_x(), place.min_y(), dx, place.height())+ } else if dx < 0. {+ euclid::rect(place.max_x() + dx, place.min_y(), -dx, place.height())+ } else if dy > 0. {+ euclid::rect(place.min_x(), place.min_y(), place.width(), dy)+ } else if dy < 0. {+ euclid::rect(place.min_x(), place.max_y() + dy, place.width(), -dy)+ } else {+ euclid::rect(place.min_x(), place.min_y(), 0., 0.)+ }+}++/// Fast, then settling. Squared rather than cubed: cubed, the first two+/// frames covered two thirds of the way and the rest was barely seen to move.+fn ease_out(t: f32) -> f32 {+ 1.0 - (1.0 - t.clamp(0.0, 1.0)).powi(2)+}++/// Last frame's layout and the slide it started, if one is still running.+#[derive(Default)]+pub struct SplitSlides {+ last: Option<TabLayout>,+ running: Option<SplitSlide>,+}++impl SplitSlides {+ /// Take this frame's layout; the slide to paint it with, and how much+ /// of its way is left.+ pub fn advance(+ &mut self,+ layout: Option<TabLayout>,+ enabled: bool,+ now: Instant,+ ) -> Option<(SplitSlide, f32)> {+ let before = std::mem::replace(&mut self.last, layout);+ if !enabled {+ self.running = None;+ return None;+ }+ if let (Some(before), Some(layout)) = (before.as_ref(), self.last.as_ref()) {+ if let Some((pane_id, edge, from_pane)) = layout.opened_by_split(before) {+ self.running = Some(SplitSlide {+ pane_id,+ edge,+ from_pane,+ started: now,+ frames: 0,+ });+ }+ }+ let slide = self.running.as_mut()?;+ slide.frames += 1;+ let slide = *slide;+ // Gone from the tab, or the tab gone from the window: nothing left+ // to slide.+ let on_screen = self+ .last+ .as_ref()+ .is_some_and(|layout| layout.rect(slide.pane_id).is_some() && !layout.zoomed);+ match slide.remaining(now).filter(|_| on_screen) {+ Some(remaining) => Some((slide, remaining)),+ None => {+ self.running = None;+ None+ }+ }+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ fn layout(tab_id: TabId, panes: &[(PaneId, [usize; 4])]) -> TabLayout {+ TabLayout {+ tab_id,+ zoomed: false,+ panes: panes+ .iter()+ .map(|(id, [left, top, width, height])| {+ (+ *id,+ CellRect {+ left: *left,+ top: *top,+ width: *width,+ height: *height,+ },+ )+ })+ .collect(),+ }+ }++ fn new_and_edge((new, edge, _): (PaneId, Edge, PaneId)) -> (PaneId, Edge) {+ (new, edge)+ }++ #[test]+ fn a_split_slides_the_new_pane_in_from_the_side_it_opened_on() {+ let one = layout(1, &[(1, [0, 0, 81, 24])]);+ let right = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);+ assert_eq!(right.opened_by_split(&one).map(new_and_edge), Some((2, Edge::Right)));+ let left = layout(1, &[(2, [0, 0, 40, 24]), (1, [41, 0, 40, 24])]);+ assert_eq!(left.opened_by_split(&one).map(new_and_edge), Some((2, Edge::Left)));+ let below = layout(1, &[(1, [0, 0, 81, 12]), (2, [0, 13, 81, 11])]);+ assert_eq!(below.opened_by_split(&one).map(new_and_edge), Some((2, Edge::Bottom)));+ let above = layout(1, &[(2, [0, 0, 81, 11]), (1, [0, 12, 81, 12])]);+ assert_eq!(above.opened_by_split(&one).map(new_and_edge), Some((2, Edge::Top)));+ }++ #[test]+ fn a_split_across_the_whole_tab_slides_in_beside_every_pane_it_squeezed() {+ let two = layout(1, &[(1, [0, 0, 81, 12]), (2, [0, 13, 81, 11])]);+ let three = layout(+ 1,+ &[(1, [0, 0, 40, 12]), (2, [0, 13, 40, 11]), (3, [41, 0, 40, 24])],+ );+ assert_eq!(+ three.opened_by_split(&two).map(new_and_edge),+ Some((3, Edge::Right))+ );+ }++ #[test]+ fn a_pane_that_did_not_come_by_a_split_does_not_slide() {+ let one = layout(1, &[(1, [0, 0, 81, 24])]);+ let two = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);+ // Another tab with two panes.+ assert_eq!(layout(2, &two.panes_spec()).opened_by_split(&one), None);+ // A zoom let go of.+ let zoomed = TabLayout {+ zoomed: true,+ ..layout(1, &[(1, [0, 0, 81, 24])])+ };+ assert_eq!(two.opened_by_split(&zoomed), None);+ // An overlay closed: the pane under it comes back in its place.+ let overlay = layout(1, &[(1, [0, 0, 40, 24]), (9, [41, 0, 40, 24])]);+ let back = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);+ assert_eq!(back.opened_by_split(&overlay), None);+ // A window's first frame.+ assert_eq!(+ two.opened_by_split(&TabLayout {+ tab_id: 1,+ zoomed: false,+ panes: vec![]+ }),+ None+ );+ // Its neighbour has not given up the room yet.+ let stale = layout(1, &[(1, [0, 0, 81, 24]), (2, [41, 0, 40, 24])]);+ assert_eq!(stale.opened_by_split(&one), None);+ }++ impl TabLayout {+ fn panes_spec(&self) -> Vec<(PaneId, [usize; 4])> {+ self.panes+ .iter()+ .map(|(id, r)| (*id, [r.left, r.top, r.width, r.height]))+ .collect()+ }+ }++ /// The remaining way of each frame painted with the slide, a frame+ /// every `frame` from the split on.+ fn run(frame: Duration) -> Vec<f32> {+ let start = Instant::now();+ let mut slides = SplitSlides::default();+ let one = || Some(layout(1, &[(1, [0, 0, 81, 24])]));+ let two = || Some(layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]));+ assert!(slides.advance(one(), true, start).is_none());+ let mut steps = vec![];+ let mut now = start;+ while let Some((slide, remaining)) = slides.advance(two(), true, now) {+ assert_eq!((slide.pane_id, slide.edge, slide.from_pane), (2, Edge::Right, 1));+ steps.push(remaining);+ now += frame;+ assert!(steps.len() < 100);+ }+ // And it does not start again.+ assert!(slides.advance(two(), true, now + frame).is_none());+ steps+ }++ #[test]+ fn a_slide_starts_on_the_split_and_settles_into_place() {+ let steps = run(Duration::from_micros(8_333));+ // On its way from the first frame, never back, and there within+ // its time.+ assert!(steps[0] < 1.0 && steps[0] > 0.6, "{steps:?}");+ // No frame jumps much more of the way than the first.+ let first = 1.0 - steps[0];+ assert!(+ steps.windows(2).all(|w| w[0] - w[1] <= first * 1.05),+ "{steps:?}"+ );+ assert!(steps.windows(2).all(|w| w[1] < w[0]), "{steps:?}");+ assert!(steps.len() as u32 >= MIN_FRAMES, "{steps:?}");+ assert!(steps.len() <= 22, "{steps:?}");+ let slide = SplitSlide {+ pane_id: 2,+ edge: Edge::Right,+ from_pane: 1,+ started: Instant::now(),+ frames: 1,+ };+ assert_eq!(slide.offset(0.5, 300., 200.), (150., 0.));+ }++ #[test]+ fn slow_frames_slow_the_slide_rather_than_skip_it() {+ let steps = run(Duration::from_millis(60));+ assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{steps:?}");+ assert!(steps.windows(2).all(|w| w[1] < w[0]), "{steps:?}");+ }++ #[test]+ fn with_the_setting_off_nothing_slides() {+ let start = Instant::now();+ let mut slides = SplitSlides::default();+ assert!(slides+ .advance(Some(layout(1, &[(1, [0, 0, 81, 24])])), false, start)+ .is_none());+ let two = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);+ assert!(slides.advance(Some(two), false, start).is_none());+ }++ #[test]+ fn a_pane_closed_mid_slide_stops_it() {+ let start = Instant::now();+ let mut slides = SplitSlides::default();+ slides.advance(Some(layout(1, &[(1, [0, 0, 81, 24])])), true, start);+ let two = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);+ assert!(slides.advance(Some(two), true, start).is_some());+ let one = layout(1, &[(1, [0, 0, 81, 24])]);+ assert!(slides+ .advance(Some(one), true, start + Duration::from_millis(10))+ .is_none());+ }+}