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): drag sidebar rows and pane tabs as themselves
RoversX1603de0c9c8d
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 36ff8458..e0063a13 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_make_way;mod sidebar_slide;mod space_swipe;pub(crate) mod thread_numbers;@@ -547,6 +548,10 @@ pub(crate) const COMMAND_PALETTE_ZINDEX: i8 = 11;/// them with the terminal would have the terminal's text drawn through it.pub(crate) const CONTENT_VIEW_FADE_ZINDEX: i8 = 8;+/// What a drag carries is solid, and goes over the panes and every panel a+/// drag can cross. Within one z-index their text would be drawn through it.+pub(crate) const DRAG_GHOST_ZINDEX: i8 = 13;+lazy_static::lazy_static! {static ref WINDOW_CLASS: Mutex<String> = Mutex::new(wezterm_gui_subcommands::DEFAULT_WINDOW_CLASS.to_owned());static ref POSITION: Mutex<Option<GuiPosition>> = Mutex::new(None);@@ -1382,6 +1387,89 @@ struct FileDragState {active: bool,}+/// How a drag took hold of what it carries: the pointer's distance from the+/// thing's top-left corner, and the thing's size. What follows the pointer+/// is the thing itself, still held where it was pressed.+#[derive(Clone, Copy, Debug, PartialEq)]+pub(crate) struct DragGrip {+ pub x: f32,+ pub y: f32,+ pub width: usize,+ pub height: usize,+}++impl DragGrip {+ pub fn of(item: &UIItem, pointer: ::window::Point) -> Self {+ Self {+ x: pointer.x as f32 - item.x as f32,+ y: pointer.y as f32 - item.y as f32,+ width: item.width,+ height: item.height,+ }+ }++ /// Where the thing's top-left corner goes with the pointer at `pointer`,+ /// whole inside a window of `window` pixels.+ pub fn origin(&self, pointer: ::window::Point, window: (usize, usize)) -> (f32, f32) {+ let place = |at: f32, size: usize, room: usize| at.min(room as f32 - size as f32).max(0.0);+ (+ place(pointer.x as f32 - self.x, self.width, window.0),+ place(pointer.y as f32 - self.y, self.height, window.1),+ )+ }+}++/// What a drag carried, going into its place once let go of, wherever that+/// has turned out to be. The row or tab stays hidden until then, so there+/// is never one of it too many or too few.+#[derive(Clone, Debug)]+pub(crate) struct DragLanding<T> {+ pub what: T,+ pub title: String,+ pub grip: DragGrip,+ /// Where it was let go of.+ from: (f32, f32),+ started: Instant,+}++impl<T> DragLanding<T> {+ const TIME: Duration = Duration::from_millis(170);++ pub fn new(+ what: T,+ title: String,+ grip: DragGrip,+ pointer: ::window::Point,+ window: (usize, usize),+ now: Instant,+ ) -> Self {+ Self {+ what,+ title,+ grip,+ from: grip.origin(pointer, window),+ started: now,+ }+ }++ /// How far it has come, 0 to 1, slowing as it arrives.+ pub fn progress(&self, now: Instant) -> f32 {+ let t = now.saturating_duration_since(self.started).as_secs_f32()+ / Self::TIME.as_secs_f32();+ 1.0 - (1.0 - t.min(1.0)).powi(3)+ }++ /// Where it is on its way to `rest`. Asked every frame, since `rest` can+ /// move: a tab goes on to the stack a drop has only just taken it to.+ pub fn place(&self, rest: (f32, f32), now: Instant) -> (f32, f32) {+ let along = self.progress(now);+ (+ self.from.0 + (rest.0 - self.from.0) * along,+ self.from.1 + (rest.1 - self.from.1) * along,+ )+ }+}+/// A left-sidebar Project or thread row being dragged to a new position in/// its list. Armed on press; the pending click fires on release when the/// drag never crossed the movement threshold.@@ -1389,6 +1477,7 @@ pub(crate) struct SidebarRowDragState {pub kind: SidebarRowKind,/// The row's display name, for the floating ghost under the cursor.pub title: String,+ pub grip: DragGrip,pub start: ::window::Point,pub current: ::window::Point,pub active: bool,@@ -1415,12 +1504,10 @@ pub(crate) enum SidebarRowKind {}/// Where releasing the drag would insert the row: directly before `before`,-/// or last in the list when None. `line_y` is where the insert indicator-/// paints.+/// or last in the list when None.#[derive(Clone, Debug, PartialEq, Eq)]pub(crate) struct SidebarInsertTarget {pub before: Option<String>,- pub line_y: isize,}/// What a Files-panel drag will paste once it lands on the terminal.@@ -1592,6 +1679,7 @@ impl PaneDropPreviewAnim {pub(crate) struct PaneTabDragState {pub pane_id: PaneId,pub title: String,+ pub grip: DragGrip,pub start: ::window::Point,pub current: ::window::Point,pub active: bool,@@ -3226,10 +3314,13 @@ pub struct TermWindow {right_sidebar_file_drag: Option<FileDragState>,/// In-flight drag of a level-2 pane tab toward a move/split drop.pane_tab_drag: Option<PaneTabDragState>,+ pane_tab_landing: Option<DragLanding<PaneId>>,/// Eased picture of `pane_tab_drag`'s drop target; see PaneDropPreviewAnim.pane_drop_preview: Option<PaneDropPreviewAnim>,/// In-flight reorder drag of a left-sidebar Project or thread row.sidebar_row_drag: Option<SidebarRowDragState>,+ sidebar_row_landing: Option<DragLanding<SidebarRowKind>>,+ sidebar_make_way: sidebar_make_way::SidebarMakeWay,/// Content views (e.g. SSH hosts) shown as synthetic tabs.content_views: Vec<ContentViewTab>,active_content_view_id: Option<ContentViewId>,@@ -4702,7 +4793,10 @@ impl TermWindow {self.finish_inline_tab_rename(true);self.right_sidebar_file_drag = None;self.pane_tab_drag = None;+ self.pane_tab_landing = None;self.sidebar_row_drag = None;+ self.sidebar_row_landing = None;+ self.sidebar_make_way.finish(false);let lost_split_drag = self.dragging.as_ref()@@ -5200,6 +5294,9 @@ impl TermWindow {pane_tab_drag: None,pane_drop_preview: None,sidebar_row_drag: None,+ sidebar_row_landing: None,+ sidebar_make_way: Default::default(),+ pane_tab_landing: None,content_views: vec![],active_content_view_id: None,content_view_response_tab_id: None,diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex 6b549494..278ce544 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -3426,9 +3426,11 @@ impl super::TermWindow {draggable: bool,event: MouseEvent,) {+ self.sidebar_row_landing = None;self.sidebar_row_drag = Some(super::SidebarRowDragState {kind,title,+ grip: super::DragGrip::of(&item, event.coords),start: event.coords,current: event.coords,active: false,@@ -3538,8 +3540,9 @@ impl super::TermWindow {/// Recompute which gap the drag would drop into. The candidate rows are/// this frame's rendered rects: same-Space Project rows for a project- /// drag, the same project's (unpinned) thread rows for a thread drag —- /// the pinned section and other projects' threads are not targets.+ /// drag, the same project's (unpinned) thread rows for a thread drag,+ /// the same group's for a reference — the pinned section and other+ /// projects' threads are not targets.fn update_sidebar_row_drag_target(&mut self, coords: ::window::Point) {let Some(kind) = self.sidebar_row_drag@@ -3561,13 +3564,7 @@ impl super::TermWindow {thread_id,project_id,} => {- // A dragged reference row reorders within the Space's ref- // list, not within the origin project's threads.- let siblings = if self.sidebar_row_is_thread_ref(thread_id) {- crate::workspace_threads::space_thread_refs(&self.active_space_id)- } else {- crate::workspace_threads::unpinned_thread_ids(project_id)- };+ let siblings = self.sidebar_thread_siblings(thread_id, project_id);self.ui_items.iter().filter_map(|candidate| match &candidate.item_type {@@ -3584,9 +3581,10 @@ impl super::TermWindow {// A thread pointer that leaves its own list's vertical extent (plus// one row of slack) is not aiming at any of its gaps: dropping there// cancels instead of snapping to the nearest end, which is what- // keeps a thread dragged onto ANOTHER project a no-op. A project- // has no foreign list to stray into — the whole sidebar is its drop- // zone, so anywhere below the last block simply means "the end".+ // keeps a thread dragged onto ANOTHER project, or a reference onto+ // another group, a no-op. A project has no foreign list to stray+ // into — the whole sidebar is its drop zone, so anywhere below the+ // last block simply means "the end".let within_span = match &kind {super::SidebarRowKind::Project(_) | super::SidebarRowKind::RefGroup(_) => {!rows.is_empty()@@ -3599,7 +3597,7 @@ impl super::TermWindow {}};let target = if sidebar_x_ok && within_span {- sidebar_insert_position(&rows, coords.y).map(|(before, line_y)| {+ sidebar_insert_position(&rows, coords.y).map(|before| {// The rendered rows are only the VISIBLE ones: "after the// last visible row" is the end of the viewport, not of the// list. Anchor to the next logical sibling instead, so a@@ -3612,26 +3610,33 @@ impl super::TermWindow {super::SidebarRowKind::Thread {thread_id,project_id,- } => {- if self.sidebar_row_is_thread_ref(thread_id) {- crate::workspace_threads::space_thread_refs(&self.active_space_id)- } else {- crate::workspace_threads::unpinned_thread_ids(project_id)- }- }+ } => self.sidebar_thread_siblings(thread_id, project_id),};let before = clamp_end_anchor_to_next_logical_sibling(before,rows.last().map(|(id, _, _)| id.as_str()),&logical,);- super::SidebarInsertTarget { before, line_y }+ super::SidebarInsertTarget { before }})} else {None};if let Some(state) = self.sidebar_row_drag.as_mut() {- state.target = target;+ if state.target != target {+ state.target = target;+ self.aim_sidebar_make_way();+ }+ }+ }++ /// What a dragged thread row moves among, in order. A dragged reference+ /// reorders within its group, not within the origin project's threads.+ fn sidebar_thread_siblings(&self, thread_id: &str, project_id: &str) -> Vec<String> {+ if self.sidebar_row_is_thread_ref(thread_id) {+ crate::workspace_threads::space_thread_refs_from(&self.active_space_id, project_id)+ } else {+ crate::workspace_threads::unpinned_thread_ids(project_id)}}@@ -3640,10 +3645,25 @@ impl super::TermWindow {state: super::SidebarRowDragState,context: &dyn WindowOps,) {- let Some(target) = state.target else {- return;+ self.sidebar_row_landing = Some(super::DragLanding::new(+ state.kind.clone(),+ state.title.clone(),+ state.grip,+ state.current,+ (self.dimensions.pixel_width, self.dimensions.pixel_height),+ Instant::now(),+ ));+ let moved = self.move_sidebar_row(&state);+ self.sidebar_make_way.finish(moved);+ context.invalidate();+ }++ /// Reorder the list as the drag asks. Returns whether it changed.+ fn move_sidebar_row(&mut self, state: &super::SidebarRowDragState) -> bool {+ let Some(target) = state.target.as_ref() else {+ return false;};- let changed = match &state.kind {+ match &state.kind {super::SidebarRowKind::Project(project_id) => {let space_id = self.active_space_id.clone();// Local Spaces order projects and ref groups in one merged@@ -3688,9 +3708,6 @@ impl super::TermWindow {)}}- };- if changed {- context.invalidate();}}@@ -3716,9 +3733,11 @@ impl super::TermWindow {return;}let title = self.pane_nav_tab_title(pane_id, &pane.get_title());+ self.pane_tab_landing = None;self.pane_tab_drag = Some(PaneTabDragState {pane_id,title,+ grip: super::DragGrip::of(&item, event.coords),start: event.coords,current: event.coords,active: false,@@ -3853,6 +3872,16 @@ impl super::TermWindow {}fn drop_pane_tab_drag(&mut self, state: PaneTabDragState) {+ // Back to its place, or, once the move below goes through, on to+ // the new one.+ self.pane_tab_landing = Some(super::DragLanding::new(+ state.pane_id,+ state.title.clone(),+ state.grip,+ state.current,+ (self.dimensions.pixel_width, self.dimensions.pixel_height),+ Instant::now(),+ ));let Some(target) = state.target else {return;};@@ -10477,7 +10506,7 @@ fn kill_workspace_windows(workspaces: &[String], skip_workspace: Option<&str>) {/// A project's draggable extent is its whole BLOCK: the header row plus/// every thread row rendered under it (nothing when collapsed). Gaps then-/// sit between whole workspaces, so "after X" paints below X's last thread+/// sit between whole workspaces, so "after X" lands below X's last thread/// instead of between X's header and its threads. Relies on the sidebar/// pushing items in visual order: each Project row followed by its rows,/// with the cross-project pinned section preceding the first Project.@@ -10534,20 +10563,20 @@ pub(crate) fn clamp_end_anchor_to_next_logical_sibling(}/// Which gap of a row list a pointer at `pointer_y` selects: insert before-/// the returned id, or at the end when None. The second value is where the-/// insert indicator line paints. Rows are (id, top, bottom) in render order;-/// the upper half of a row aims before it, the lower half after it.+/// the returned id, or at the end when None, and no gap at all without rows.+/// Rows are (id, top, bottom) in render order; the upper half of a row aims+/// before it, the lower half after it.pub(crate) fn sidebar_insert_position(rows: &[(String, isize, isize)],pointer_y: isize,-) -> Option<(Option<String>, isize)> {+) -> Option<Option<String>> {for (id, top, bottom) in rows {let mid = (top + bottom) / 2;if pointer_y < mid {- return Some((Some(id.clone()), *top));+ return Some(Some(id.clone()));}}- rows.last().map(|(_, _, bottom)| (None, *bottom))+ rows.last().map(|_| None)}#[cfg(test)]@@ -10619,10 +10648,10 @@ mod sidebar_drag_tests {("beta".to_string(), 176, 196),]);- // Below beta: the end, with the line under the last block.+ // Below beta: the end.assert_eq!(sidebar_insert_position(&folder_block_extents(&items, "space-x"), 500),- Some((None, 196))+ Some(None));}@@ -10660,20 +10689,20 @@ mod sidebar_drag_tests {// Above everything and in the first row's upper half: before "a".assert_eq!(sidebar_insert_position(&rows(), -10),- Some((Some("a".to_string()), 0))+ Some(Some("a".to_string())));assert_eq!(sidebar_insert_position(&rows(), 4),- Some((Some("a".to_string()), 0))+ Some(Some("a".to_string())));// Lower half of "a" aims after it = before "b".assert_eq!(sidebar_insert_position(&rows(), 15),- Some((Some("b".to_string()), 24))+ Some(Some("b".to_string())));// Lower half of the last row, and anywhere below: the end.- assert_eq!(sidebar_insert_position(&rows(), 60), Some((None, 68)));- assert_eq!(sidebar_insert_position(&rows(), 500), Some((None, 68)));+ assert_eq!(sidebar_insert_position(&rows(), 60), Some(None));+ assert_eq!(sidebar_insert_position(&rows(), 500), Some(None));// No rows: nowhere to drop.assert_eq!(sidebar_insert_position(&[], 10), None);}diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex 45d3d6d4..6330e826 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -3888,84 +3888,39 @@ impl crate::TermWindow {self.paint_drag_ghost_pill(&label, anchor)}- /// Reorder drag of a left-sidebar Project/thread row: a 2px accent- /// insert line at the gap releasing would drop into, plus the floating- /// ghost pill with the row's title.+ /// Reorder drag of a left-sidebar Project/thread row: the rows moving+ /// aside for it, which the sidebar paints where this leaves them, and+ /// the row itself, following the pointer. Driven here and not from the+ /// mouse handler for `paint_pane_tab_drag_overlay`'s reason, and past the+ /// drag's end, while the rows and the row settle.fn paint_sidebar_row_drag_overlay(&mut self) -> anyhow::Result<()> {- let Some(state) = self.sidebar_row_drag.as_ref() else {- return Ok(());- };- if !state.active {- return Ok(());- }- let label = state.title.clone();- let anchor = state.current;- let line_y = state.target.as_ref().map(|target| target.line_y);-- let sidebar_span = self- .ui_items- .iter()- .find(|item| {- item.item_type == crate::termwindow::UIItemType::WorkspaceSidebarBackground- })- .map(|bg| (bg.x as f32, bg.width as f32));-- if let (Some(line_y), Some((bg_x, bg_width))) = (line_y, sidebar_span) {- // Same explicit accent blue as the pane drop preview: readable- // in both appearances regardless of the palette's selected_bg.- let accent = match crate::native_settings::effective_appearance() {- window::Appearance::Light | window::Appearance::LightHighContrast => {- LinearRgba::with_srgba(0, 122, 255, 255)- }- window::Appearance::Dark | window::Appearance::DarkHighContrast => {- LinearRgba::with_srgba(10, 132, 255, 255)- }- };- let inset = self.ui_px(crate::termwindow::ui::tokens::SIDEBAR_INSET) as f32;- let thickness = self.ui_f32(2.0).max(2.0);- let rect = euclid::rect(- bg_x + inset,- line_y as f32 - thickness / 2.0,- (bg_width - inset * 2.0).max(0.0),- thickness,- );- let gl_state = self.render_state.as_ref().unwrap();- let layer = gl_state- .layer_for_zindex(0)- .context("sidebar drag overlay layer")?;- let mut layers = layer.quad_allocator();- self.filled_rectangle(&mut layers, 0, rect, accent)- .context("sidebar drag insert line")?;+ let now = Instant::now();+ if self.sidebar_make_way.step(now) {+ self.update_next_frame_time(Some(now + Duration::from_millis(16)));}-- self.paint_drag_ghost_pill(&label, anchor)+ self.paint_sidebar_row_ghost(now)}/// Translucent preview of where a dragged level-2 pane tab would land/// (its tab bar = move into its stack, full pane = swap with it, half- /// pane = split), plus the floating tab-title pill. Registers no UIItem- /// (hit-transparent).+ /// pane = split), plus the tab itself, following the pointer. Registers+ /// no UIItem (hit-transparent).fn paint_pane_tab_drag_overlay(&mut self) -> anyhow::Result<()> {- let Some(state) = self.pane_tab_drag.as_ref() else {+ let now = Instant::now();+ let Some(state) = self.pane_tab_drag.as_ref().filter(|state| state.active) else {// The drag ended (dropped or cancelled): the layout underneath// has already changed, so a lingering highlight would point at- // nothing. Drop the picture rather than fade it.+ // nothing. Drop the picture rather than fade it. The tab has+ // still to get back to a place.self.pane_drop_preview = None;- return Ok(());+ return self.paint_pane_tab_ghost(now);};- if !state.active {- self.pane_drop_preview = None;- return Ok(());- }- let label = state.title.clone();- let anchor = state.current;let target_rect = state.target.as_ref().map(|target| target.rect);// Ease the drawn highlight toward the hit-tested target. Driven here// and not from the mouse handler because paint_impl clears// has_animation on entry, so only a deadline registered during paint// survives to schedule the next frame.- let now = Instant::now();let shown = match (self.pane_drop_preview.as_mut(), target_rect) {(None, None) => None,(None, Some(rect)) => {@@ -4075,7 +4030,62 @@ impl crate::TermWindow {}}- self.paint_drag_ghost_pill(&label, anchor)+ self.paint_pane_tab_ghost(now)+ }++ /// Set what a drag carries at `(x, y)`, on a surface of its own with a+ /// shadow under it, lifted off its list; `lifted` thins the shadow as it+ /// comes back down. `content` is recorded with the thing's corner at the+ /// origin: the painters take unsigned pixels, and tabs lay themselves+ /// out from x = 0. Registers no UIItem (hit-transparent).+ #[allow(clippy::too_many_arguments)]+ pub(crate) fn paint_drag_ghost(+ &self,+ content: &HeapQuadAllocator,+ (x, y): (f32, f32),+ grip: crate::termwindow::DragGrip,+ surface: LinearRgba,+ border: LinearRgba,+ lifted: f32,+ radius: f32,+ ) -> anyhow::Result<()> {+ let window = (self.dimensions.pixel_width, self.dimensions.pixel_height);+ let gl_state = self.render_state.as_ref().unwrap();+ let layer = gl_state+ .layer_for_zindex(crate::termwindow::DRAG_GHOST_ZINDEX)+ .context("drag ghost layer")?;+ let mut layers = layer.quad_allocator();++ // The surface first, and in place: the shadow is cut to the window+ // as it is drawn, which it could not be from around the origin.+ let ctx = DrawContext::new(gl_state, self.dimensions, &self.render_metrics);+ let shadow = LinearRgba::with_components(+ 0.0,+ 0.0,+ 0.0,+ lifted * if self.chrome().is_dark() { 0.5 } else { 0.22 },+ );+ ctx.draw_elevated_surface(+ &mut layers,+ 0,+ euclid::rect(x, y, grip.width as f32, grip.height as f32),+ surface,+ border,+ shadow,+ radius,+ )+ .context("drag ghost surface")?;++ let clip = QuadClipRect::from_top_left_pixels(+ 0.0,+ 0.0,+ window.0 as f32,+ window.1 as f32,+ &self.dimensions,+ );+ content+ .apply_to_clipped_at(&mut layers, x, y, clip, 1.0)+ .context("drag ghost content")}/// Floating label that follows the cursor during a drag. Painted after@@ -5894,11 +5904,71 @@ impl crate::TermWindow {}}+/// `top` as it looks on `ground`, solid: a ghost goes over anything, and a+/// see-through window would show that through a surface as its bar paints it.+pub(crate) fn drag_ghost_surface(top: LinearRgba, ground: LinearRgba) -> LinearRgba {+ crate::termwindow::ui::sidebar::over(+ top,+ LinearRgba::with_components(ground.0, ground.1, ground.2, 1.0),+ )+}+#[cfg(test)]mod tests {use super::*;use crate::quad::TripleLayerQuadAllocatorTrait;+ #[test]+ fn what_was_let_go_of_goes_from_there_to_its_place() {+ let now = Instant::now();+ let landing = crate::termwindow::DragLanding::new(+ (),+ String::new(),+ grip_of_a_row(),+ ::window::Point::new(340, 406),+ (1000, 800),+ now,+ );+ let rest = (10.0, 100.0);+ assert_eq!(landing.place(rest, now), (310.0, 400.0));+ let later = now + Duration::from_millis(50);+ let (x, y) = landing.place(rest, later);+ assert!(x > 10.0 && x < 310.0 && y > 100.0 && y < 400.0);+ // Faster at first than at the end.+ assert!(landing.progress(later) > 0.5);+ assert_eq!(landing.place(rest, now + Duration::from_secs(1)), rest);+ }++ fn grip_of_a_row() -> crate::termwindow::DragGrip {+ // Pressed 30px in and 6px down a row at (10, 100), 200 by 28.+ crate::termwindow::DragGrip::of(+ &UIItem {+ x: 10,+ y: 100,+ width: 200,+ height: 28,+ item_type: UIItemType::WorkspaceSidebarBackground,+ },+ ::window::Point::new(40, 106),+ )+ }++ #[test]+ fn a_dragged_row_stays_held_where_it_was_pressed() {+ let grip = grip_of_a_row();+ let window = (1000, 800);+ assert_eq!(grip.origin(::window::Point::new(40, 106), window), (10.0, 100.0));+ assert_eq!(grip.origin(::window::Point::new(340, 406), window), (310.0, 400.0));+ }++ #[test]+ fn a_dragged_row_stays_whole_inside_the_window() {+ let grip = grip_of_a_row();+ let window = (1000, 800);+ assert_eq!(grip.origin(::window::Point::new(0, 0), window), (0.0, 0.0));+ assert_eq!(grip.origin(::window::Point::new(2000, 2000), window), (800.0, 772.0));+ }+#[test]fn right_sidebar_hover_keeps_tab_bar_buttons_clickable() {// Test both the narrow blocker used during animation and the fulldiff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rsindex e1d7a060..66a90159 100644--- a/wezterm-gui/src/termwindow/render/pane.rs+++ b/wezterm-gui/src/termwindow/render/pane.rs@@ -1498,6 +1498,22 @@ impl crate::TermWindow {let tab_left = pane_x + place.x;let tab_right = tab_left + tab_width as f32;+ // A tab pressed half out of the strip was hit where the strip+ // stops; what the drag carries is all of it.+ let carried = match self+ .pane_tab_drag+ .as_mut()+ .filter(|drag| drag.pane_id == tab.pane_id)+ {+ Some(drag) => {+ drag.grip.width = tab_width;+ drag.active+ }+ None => false,+ } || self+ .pane_tab_landing+ .as_ref()+ .is_some_and(|landing| landing.what == tab.pane_id);if tab_right <= tab_start as f32 || tab_left >= max_tab_right as f32 {continue;}@@ -1562,6 +1578,12 @@ impl crate::TermWindow {},});}+ // A tab a drag has is painted where the pointer is, then on its+ // way into place, so it is not left here as well. Its place in+ // the strip stays.+ if carried {+ continue;+ }// Reborrow: the surrounding loop cannot move the caller's `&mut`.let out_layers = &mut *layers;@@ -1827,6 +1849,104 @@ impl crate::TermWindow {)}+ /// The tab a drag carries, laid out as the strip lays it out and+ /// selected, as pressing it left it. Its close button stays behind:+ /// nothing on it can be pressed while it is carried. Let go of, it goes+ /// on to its place, taking on the width it finds there.+ pub(crate) fn paint_pane_tab_ghost(&mut self, now: Instant) -> anyhow::Result<()> {+ let window = (self.dimensions.pixel_width, self.dimensions.pixel_height);+ let drag = self.pane_tab_drag.as_ref().filter(|drag| drag.active);+ let (pane_id, raw_title, origin, grip) = if let Some(state) = drag {+ let origin = state.grip.origin(state.current, window);+ (state.pane_id, state.title.clone(), origin, state.grip)+ } else if let Some(landing) = self.pane_tab_landing.clone() {+ let rest = self.ui_items.iter().find(|item| {+ matches!(+ &item.item_type,+ UIItemType::PaneNav { action: PaneNavAction::Activate(id), .. }+ if *id == landing.what+ )+ });+ let Some(rest) = rest else {+ self.pane_tab_landing = None;+ return Ok(());+ };+ let origin = landing.place((rest.x as f32, rest.y as f32), now);+ let landed = landing.progress(now);+ let from = landing.grip.width as f32;+ let width = (from + (rest.width as f32 - from) * landed).round() as usize;+ // Its last frame here is the tab's first frame back, or there+ // would be one with neither.+ if landed >= 1.0 {+ self.pane_tab_landing = None;+ }+ self.update_next_frame_time(Some(now + std::time::Duration::from_millis(16)));+ let grip = crate::termwindow::DragGrip {+ width,+ ..landing.grip+ };+ (landing.what, landing.title, origin, grip)+ } else {+ return Ok(());+ };+ let (width, height) = (grip.width, grip.height);+ let (title, running) = match split_leading_legacy_progress_marker(&raw_title) {+ Some("") => ("Terminal", true),+ Some(title) => (title, true),+ None => (raw_title.as_str(), false),+ };+ let chrome = self.chrome();+ let surface = crate::termwindow::render::paint::drag_ghost_surface(+ chrome.active_tab_surface(),+ self.tab_bar_surface(chrome.header_bg),+ );+ let ui_font = self+ .fonts+ .title_font_with_size(crate::native_settings::pane_header_font_size(+ &crate::native_settings::load_shared(),+ ))+ .context("pane tab ghost font")?;+ let ui_metrics = RenderMetrics::with_font_metrics(&ui_font.metrics());++ let mut content = HeapQuadAllocator::default();+ let mut layers = TripleLayerQuadAllocator::Heap(&mut content);+ let icon_size = self.ui_px(TAB_ICON_SIZE).min(height);+ let icon_right = self.paint_pane_tab_icon(+ &mut layers,+ pane_id,+ 0,+ height,+ icon_size,+ running,+ chrome.text,+ surface,+ self.focused.is_some(),+ )?;+ let text_x = icon_right + self.ui_px(PANE_NAV_ICON_GAP);+ let text_right = self.tab_close_button_x(width, height, icon_size);+ self.paint_pane_nav_text(+ &mut layers,+ &ui_font,+ ui_metrics,+ title,+ text_x,+ height.saturating_sub(ui_metrics.cell_size.height as usize) / 2,+ text_right.saturating_sub(text_x + self.ui_px(PANE_NAV_ICON_GAP)),+ chrome.text,+ )?;+ drop(layers);++ self.paint_drag_ghost(+ &content,+ origin,+ grip,+ surface,+ chrome.control_border,+ 1.0,+ self.ui_f32(PANE_NAV_TAB_RADIUS),+ )+ }+fn paint_pane_nav_text(&self,layers: &mut TripleLayerQuadAllocator,diff --git a/wezterm-gui/src/termwindow/sidebar_make_way.rs b/wezterm-gui/src/termwindow/sidebar_make_way.rsnew file mode 100644index 00000000..f3321a44--- /dev/null+++ b/wezterm-gui/src/termwindow/sidebar_make_way.rs@@ -0,0 +1,220 @@+//! Sidebar rows moving out of the way of one being dragged through them.+//!+//! Only the picture moves. A row keeps its place in the list and its hit+//! rect, which the drop is aimed by, until the drop: where a row is drawn+//! never feeds back into where the gap goes, so the rows cannot chase it.++use std::collections::HashMap;+use std::time::{Duration, Instant};++/// Time constant of the rows' ease: most of the way in three of these.+const TAU: Duration = Duration::from_millis(50);+/// Close enough to where it is going, in pixels.+const NEAR: f32 = 0.5;++/// Which rows give way for `source` to go before `before`, the end of the+/// list when None, and by how much: `by` is what `source` takes up. Rows+/// between where it was and where it goes close up behind it.+pub(crate) fn shifts_for_move(+ list: &[&str],+ source: &str,+ before: Option<&str>,+ by: f32,+) -> Vec<(String, f32)> {+ let Some(from) = list.iter().position(|id| *id == source) else {+ return vec![];+ };+ // Not in the list: a row the status filter hides, or the other side of+ // it. Either way past everything this list shows.+ let to = before+ .and_then(|before| list.iter().position(|id| *id == before))+ .unwrap_or(list.len());+ let (passed, by) = if to > from {+ (&list[from + 1..to], -by)+ } else {+ (&list[to..from], by)+ };+ passed.iter().map(|id| (id.to_string(), by)).collect()+}++#[derive(Clone, Copy, Debug, PartialEq)]+struct Shift {+ drawn: f32,+ going: f32,+}++/// How far from their places rows are drawn, by row or folder id. Holds only+/// rows on the move or moved aside, so it empties when a drag has settled.+#[derive(Debug, Default)]+pub(crate) struct SidebarMakeWay {+ shifts: HashMap<String, Shift>,+ last_tick: Option<Instant>,+}++impl SidebarMakeWay {+ pub fn shift_of(&self, id: &str) -> f32 {+ self.shifts.get(id).map_or(0.0, |shift| shift.drawn)+ }++ /// Send the rows in `going` that far from their places, the rest home.+ pub fn aim(&mut self, going: Vec<(String, f32)>) {+ for shift in self.shifts.values_mut() {+ shift.going = 0.0;+ }+ for (id, by) in going {+ self.shifts+ .entry(id)+ .or_insert(Shift {+ drawn: 0.0,+ going: 0.0,+ })+ .going = by;+ }+ }++ /// The drag is over. With `moved`, the list has just changed to what the+ /// rows were heading for, so each is now at home in a new place, still+ /// drawn where it was: it goes on from there rather than jumping. Without+ /// it, they go back.+ pub fn finish(&mut self, moved: bool) {+ for shift in self.shifts.values_mut() {+ if moved {+ shift.drawn -= shift.going;+ }+ shift.going = 0.0;+ }+ }++ /// Advance the rows. Returns whether any is still moving.+ pub fn step(&mut self, now: Instant) -> bool {+ // A starved frame must not land as one huge jump.+ let dt = self.last_tick.map_or(Duration::from_millis(16), |last| {+ now.saturating_duration_since(last)+ .min(Duration::from_millis(100))+ });+ let k = 1.0 - (-(dt.as_secs_f32() / TAU.as_secs_f32())).exp();+ let mut moving = false;+ for shift in self.shifts.values_mut() {+ if (shift.going - shift.drawn).abs() <= NEAR {+ shift.drawn = shift.going;+ } else {+ shift.drawn += (shift.going - shift.drawn) * k;+ moving = true;+ }+ }+ self.shifts+ .retain(|_, shift| shift.drawn != 0.0 || shift.going != 0.0);+ self.last_tick = moving.then_some(now);+ moving+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ const LIST: [&str; 4] = ["a", "b", "c", "d"];++ fn shifts(source: &str, before: Option<&str>) -> Vec<(String, f32)> {+ shifts_for_move(&LIST, source, before, 10.0)+ }++ fn pairs(want: &[(&str, f32)]) -> Vec<(String, f32)> {+ want.iter().map(|(id, by)| (id.to_string(), *by)).collect()+ }++ #[test]+ fn rows_a_downward_drag_passes_close_up_behind_it() {+ assert_eq!(shifts("a", Some("c")), pairs(&[("b", -10.0)]));+ assert_eq!(shifts("a", Some("d")), pairs(&[("b", -10.0), ("c", -10.0)]));+ }++ #[test]+ fn rows_an_upward_drag_passes_step_down_for_it() {+ assert_eq!(shifts("d", Some("c")), pairs(&[("c", 10.0)]));+ assert_eq!(shifts("c", Some("a")), pairs(&[("a", 10.0), ("b", 10.0)]));+ }++ #[test]+ fn the_end_of_the_list_is_past_every_row() {+ assert_eq!(shifts("c", None), pairs(&[("d", -10.0)]));+ // Hidden by the status filter: as far as this list shows, the end.+ assert_eq!(shifts("c", Some("hidden")), pairs(&[("d", -10.0)]));+ }++ #[test]+ fn nothing_moves_for_a_row_over_its_own_place() {+ assert!(shifts("b", Some("b")).is_empty());+ assert!(shifts("b", Some("c")).is_empty());+ assert!(shifts("d", None).is_empty());+ }++ #[test]+ fn a_row_not_in_the_list_moves_nothing() {+ assert!(shifts("elsewhere", Some("a")).is_empty());+ }++ fn settle(way: &mut SidebarMakeWay) {+ let mut now = Instant::now();+ for _ in 0..200 {+ now += Duration::from_millis(16);+ if !way.step(now) {+ return;+ }+ }+ panic!("the rows never settled");+ }++ #[test]+ fn rows_stay_aside_until_sent_home_and_are_then_forgotten() {+ let mut way = SidebarMakeWay::default();+ way.aim(pairs(&[("b", -10.0)]));+ settle(&mut way);+ assert_eq!(way.shift_of("b"), -10.0);++ way.aim(vec![]);+ settle(&mut way);+ assert_eq!(way.shift_of("b"), 0.0);+ assert!(way.shifts.is_empty());+ }++ #[test]+ fn a_row_changes_course_from_where_it_is_drawn() {+ let mut way = SidebarMakeWay::default();+ way.aim(pairs(&[("b", -10.0)]));+ way.step(Instant::now());+ let drawn = way.shift_of("b");+ assert!(drawn < 0.0 && drawn > -10.0);++ way.aim(pairs(&[("b", 10.0)]));+ assert_eq!(way.shift_of("b"), drawn);+ }++ #[test]+ fn a_drop_leaves_rows_drawn_where_they_were() {+ let mut way = SidebarMakeWay::default();+ way.aim(pairs(&[("b", -10.0)]));+ way.step(Instant::now());+ let drawn = way.shift_of("b");++ // The row's place is now ten pixels up: drawn at the same spot, it+ // is that much less far from it.+ way.finish(true);+ assert_eq!(way.shift_of("b"), drawn + 10.0);+ settle(&mut way);+ assert!(way.shifts.is_empty());+ }++ #[test]+ fn a_cancelled_drag_sends_rows_home_from_where_they_are() {+ let mut way = SidebarMakeWay::default();+ way.aim(pairs(&[("b", -10.0)]));+ way.step(Instant::now());+ let drawn = way.shift_of("b");++ way.finish(false);+ assert_eq!(way.shift_of("b"), drawn);+ settle(&mut way);+ assert!(way.shifts.is_empty());+ }+}diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rsindex 66ebbbcd..0632f094 100644--- a/wezterm-gui/src/termwindow/ui/sidebar.rs+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs@@ -1,4 +1,6 @@-use crate::quad::{QuadTrait, TripleLayerQuadAllocator, TripleLayerQuadAllocatorTrait};+use crate::quad::{+ HeapQuadAllocator, QuadTrait, TripleLayerQuadAllocator, TripleLayerQuadAllocatorTrait,+};use crate::termwindow::render::corners::{BOTTOM_LEFT_ROUNDED_CORNER, BOTTOM_RIGHT_ROUNDED_CORNER, TOP_LEFT_ROUNDED_CORNER,TOP_RIGHT_ROUNDED_CORNER,@@ -16,7 +18,8 @@ use crate::termwindow::ui::tokens::{WINDOW_TAB_TOP_SPACER,};use crate::native_settings::{NativeThreadIcons, NativeThreadStatus};-use crate::termwindow::{UIItem, UIItemType};+use crate::termwindow::sidebar_make_way::shifts_for_move;+use crate::termwindow::{SidebarRowKind, UIItem, UIItemType};use crate::thread_marks::{self, Mark};use crate::ui::draw::DrawContext;use crate::ui::{scale_ui_f32, scale_ui_usize, unscale_ui_usize, UiPalette};@@ -815,6 +818,18 @@ impl crate::TermWindow {}}+ /// Whether something other than the Space's own threads is on screen, so+ /// that their active pointer is stale for `suppress_active` above.+ fn sidebar_own_active_is_stale(+ &self,+ view: &workspace_threads::WorkspaceThreadsView,+ active_workspace: &str,+ ) -> bool {+ view.ref_workspace_on_screen()+ || workspace_threads::is_share_view_workspace(active_workspace)+ || self.any_share_view_opening()+ }+/// A thread at rest, in the status colours (`thread_marks`): the one/// the user is in, `current`, in green.fn sidebar_thread_dot_color(@@ -1568,6 +1583,25 @@ impl crate::TermWindow {.context("sidebar ui font")?;let ui_metrics = RenderMetrics::with_font_metrics(&ui_font.metrics());let row_marks = self.sidebar_thread_row_marks()?;+ // A row a drag has is painted where the pointer is, then on its way+ // into place, so it is not left here as well. Its hit rect stays:+ // the drop is aimed by those, not by where rows are drawn.+ let carried = self+ .sidebar_row_drag+ .as_ref()+ .filter(|drag| drag.active)+ .map(|drag| &drag.kind)+ .or(self.sidebar_row_landing.as_ref().map(|landing| &landing.what))+ .cloned();+ let thread_carried = |id: &str| {+ matches!(&carried, Some(SidebarRowKind::Thread { thread_id, .. }) if thread_id == id)+ };+ let folder_carried = |id: &str| {+ matches!(+ &carried,+ Some(SidebarRowKind::Project(key) | SidebarRowKind::RefGroup(key)) if key == id+ )+ };let ui_cell_height = ui_metrics.cell_size.height as usize;let icon_size = (ui_cell_height + self.ui_px(12)).clamp(self.ui_px(30), self.ui_px(36));let layout = self.workspace_sidebar_layout(rect, ui_cell_height, icon_size);@@ -1654,9 +1688,7 @@ impl crate::TermWindow {// A ref row is showing its workspace, or a row of "Shared with me"// is: the Space's own rows must not paint a second active highlight// from their stale pointer.- let suppress_own_active = view.ref_workspace_on_screen()- || workspace_threads::is_share_view_workspace(&active_workspace)- || self.any_share_view_opening();+ let suppress_own_active = self.sidebar_own_active_is_stale(&view, &active_workspace);let header_icon_size = icon_size.min(self.ui_px(32));let button_size = (header_icon_size + self.ui_px(8)).clamp(self.ui_px(32), self.ui_px(40));@@ -2118,10 +2150,16 @@ impl crate::TermWindow {}let list_top_f = list_top as f32;let content_bottom_f = content_bottom as f32;- let suppress_hover = self- .current_mouse_event- .as_ref()- .is_some_and(|event| matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_)));+ let suppress_hover = carried.is_some()+ || self+ .current_mouse_event+ .as_ref()+ .is_some_and(|event| matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_)));+ // Whether a row drawn from `top` shows, which a row moved aside may+ // when its place does not.+ let paints_at = |top: f32| {+ top + session_row_height as f32 > list_top_f && top < content_bottom_f+ };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.@@ -2448,7 +2486,9 @@ impl crate::TermWindow {let row_top = list_top_f + virtual_y as f32 - scroll_offset;let row_bottom = row_top + session_row_height as f32;let row_is_visible = row_bottom > list_top_f && row_top < content_bottom_f;- let y = row_top.floor().max(0.0) as usize;+ let folder_shift = self.sidebar_make_way.shift_of(&project.id);+ let row_paints = paints_at(row_top + folder_shift) && !folder_carried(&project.id);+ let y = (row_top + folder_shift).floor().max(0.0) as usize;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);@@ -2516,7 +2556,7 @@ impl crate::TermWindow {let icon_y = y + ((session_row_height.saturating_sub(icon_size)) / 2);let disclosure_y = y + ((session_row_height.saturating_sub(disclosure_size)) / 2);let text_y = y + ((session_row_height.saturating_sub(ui_cell_height)) / 2);- if row_is_visible {+ if row_paints {self.ui_items.push(UIItem {x: disclosure_x,y: disclosure_y,@@ -2536,39 +2576,14 @@ impl crate::TermWindow {disclosure_size,muted_fg,)?;- let remote_brand = if project.is_remote {- project.distro.as_deref().and_then(distro_to_icon)- } else {- None- };- if let Some(brand) = remote_brand {- // Detected remote OS: show its brand logo in full color.- self.paint_sidebar_brand_icon(- layers,- brand,- project_icon_x,- icon_y,- icon_size,- )?;- } else {- let project_icon = if project.is_remote {- // Remote host without a detected OS: a globe marks it as- // distinct from local folder projects in the mixed list.- SvgIcon::Globe- } else if project.threads_collapsed {- SvgIcon::Folder- } else {- SvgIcon::FolderOpen- };- self.paint_sidebar_icon(- layers,- project_icon,- project_icon_x,- icon_y,- icon_size,- muted_fg,- )?;- }+ self.paint_sidebar_project_icon(+ layers,+ project,+ project_icon_x,+ icon_y,+ icon_size,+ muted_fg,+ )?;let project_title = self.sidebar_project_title(&project.id, &project.name);self.paint_sidebar_name(layers,@@ -2583,7 +2598,7 @@ impl crate::TermWindow {)?;}- if row_is_visible {+ if row_paints {let project_action_y =y + ((session_row_height.saturating_sub(project_action_size)) / 2);let project_action_hovered = !suppress_hover@@ -2607,13 +2622,17 @@ impl crate::TermWindow {false,).context("sidebar new thread button")?;- self.ui_items.push(UIItem {- x: project_action_x,- y: project_action_y,- width: project_action_size,- height: project_action_size,- item_type: UIItemType::WorkspaceThreadNew(project.id.clone()),- });+ // Not while rows are moving: it counts toward the extent+ // of its folder, and it is drawn away from its place.+ if carried.is_none() {+ self.ui_items.push(UIItem {+ x: project_action_x,+ y: project_action_y,+ width: project_action_size,+ height: project_action_size,+ item_type: UIItemType::WorkspaceThreadNew(project.id.clone()),+ });+ }let action_icon_size = (header_icon_size + 4).min(project_action_size.saturating_sub(self.ui_px(SIDEBAR_SECTION_ACTION_ICON_INSET)),@@ -2649,7 +2668,11 @@ impl crate::TermWindow {let row_top = list_top_f + virtual_y as f32 - scroll_offset;let row_bottom = row_top + session_row_height as f32;let row_is_visible = row_bottom > list_top_f && row_top < content_bottom_f;- let y = row_top.floor().max(0.0) as usize;+ let row_shift = folder_shift + self.sidebar_make_way.shift_of(&session.id);+ let row_paints = paints_at(row_top + row_shift)+ && !thread_carried(&session.id)+ && !folder_carried(&project.id);+ let y = (row_top + row_shift).floor().max(0.0) as usize;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;@@ -2661,7 +2684,7 @@ impl crate::TermWindow {current_row =Some(CurrentRow::new(virtual_y, None, thread_icon(session)));}- if row_is_visible && is_selected {+ if row_paints && is_selected {let row_rect = euclid::rect(session_x as f32,y as f32,@@ -2696,6 +2719,8 @@ impl crate::TermWindow {height: hit_height,item_type: UIItemType::WorkspaceThread(session.id.clone()),});+ }+ if row_paints {let is_hovered = !suppress_hover&& self.is_pointer_over_ui_rect(session_x,@@ -2869,7 +2894,9 @@ impl crate::TermWindow {let row_top = list_top_f + virtual_y as f32 - scroll_offset;let row_bottom = row_top + session_row_height as f32;let row_is_visible = row_bottom > list_top_f && row_top < content_bottom_f;- let y = row_top.floor().max(0.0) as usize;+ let folder_shift = self.sidebar_make_way.shift_of(&group.key);+ let row_paints = paints_at(row_top + folder_shift) && !folder_carried(&group.key);+ let y = (row_top + folder_shift).floor().max(0.0) as usize;// Hit rect clamped to the list viewport, like every other// full-width row: a header scrolled under the toolbar keeps// painting (masked) but must not swallow toolbar clicks.@@ -2924,6 +2951,8 @@ impl crate::TermWindow {origin: origin_tag,},});+ }+ if row_paints {self.paint_sidebar_icon(layers,if group.collapsed {@@ -3005,7 +3034,7 @@ impl crate::TermWindow {!group.attached,).context("sidebar ref group new thread button")?;- if group.attached {+ if group.attached && carried.is_none() {self.ui_items.push(UIItem {x: group_action_x,y: group_action_y,@@ -3065,7 +3094,11 @@ impl crate::TermWindow {let row_top = list_top_f + virtual_y as f32 - scroll_offset;let row_bottom = row_top + session_row_height as f32;let row_is_visible = row_bottom > list_top_f && row_top < content_bottom_f;- let y = row_top.floor().max(0.0) as usize;+ let row_shift = folder_shift + self.sidebar_make_way.shift_of(&session.id);+ let row_paints = paints_at(row_top + row_shift)+ && !thread_carried(&session.id)+ && !folder_carried(&group.key);+ let y = (row_top + row_shift).floor().max(0.0) as usize;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;@@ -3089,6 +3122,8 @@ impl crate::TermWindow {item_type: UIItemType::WorkspaceThread(session.id.clone()),});}+ }+ if row_paints {let is_hovered = !suppress_hover&& self.is_pointer_over_ui_rect(session_x,@@ -4400,7 +4435,323 @@ impl crate::TermWindow {)}- /// A folder's name: as a thread row's, it goes out when it is too long.+ fn paint_sidebar_project_icon(+ &self,+ layers: &mut TripleLayerQuadAllocator,+ project: &workspace_threads::ProjectView,+ x: usize,+ y: usize,+ size: usize,+ color: LinearRgba,+ ) -> anyhow::Result<()> {+ let remote_brand = if project.is_remote {+ project.distro.as_deref().and_then(distro_to_icon)+ } else {+ None+ };+ if let Some(brand) = remote_brand {+ // Detected remote OS: show its brand logo in full color.+ return self.paint_sidebar_brand_icon(layers, brand, x, y, size);+ }+ let icon = if project.is_remote {+ // Remote host without a detected OS: a globe marks it as+ // distinct from local folder projects in the mixed list.+ SvgIcon::Globe+ } else if project.threads_collapsed {+ SvgIcon::Folder+ } else {+ SvgIcon::FolderOpen+ };+ self.paint_sidebar_icon(layers, icon, x, y, size, color)+ }++ /// Send the rows around the one being dragged where the drop would+ /// leave them, the gap showing where it would land.+ pub(crate) fn aim_sidebar_make_way(&mut self) {+ let going = self.sidebar_make_way_shifts().unwrap_or_default();+ self.sidebar_make_way.aim(going);+ }++ fn sidebar_make_way_shifts(&self) -> Option<Vec<(String, f32)>> {+ let drag = self.sidebar_row_drag.as_ref().filter(|drag| drag.active)?;+ let before = drag.target.as_ref()?.before.as_deref();+ let rect = self.workspace_sidebar_rect()?;+ let ui_cell_height = self.workspace_sidebar_cell_height();+ let icon_size = (ui_cell_height + self.ui_px(12)).clamp(self.ui_px(30), self.ui_px(36));+ let layout = self.workspace_sidebar_layout(rect, ui_cell_height, icon_size);+ let row = layout.row_height + self.ui_px(SIDEBAR_ROW_GAP);++ let mux = Mux::get();+ let active_workspace = self+ .current_mux_workspace()+ .unwrap_or_else(|| mux.active_workspace());+ let workspaces = mux.iter_workspaces();+ let view = self.workspace_sidebar_view(&active_workspace, &workspaces);++ match &drag.kind {+ SidebarRowKind::Thread {+ thread_id,+ project_id,+ } => {+ let own = view+ .projects+ .iter()+ .map(|project| project.threads.iter().map(|t| t.id.as_str()).collect())+ .find(|list: &Vec<&str>| list.contains(&thread_id.as_str()));+ if let Some(list) = own {+ return Some(shifts_for_move(&list, thread_id, before, row as f32));+ }+ let refs =+ workspace_threads::space_thread_refs_from(&self.active_space_id, project_id);+ let refs: Vec<&str> = refs.iter().map(String::as_str).collect();+ Some(shifts_for_move(&refs, thread_id, before, row as f32))+ }+ SidebarRowKind::Project(key) | SidebarRowKind::RefGroup(key) => {+ // A folder moves whole, past folders it takes up the room of.+ let folders: Vec<(&str, usize)> = view+ .display_order+ .iter()+ .filter_map(|folder| match *folder {+ workspace_threads::SidebarFolder::Project(index) => {+ let project = view.projects.get(index)?;+ let rows = if project.threads_collapsed {+ 0+ } else {+ project.threads.len()+ };+ (!project.is_archived).then_some((project.id.as_str(), rows))+ }+ workspace_threads::SidebarFolder::RefGroup(index) => {+ let group = view.ref_groups.get(index)?;+ let rows = if group.collapsed {+ 0+ } else {+ group.threads.len()+ };+ Some((group.key.as_str(), rows))+ }+ })+ .collect();+ let rows = folders.iter().find(|(id, _)| id == key)?.1;+ let by = (rows + 1) * row + self.ui_px(WORKSPACE_GROUP_EXTRA_GAP);+ let list: Vec<&str> = folders.iter().map(|(id, _)| *id).collect();+ Some(shifts_for_move(&list, key, before, by as f32))+ }+ }+ }++ /// Where a row rests in the list as painted this frame.+ fn sidebar_row_rest(&self, kind: &SidebarRowKind) -> Option<(f32, f32)> {+ let space_prefix = format!("{}::", self.active_space_id);+ self.ui_items+ .iter()+ .find(|item| match (&item.item_type, kind) {+ (UIItemType::WorkspaceThread(id), SidebarRowKind::Thread { thread_id, .. }) => {+ id == thread_id+ }+ (UIItemType::Project(id), SidebarRowKind::Project(project_id)) => id == project_id,+ (UIItemType::ThreadRefGroupToggle { key, .. }, SidebarRowKind::RefGroup(raw)) => {+ key.strip_prefix(&space_prefix).unwrap_or(key.as_str()) == raw.as_str()+ }+ _ => false,+ })+ .map(|item| (item.x as f32, item.y as f32))+ }++ /// The row a reorder carries, laid out as the list lays it out, on a+ /// surface of its own: at rest most rows have none to lift. Its buttons+ /// stay behind: nothing on it can be pressed while it is carried. Let+ /// go of, it goes on to its place, and such a surface fades as it gets+ /// there, so that the row it becomes is no different.+ pub(crate) fn paint_sidebar_row_ghost(&mut self, now: Instant) -> anyhow::Result<()> {+ let drag = self.sidebar_row_drag.as_ref().filter(|drag| drag.active);+ let (kind, title, grip, origin, landed) = if let Some(state) = drag {+ let window = (self.dimensions.pixel_width, self.dimensions.pixel_height);+ let origin = state.grip.origin(state.current, window);+ (state.kind.clone(), state.title.clone(), state.grip, origin, 0.0)+ } else if let Some(landing) = self.sidebar_row_landing.clone() {+ let Some(rest) = self.sidebar_row_rest(&landing.what) else {+ self.sidebar_row_landing = None;+ return Ok(());+ };+ let landed = landing.progress(now);+ let origin = landing.place(rest, now);+ // Its last frame here is the row's first frame back, or there+ // would be one with neither.+ if landed >= 1.0 {+ self.sidebar_row_landing = None;+ }+ self.update_next_frame_time(Some(now + Duration::from_millis(16)));+ (landing.what, landing.title, landing.grip, origin, landed)+ } else {+ return Ok(());+ };+ let Some(rect) = self.workspace_sidebar_rect() else {+ return Ok(());+ };+ let chrome = self.chrome();+ let ui_font = self+ .fonts+ .title_font_with_size(crate::native_settings::sidebar_font_size(+ &crate::native_settings::load_shared(),+ ))+ .context("sidebar row ghost font")?;+ let ui_metrics = RenderMetrics::with_font_metrics(&ui_font.metrics());+ let ui_cell_height = ui_metrics.cell_size.height as usize;+ let icon_size = (ui_cell_height + self.ui_px(12)).clamp(self.ui_px(30), self.ui_px(36));+ // Not the row's hit rect, which the list's ends cut.+ let height = self+ .workspace_sidebar_layout(rect, ui_cell_height, icon_size)+ .row_height;+ let grip = crate::termwindow::DragGrip { height, ..grip };+ let width = grip.width;+ let inset = self.ui_px(SIDEBAR_INSET);+ let text_y = height.saturating_sub(ui_cell_height) / 2;+ let surface = crate::termwindow::render::paint::drag_ghost_surface(+ chrome.sidebar_row_active_bg,+ self.sidebar_surface(chrome.workspace_sidebar_bg),+ );++ let mux = Mux::get();+ let active_workspace = self+ .current_mux_workspace()+ .unwrap_or_else(|| mux.active_workspace());+ let workspaces = mux.iter_workspaces();+ let view = self.workspace_sidebar_view(&active_workspace, &workspaces);+ let suppress_own_active = self.sidebar_own_active_is_stale(&view, &active_workspace);++ // Whether the row has a surface of its own to come down onto.+ let mut rests_selected = false;+ let mut content = HeapQuadAllocator::default();+ let mut layers = TripleLayerQuadAllocator::Heap(&mut content);+ // A folder header's chevron and name; says where its icon goes.+ let folder_row = |layers: &mut TripleLayerQuadAllocator,+ collapsed: bool,+ fg: LinearRgba|+ -> anyhow::Result<(usize, usize)> {+ let disclosure_size = icon_size.min(22);+ self.paint_sidebar_icon(+ layers,+ if collapsed {+ SvgIcon::ChevronRight+ } else {+ SvgIcon::ChevronDown+ },+ inset,+ height.saturating_sub(disclosure_size) / 2,+ disclosure_size,+ chrome.secondary_text,+ )?;+ let icon_x = inset + disclosure_size + 4;+ let text_x = icon_x + icon_size + self.ui_px(SIDEBAR_ICON_GAP);+ self.paint_sidebar_name(+ layers,+ &ui_font,+ ui_metrics,+ &title,+ text_x,+ text_y,+ width.saturating_sub(text_x + inset),+ fg,+ )?;+ Ok((icon_x, height.saturating_sub(icon_size) / 2))+ };+ match &kind {+ SidebarRowKind::Thread { thread_id, .. } => {+ let own = view+ .pinned_threads+ .iter()+ .chain(view.projects.iter().flat_map(|project| &project.threads))+ .find(|thread| thread.id == *thread_id)+ .map(|thread| (thread, false, suppress_own_active));+ let row = own.or_else(|| {+ view.ref_groups+ .iter()+ .flat_map(|group| &group.threads)+ .find(|reference| reference.thread.id == *thread_id)+ .map(|reference| {+ let dimmed = reference.dangling || !reference.origin_domain_attached;+ (&reference.thread, dimmed, false)+ })+ });+ let Some((thread, dimmed, suppress_active)) = row else {+ return Ok(());+ };+ rests_selected = self.is_workspace_sidebar_thread_selected(thread, suppress_active);+ let marks = self.sidebar_thread_row_marks()?;+ let (text_x, marks_right) = self.paint_sidebar_thread_marks(+ &mut layers,+ &marks,+ thread,+ inset + 2,+ width.saturating_sub(inset),+ 0,+ height,+ surface,+ true,+ dimmed,+ rests_selected,+ 1.0,+ &chrome,+ chrome.text,+ )?;+ self.paint_sidebar_name(+ &mut layers,+ &ui_font,+ ui_metrics,+ &title,+ text_x,+ text_y,+ marks_right.saturating_sub(text_x + inset),+ if dimmed {+ chrome.secondary_text.mul_alpha(0.7)+ } else {+ chrome.text+ },+ )?;+ }+ SidebarRowKind::Project(project_id) => {+ let Some(project) = view.projects.iter().find(|p| p.id == *project_id) else {+ return Ok(());+ };+ let fg = chrome.secondary_text;+ let (x, y) = folder_row(&mut layers, project.threads_collapsed, fg)?;+ self.paint_sidebar_project_icon(&mut layers, project, x, y, icon_size, fg)?;+ }+ SidebarRowKind::RefGroup(key) => {+ let Some(group) = view.ref_groups.iter().find(|group| group.key == *key) else {+ return Ok(());+ };+ let fg = if group.attached {+ chrome.secondary_text+ } else {+ chrome.secondary_text.mul_alpha(0.6)+ };+ let (x, y) = folder_row(&mut layers, group.collapsed, fg)?;+ let icon = if group.server_folder {+ SvgIcon::Server+ } else {+ SvgIcon::Link2+ };+ self.paint_sidebar_icon(&mut layers, icon, x, y, icon_size, fg)?;+ }+ }+ drop(layers);++ let lifted = if rests_selected { 1.0 } else { 1.0 - landed };+ self.paint_drag_ghost(+ &content,+ origin,+ grip,+ surface.mul_alpha(lifted),+ chrome.sidebar_row_active_border.mul_alpha(lifted),+ lifted,+ self.ui_f32(SIDEBAR_ROW_HIGHLIGHT_RADIUS),+ )+ }++ /// A folder's or a carried row's name: as a thread row's, it goes out+ /// when it is too long.#[allow(clippy::too_many_arguments)]fn paint_sidebar_name(&self,diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rsindex b82fb646..dd588ec1 100644--- a/wezterm-gui/src/workspace_threads.rs+++ b/wezterm-gui/src/workspace_threads.rs@@ -1697,15 +1697,24 @@ fn lock_store_following_settings() -> parking_lot::MutexGuard<'static, Workspacestore}-/// The reference list of a Space, in display order.-pub fn space_thread_refs(host_space_id: &str) -> Vec<String> {- THREAD_STORE- .lock()+/// A Space's references to threads of one project, in display order: the+/// group a dragged reference moves within. A server folder's own rows show+/// in that group too but are no references, and stay below these.+pub fn space_thread_refs_from(host_space_id: &str, project_id: &str) -> Vec<String> {+ let store = THREAD_STORE.lock();+ let refs = store.spaces.iter().find(|space| space.id == host_space_id)- .map(|space| space.thread_refs.clone())- .unwrap_or_default()+ .map(|space| space.thread_refs.as_slice())+ .unwrap_or(&[]);+ let Some(project) = store.projects.iter().find(|p| p.id == project_id) else {+ return Vec::new();+ };+ refs.iter()+ .filter(|id| project.threads.iter().any(|thread| &thread.id == *id))+ .cloned()+ .collect()}/// Remember which reference the user last opened from this Space, so the@@ -6751,7 +6760,10 @@ impl WorkspaceThreadStore {space.thread_refs.len() != before}- /// Reorder a reference before another (or to the end with `None`).+ /// Reorder a reference before another of its group, the references to+ /// the same project (or to the end of them with `None`). They trade the+ /// places they hold in the Space's list, so groups, which show in the+ /// order they first appear there, stay as they are./// Purely local: reference order never travels to any server.fn move_thread_ref_before(&mut self,@@ -6759,6 +6771,13 @@ impl WorkspaceThreadStore {thread_id: &str,before: Option<&str>,) -> bool {+ let Some(project) = self+ .projects+ .iter()+ .find(|project| project.threads.iter().any(|t| t.id == thread_id))+ else {+ return false;+ };let Some(space) = self.spaces.iter_mut()@@ -6766,30 +6785,44 @@ impl WorkspaceThreadStore {else {return false;};- let Some(from) = space.thread_refs.iter().position(|id| id == thread_id) else {+ let places: Vec<usize> = (0..space.thread_refs.len())+ .filter(|&place| {+ let id = &space.thread_refs[place];+ project.threads.iter().any(|thread| &thread.id == id)+ })+ .collect();+ let mut group: Vec<String> = places+ .iter()+ .map(|&place| space.thread_refs[place].clone())+ .collect();+ let Some(from) = group.iter().position(|id| id == thread_id) else {return false;};- // Mirror move_thread_before's guards: a drop on the row itself or on- // an anchor that has meanwhile vanished cancels the drag instead of- // teleporting the reference to the end of the list.+ // Mirror move_thread_before's guards: a drop on the row itself, on an+ // anchor that has meanwhile vanished or on one in another group+ // cancels the drag instead of teleporting the reference to the end+ // of the list.let to = match before {Some(anchor) => {if anchor == thread_id {return false;}- let Some(index) = space.thread_refs.iter().position(|id| id == anchor) else {+ let Some(index) = group.iter().position(|id| id == anchor) else {return false;};index}- None => space.thread_refs.len(),+ None => group.len(),};if to == from || to == from + 1 {return false;}- let moved = space.thread_refs.remove(from);+ let moved = group.remove(from);let to = if to > from { to - 1 } else { to };- space.thread_refs.insert(to, moved);+ group.insert(to, moved);+ for (place, id) in places.into_iter().zip(group) {+ space.thread_refs[place] = id;+ }true}@@ -12040,6 +12073,45 @@ mod tests {assert_eq!(space.thread_refs, vec![t1, t2]);}+ #[test]+ fn a_reference_moves_only_within_its_group() {+ let (mut store, coll, t1, t2) = store_with_collection();+ let mut other = default_project_for_space(DEFAULT_SPACE_ID);+ other.id = "project-other".to_string();+ let o1 = WorkspaceThread::new(other.id.clone(), "gamma".to_string(), None);+ let o2 = WorkspaceThread::new(other.id.clone(), "delta".to_string(), None);+ let (o1, o2) = {+ let ids = (o1.id.clone(), o2.id.clone());+ other.threads.extend([o1, o2]);+ ids+ };+ store.projects.push(other);+ for id in [&t1, &o1, &t2, &o2] {+ assert!(store.add_thread_ref(&coll, id));+ }+ let refs = |store: &WorkspaceThreadStore| {+ let space = store.spaces.iter().find(|s| s.id == coll).unwrap();+ space.thread_refs.clone()+ };++ // Over another group, nothing happens.+ assert!(!store.move_thread_ref_before(&coll, &o1, Some(&t1)));+ assert!(!store.move_thread_ref_before(&coll, &t2, Some(&o2)));+ assert_eq!(refs(&store), vec![t1.clone(), o1.clone(), t2.clone(), o2.clone()]);++ // The end is the end of its group, and the first row of the group+ // that goes there leaves the group where it first appears.+ assert!(store.move_thread_ref_before(&coll, &t1, None));+ assert_eq!(refs(&store), vec![t2.clone(), o1.clone(), t1.clone(), o2.clone()]);+ assert!(store.move_thread_ref_before(&coll, &o1, None));+ assert_eq!(refs(&store), vec![t2.clone(), o2.clone(), t1.clone(), o1.clone()]);+ assert!(store.move_thread_ref_before(&coll, &o1, Some(&o2)));+ assert_eq!(refs(&store), vec![t2.clone(), o1.clone(), t1.clone(), o2.clone()]);++ // The last of its group stays there.+ assert!(!store.move_thread_ref_before(&coll, &t1, None));+ }+#[test]fn sync_current_project_never_seeds_refs_only_spaces() {let (mut store, coll, t1, _) = store_with_collection();