diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 5a24766..336b2c5 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -72,7 +72,7 @@ use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; use gpui::{ AnyElement, App, Application, Bounds, ClickEvent, Context, Corners, CursorStyle, Div, DragMoveEvent, FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, - MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, + MouseExitEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div, point, prelude::*, px, relative, rgb, rgba, size, diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 878109f..6a8f8f8 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -3,6 +3,18 @@ use crate::*; +/// Whether a seam that just lost its drag owes a disk write -- exactly the +/// two persisted seams ([`Split::PERSISTED`]), same rule `drag_release`'s own +/// `matches!` already lived by. Pulled out to its own free function, taking +/// no `Context`, so [`Player::drag_left_window`]'s save-on-leave guard is +/// checkable without a `TestAppContext` this test binary has none of (see +/// `tests/media.rs`'s own note on the same limit) -- the wiring that calls it +/// from a live `MouseExitEvent` still cannot be, and is proven by driving +/// instead. +pub(crate) fn split_drag_owes_save(split: Option) -> bool { + matches!(split, Some(Split::Dock) | Some(Split::Bench)) +} + impl Player { /// Splits the clip under the playhead. Metadata only: the timeline->source /// mapping is unchanged, so nothing reseeks and no flag is touched. @@ -1479,6 +1491,32 @@ impl Player { /// where it sits (`Hitbox::is_hovered`, window.rs:788), so while a card is /// up the root is not hovered anywhere under it and hears none of this: the /// press set a value and the drag then froze on it. + /// The one event a release outside the window's own surface is + /// guaranteed to raise: Wayland (and X11) tell a client its pointer has + /// left, unconditionally, whether or not a button is down + /// (`wl_pointer::Event::Leave`, gpui's `platform/linux/wayland/client.rs`) + /// -- but a `Button::Released` that lands *after* that Leave is never + /// forwarded at all, because gpui only dispatches it to the window that + /// is still `mouse_focused_window`, and Leave just cleared that. So the + /// seam's own release handler (`drag_release`, bound to `on_mouse_up`) + /// can be skipped entirely by a drag that ends outside the frame, and + /// `drag_move`'s "next incidental motion" fallback above only fires once + /// the pointer comes back -- which a restart before that motion, or a + /// release the user never revisits, may never do. This is the one + /// dependable earlier moment: the size a `Split::Dock`/`Split::Bench` + /// drag is holding right now is exactly what a release beyond this + /// instant would have kept, since no further sample can arrive from + /// outside the surface, so it is saved here rather than left to chance. + /// Wired at the root via [`Player::mount_mouse_exit_listener`]'s + /// `window.on_mouse_event`, the low-level door `Interactivity`'s fluent + /// `on_mouse_*` builders do not expose for `MouseExitEvent`. + pub(crate) fn drag_left_window(&mut self, cx: &mut Context) { + if split_drag_owes_save(self.split_drag) { + save_stance_splits(&self.splits); + } + cx.notify(); + } + pub(crate) fn drag_move( &mut self, event: &MouseMoveEvent, @@ -1524,7 +1562,7 @@ impl Player { // the drag holds for the session and reverts on restart. _ => { self.split_drag = None; - if matches!(split, Split::Dock | Split::Bench) { + if split_drag_owes_save(Some(split)) { save_stance_splits(&self.splits); } } @@ -1662,7 +1700,7 @@ impl Player { // on the release that ends the gesture, the same small-file // round trip `ui::dock_stance`'s tab pick uses -- not on every // sample in between, which `drag_move` above never owed a write. - if matches!(split, Split::Dock | Split::Bench) { + if split_drag_owes_save(Some(split)) { save_stance_splits(&self.splits); } return; diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 499dcc7..37218e4 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1811,6 +1811,26 @@ fn a_saved_seam_survives_a_reload() { assert_eq!(loaded.get(Split::Bench), None); } +/// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends +/// with no further pointer event ever coming (`Player::drag_left_window`, +/// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary +/// cannot raise -- see `tests/media.rs`'s own note on the same limit, and +/// the harness drive `D2` in this session's report for the wiring itself). +/// What *is* checkable here without a window: exactly the two persisted +/// seams owe that save, the same set `Split::PERSISTED` already names, and a +/// drag that never started (`None`) owes nothing. +#[test] +fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { + use crate::{Split, player::timeline_edit::split_drag_owes_save}; + + assert!(split_drag_owes_save(Some(Split::Dock))); + assert!(split_drag_owes_save(Some(Split::Bench))); + assert!(!split_drag_owes_save(Some(Split::Library))); + assert!(!split_drag_owes_save(Some(Split::Inspector))); + assert!(!split_drag_owes_save(Some(Split::Timeline))); + assert!(!split_drag_owes_save(None)); +} + /// A missing file leaves every region at its default -- the silent fallback /// `load_stance_splits`'s doc comment promises. #[test] diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 75fea13..b918bba 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -596,6 +596,30 @@ fn dock(player: &Player, dock_w: f32, window_h: Pixels, cx: &mut Context .child(dock_stance::render(player, dock_w, window_h, cx)) } +/// A zero-size element whose only job is `window.on_mouse_event`'s door: +/// `Interactivity`'s fluent `on_mouse_*` builders (the ones `render`'s root +/// div uses for the drag itself, just below) have no `MouseExitEvent` case, +/// so this is the lowest rung that reaches it -- registered fresh every +/// frame, the same way `canvas()` is already used elsewhere in this crate +/// for paint-time access `div()` does not expose. See +/// [`Player::drag_left_window`] for why this event, and not a release, is +/// what a seam drag ending outside the window is saved on. +fn mouse_exit_listener(cx: &mut Context) -> impl IntoElement { + let player = cx.entity(); + canvas( + |_, _, _| (), + move |_, _, window, _| { + window.on_mouse_event(move |_: &MouseExitEvent, phase, _window, cx| { + if phase == gpui::DispatchPhase::Bubble { + player.update(cx, |this, cx| this.drag_left_window(cx)); + } + }); + }, + ) + .absolute() + .size(px(0.)) +} + /// The whole stance: spine, screen, time band, bench, ledger, dock, in the /// order DESIGN §5 draws them, over the same key handler the legacy tree /// uses (DESIGN §12 step 3): the darkroom draws its own regions but answers @@ -769,6 +793,7 @@ pub(crate) fn render( .size_full() .flex() .bg(rgb(DARK_CANVAS())) + .child(mouse_exit_listener(cx)) .child(spine(player, cx)) .child( div()