From 5c84c026e2c235d0464ef39f13b8916a99a74442 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 12:01:20 -0800 Subject: [PATCH] Docking: a native window's move records its place once, when it ends While the app moved a floating window shown in an OS window, the dock area recorded the window's new place (Action::SetNative) in every pass of the drag. Each record was a workspace edit, which changed the workspace revision and rebuilt the dock's kept specs, titles and geometry in every frame of the drag. FloatingGroupOutput gains `moving`, kept in the group's memory from a move's Begin to its Commit or Cancel. DockArea skips native::reported while it is set; the Commit pass and the passes after it record the place where the window was let go. The new trial counts the placement records during a six-step drag of a palette the app moves: 6 without the change, 0 with it, and the release still records the final place. --- crates/ui-panels/src/docking/floating.rs | 18 ++++++++ crates/ui-panels/src/docking/native.rs | 2 +- crates/ui-patterns/src/patterns/dock/area.rs | 8 +++- crates/ui-patterns/tests/it/docking/native.rs | 44 +++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/crates/ui-panels/src/docking/floating.rs b/crates/ui-panels/src/docking/floating.rs index a8c3725788..81f1aafbb9 100644 --- a/crates/ui-panels/src/docking/floating.rs +++ b/crates/ui-panels/src/docking/floating.rs @@ -22,6 +22,7 @@ use crate::display::Icon; use crate::primitives::IconSpec; use crate::runtime::drag::OsFile; use crate::runtime::env::{Env, Label}; +use crate::runtime::memory::sub; use crate::runtime::overlay::CloseReason; use crate::runtime::windows::{ResizeEdge, WindowSpec}; use crate::sections::{HeaderAction, HeaderStrength, MenuRows, TitleRow}; @@ -213,8 +214,19 @@ pub struct FloatingGroupOutput { pub resize: Vec<(ResizeEdge, Rect, Id)>, /// Where `files` were dropped, in the group's layer space, when the drop session knew the pointer. pub files_at: Option, + /// A move of the group's window is still running after this pass: its `Begin` has been reported in `placed`, and + /// its `Commit` or `Cancel` has not. The passes between two steps report no `placed`. + pub moving: bool, } +/// Whether a move of the group's window is running: set by its `Begin` and `Update` steps, cleared by its `Commit` +/// or `Cancel` and by any step of a resize. +#[derive(Clone, Copy, Default)] +struct Gesture(bool); + +/// The memory slot of [`Gesture`] under the group's id. +const GESTURE: &str = "window_gesture"; + impl Outcome for FloatingGroupOutput { type Value = NoValue; @@ -619,6 +631,11 @@ impl Component for FloatingGroup<'_> { // A dock window's band double click collapses or expands its column, as a dock column's bar does. let collapsed = self.column.map(|column| column.collapsed.is_some()); let iconic = collapsed.filter(|_| self.chevron || self.toggled).map(|collapsed| !collapsed); + let gesture = &mut cx.core.memory.shown::(sub(cx.core.id, GESTURE)).0; + if let Some(change) = self.placed { + *gesture = change.kind == PlacementKind::Move && matches!(change.phase, GesturePhase::Begin | GesturePhase::Update); + } + let moving = *gesture; let output = FloatingGroupOutput { response: cx.response.clone(), placed: self.placed, @@ -632,6 +649,7 @@ impl Component for FloatingGroup<'_> { grip: cx.move_band(), resize: cx.resize_grips(), files_at: self.files_at, + moving, }; native::raise(&cx.core.ctx, &output, self.raise); native::fade(&cx.core.ctx, &output); diff --git a/crates/ui-panels/src/docking/native.rs b/crates/ui-panels/src/docking/native.rs index 2af9145811..f7b43d95a5 100644 --- a/crates/ui-panels/src/docking/native.rs +++ b/crates/ui-panels/src/docking/native.rs @@ -129,7 +129,7 @@ pub fn waited(ctx: &Context, opening: &Opening, output: &FloatingGroupOutput) { /// app window's is recorded, with the rect `kept` gives for the rect the OS shows the window at (outer top-left corner /// and inner size, in desktop points), so a collapsed window keeps its expanded rect /// ([`WindowColumn::kept`](super::WindowColumn::kept)). `None` while the model already holds what the OS reports, so a -/// window at rest costs no action. +/// window at rest costs no action. A caller skips it while the window's move runs ([`FloatingGroupOutput::moving`]). #[doc(hidden)] pub fn reported(ctx: &Context, window: &Floating

, viewport: ViewportId, kept: impl FnOnce(Rect) -> Rect) -> Option> { let panel = window.panels().next()?; diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 00bf938db0..803a4e9fb3 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -2316,8 +2316,12 @@ impl Pass<'_, P> { kept.edge = keeps.unwrap_or(kept.edge); self.report.actions.push(Action::move_floating_with_edge(anchor.clone(), rect, keeps)); } - let reported = native::reported(&ctx, window, viewport, |shown| kept.kept(shown, opening.rect, chrome, scene.rtl)); - self.report.actions.extend(reported); + // The OS window's place changes in every pass of a move; the workspace records it once, when the move + // ends. + if !output.moving { + let reported = native::reported(&ctx, window, viewport, |shown| kept.kept(shown, opening.rect, chrome, scene.rtl)); + self.report.actions.extend(reported); + } } } else if let Some(mut change) = output.placed.filter(|change| change.kind != PlacementKind::Move || change.phase == GesturePhase::Commit) { diff --git a/crates/ui-patterns/tests/it/docking/native.rs b/crates/ui-patterns/tests/it/docking/native.rs index 3e05cd593c..218856dba6 100644 --- a/crates/ui-patterns/tests/it/docking/native.rs +++ b/crates/ui-patterns/tests/it/docking/native.rs @@ -528,6 +528,50 @@ fn a_native_palette_the_app_moves_follows_the_system_pointer_not_a_stale_event() assert_eq!(window.min + ROW_AT.to_vec2(), desktop, "the window lands where the pointer let go"); } +/// While the app moves a native palette by its title row, the dock records no placement, though the OS window reports +/// a new place in every pass: the workspace takes no edit per pass of the drag, and records where the window was let +/// go once the move ends. +#[trial] +fn a_native_palette_records_its_place_once_its_move_ends_and_not_in_each_pass_of_it() { + let system = Arc::new(FakeSystem::new()); + let mut dock = NativeDock::on(Os::Linux, Arc::clone(&system)); + let mut window = FLOAT_AT; + let mut desktop = FLOAT_AT.min + ROW_AT.to_vec2(); + system.set_pointer(Some([desktop.x, desktop.y])); + let recorded = |actions: &[Action]| actions.iter().filter(|action| matches!(action, Action::SetNative { .. })).count(); + // Each frame, the OS puts the window where the app sent it, and the window reports that place in the next. + let frame = |dock: &mut NativeDock, window: &mut Rect, events: Vec| { + let (actions, commands) = dock.frame(events); + if let Some(to) = outer_positions(&commands).last() { + *window = Rect::from_min_size(*to, window.size()); + dock.windows.child_info(info(true, *window)); + } + actions + }; + for events in [vec![moved(ROW_AT)], vec![press(ROW_AT)]] { + frame(&mut dock, &mut window, events); + } + // Away from the main window, so the release docks nothing. + let step = Vec2::new(40.0, 25.0); + let mut during = 0; + for _ in 0..6 { + desktop += step; + system.set_pointer(Some([desktop.x, desktop.y])); + let event = moved(desktop - window.min.to_vec2()); + during += recorded(&frame(&mut dock, &mut window, vec![event])); + } + assert_ne!(window.min, FLOAT_AT.min, "the window follows the drag"); + assert_eq!(during, 0, "no placement is recorded while the move runs"); + let mut after = 0; + let let_go = release(desktop - window.min.to_vec2()); + for events in [vec![let_go], vec![], vec![]] { + after += recorded(&frame(&mut dock, &mut window, events)); + } + assert!(after >= 1, "the place the window was let go at is recorded once the move ends"); + let placed = dock.workspace.layout().floating[0].native.as_ref().and_then(Placement::position); + assert_eq!(placed.map(Pos2::from), Some(window.min), "the workspace holds where the window was let go"); +} + /// Where the OS moves windows and the app reads the system pointer and button meanwhile (macOS): the title row's press /// hands the move to the OS in its own pass, the system pointer over the main window's group marks it (Cmd keeps the /// drop floating), and the window docks when the system tells the button is up, not on the first pass after the