A seam released outside the window keeps its size
Browse files at this commit563ade6d2010e5826a58cd290c8a3d0e903112f6Parent: 415cb58- fix
- a seam released outside the window keeps its size
4 changed files +86 -3
- crates/app/src/main.rs +1 -1
- crates/app/src/player/timeline_edit.rs +40 -2
- crates/app/src/tests/layout.rs +20 -0
- crates/app/src/ui/stance.rs +25 -0
crates/app/src/main.rsmodified+1 -1
| @@ -72,7 +72,7 @@ use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; | |||
| 72 | use gpui::{ | 72 | use gpui::{ |
| 73 | AnyElement, App, Application, Bounds, ClickEvent, Context, Corners, CursorStyle, Div, | 73 | AnyElement, App, Application, Bounds, ClickEvent, Context, Corners, CursorStyle, Div, |
| 74 | DragMoveEvent, FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, | 74 | DragMoveEvent, FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, |
| 75 | - MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, | 75 | + MouseExitEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, |
| 76 | ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions, | 76 | ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions, |
| 77 | Window, WindowBounds, WindowOptions, canvas, div, point, prelude::*, px, relative, rgb, rgba, | 77 | Window, WindowBounds, WindowOptions, canvas, div, point, prelude::*, px, relative, rgb, rgba, |
| 78 | size, | 78 | size, |
crates/app/src/player/timeline_edit.rsmodified+40 -2
| @@ -3,6 +3,18 @@ | |||
| 3 | 3 | ||
| 4 | use crate::*; | 4 | use crate::*; |
| 5 | 5 | ||
| 6 | +/// Whether a seam that just lost its drag owes a disk write -- exactly the | ||
| 7 | +/// two persisted seams ([`Split::PERSISTED`]), same rule `drag_release`'s own | ||
| 8 | +/// `matches!` already lived by. Pulled out to its own free function, taking | ||
| 9 | +/// no `Context`, so [`Player::drag_left_window`]'s save-on-leave guard is | ||
| 10 | +/// checkable without a `TestAppContext` this test binary has none of (see | ||
| 11 | +/// `tests/media.rs`'s own note on the same limit) -- the wiring that calls it | ||
| 12 | +/// from a live `MouseExitEvent` still cannot be, and is proven by driving | ||
| 13 | +/// instead. | ||
| 14 | +pub(crate) fn split_drag_owes_save(split: Option<Split>) -> bool { | ||
| 15 | + matches!(split, Some(Split::Dock) | Some(Split::Bench)) | ||
| 16 | +} | ||
| 17 | + | ||
| 6 | impl Player { | 18 | impl Player { |
| 7 | /// Splits the clip under the playhead. Metadata only: the timeline->source | 19 | /// Splits the clip under the playhead. Metadata only: the timeline->source |
| 8 | /// mapping is unchanged, so nothing reseeks and no flag is touched. | 20 | /// mapping is unchanged, so nothing reseeks and no flag is touched. |
| @@ -1479,6 +1491,32 @@ impl Player { | |||
| 1479 | /// where it sits (`Hitbox::is_hovered`, window.rs:788), so while a card is | 1491 | /// where it sits (`Hitbox::is_hovered`, window.rs:788), so while a card is |
| 1480 | /// up the root is not hovered anywhere under it and hears none of this: the | 1492 | /// up the root is not hovered anywhere under it and hears none of this: the |
| 1481 | /// press set a value and the drag then froze on it. | 1493 | /// press set a value and the drag then froze on it. |
| 1494 | + /// The one event a release outside the window's own surface is | ||
| 1495 | + /// guaranteed to raise: Wayland (and X11) tell a client its pointer has | ||
| 1496 | + /// left, unconditionally, whether or not a button is down | ||
| 1497 | + /// (`wl_pointer::Event::Leave`, gpui's `platform/linux/wayland/client.rs`) | ||
| 1498 | + /// -- but a `Button::Released` that lands *after* that Leave is never | ||
| 1499 | + /// forwarded at all, because gpui only dispatches it to the window that | ||
| 1500 | + /// is still `mouse_focused_window`, and Leave just cleared that. So the | ||
| 1501 | + /// seam's own release handler (`drag_release`, bound to `on_mouse_up`) | ||
| 1502 | + /// can be skipped entirely by a drag that ends outside the frame, and | ||
| 1503 | + /// `drag_move`'s "next incidental motion" fallback above only fires once | ||
| 1504 | + /// the pointer comes back -- which a restart before that motion, or a | ||
| 1505 | + /// release the user never revisits, may never do. This is the one | ||
| 1506 | + /// dependable earlier moment: the size a `Split::Dock`/`Split::Bench` | ||
| 1507 | + /// drag is holding right now is exactly what a release beyond this | ||
| 1508 | + /// instant would have kept, since no further sample can arrive from | ||
| 1509 | + /// outside the surface, so it is saved here rather than left to chance. | ||
| 1510 | + /// Wired at the root via [`Player::mount_mouse_exit_listener`]'s | ||
| 1511 | + /// `window.on_mouse_event`, the low-level door `Interactivity`'s fluent | ||
| 1512 | + /// `on_mouse_*` builders do not expose for `MouseExitEvent`. | ||
| 1513 | + pub(crate) fn drag_left_window(&mut self, cx: &mut Context<Self>) { | ||
| 1514 | + if split_drag_owes_save(self.split_drag) { | ||
| 1515 | + save_stance_splits(&self.splits); | ||
| 1516 | + } | ||
| 1517 | + cx.notify(); | ||
| 1518 | + } | ||
| 1519 | + | ||
| 1482 | pub(crate) fn drag_move( | 1520 | pub(crate) fn drag_move( |
| 1483 | &mut self, | 1521 | &mut self, |
| 1484 | event: &MouseMoveEvent, | 1522 | event: &MouseMoveEvent, |
| @@ -1524,7 +1562,7 @@ impl Player { | |||
| 1524 | // the drag holds for the session and reverts on restart. | 1562 | // the drag holds for the session and reverts on restart. |
| 1525 | _ => { | 1563 | _ => { |
| 1526 | self.split_drag = None; | 1564 | self.split_drag = None; |
| 1527 | - if matches!(split, Split::Dock | Split::Bench) { | 1565 | + if split_drag_owes_save(Some(split)) { |
| 1528 | save_stance_splits(&self.splits); | 1566 | save_stance_splits(&self.splits); |
| 1529 | } | 1567 | } |
| 1530 | } | 1568 | } |
| @@ -1662,7 +1700,7 @@ impl Player { | |||
| 1662 | // on the release that ends the gesture, the same small-file | 1700 | // on the release that ends the gesture, the same small-file |
| 1663 | // round trip `ui::dock_stance`'s tab pick uses -- not on every | 1701 | // round trip `ui::dock_stance`'s tab pick uses -- not on every |
| 1664 | // sample in between, which `drag_move` above never owed a write. | 1702 | // sample in between, which `drag_move` above never owed a write. |
| 1665 | - if matches!(split, Split::Dock | Split::Bench) { | 1703 | + if split_drag_owes_save(Some(split)) { |
| 1666 | save_stance_splits(&self.splits); | 1704 | save_stance_splits(&self.splits); |
| 1667 | } | 1705 | } |
| 1668 | return; | 1706 | return; |
crates/app/src/tests/layout.rsmodified+20 -0
| @@ -1811,6 +1811,26 @@ fn a_saved_seam_survives_a_reload() { | |||
| 1811 | assert_eq!(loaded.get(Split::Bench), None); | 1811 | assert_eq!(loaded.get(Split::Bench), None); |
| 1812 | } | 1812 | } |
| 1813 | 1813 | ||
| 1814 | +/// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends | ||
| 1815 | +/// with no further pointer event ever coming (`Player::drag_left_window`, | ||
| 1816 | +/// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary | ||
| 1817 | +/// cannot raise -- see `tests/media.rs`'s own note on the same limit, and | ||
| 1818 | +/// the harness drive `D2` in this session's report for the wiring itself). | ||
| 1819 | +/// What *is* checkable here without a window: exactly the two persisted | ||
| 1820 | +/// seams owe that save, the same set `Split::PERSISTED` already names, and a | ||
| 1821 | +/// drag that never started (`None`) owes nothing. | ||
| 1822 | +#[test] | ||
| 1823 | +fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { | ||
| 1824 | + use crate::{Split, player::timeline_edit::split_drag_owes_save}; | ||
| 1825 | + | ||
| 1826 | + assert!(split_drag_owes_save(Some(Split::Dock))); | ||
| 1827 | + assert!(split_drag_owes_save(Some(Split::Bench))); | ||
| 1828 | + assert!(!split_drag_owes_save(Some(Split::Library))); | ||
| 1829 | + assert!(!split_drag_owes_save(Some(Split::Inspector))); | ||
| 1830 | + assert!(!split_drag_owes_save(Some(Split::Timeline))); | ||
| 1831 | + assert!(!split_drag_owes_save(None)); | ||
| 1832 | +} | ||
| 1833 | + | ||
| 1814 | /// A missing file leaves every region at its default -- the silent fallback | 1834 | /// A missing file leaves every region at its default -- the silent fallback |
| 1815 | /// `load_stance_splits`'s doc comment promises. | 1835 | /// `load_stance_splits`'s doc comment promises. |
| 1816 | #[test] | 1836 | #[test] |
crates/app/src/ui/stance.rsmodified+25 -0
| @@ -596,6 +596,30 @@ fn dock(player: &Player, dock_w: f32, window_h: Pixels, cx: &mut Context<Player> | |||
| 596 | .child(dock_stance::render(player, dock_w, window_h, cx)) | 596 | .child(dock_stance::render(player, dock_w, window_h, cx)) |
| 597 | } | 597 | } |
| 598 | 598 | ||
| 599 | +/// A zero-size element whose only job is `window.on_mouse_event`'s door: | ||
| 600 | +/// `Interactivity`'s fluent `on_mouse_*` builders (the ones `render`'s root | ||
| 601 | +/// div uses for the drag itself, just below) have no `MouseExitEvent` case, | ||
| 602 | +/// so this is the lowest rung that reaches it -- registered fresh every | ||
| 603 | +/// frame, the same way `canvas()` is already used elsewhere in this crate | ||
| 604 | +/// for paint-time access `div()` does not expose. See | ||
| 605 | +/// [`Player::drag_left_window`] for why this event, and not a release, is | ||
| 606 | +/// what a seam drag ending outside the window is saved on. | ||
| 607 | +fn mouse_exit_listener(cx: &mut Context<Player>) -> impl IntoElement { | ||
| 608 | + let player = cx.entity(); | ||
| 609 | + canvas( | ||
| 610 | + |_, _, _| (), | ||
| 611 | + move |_, _, window, _| { | ||
| 612 | + window.on_mouse_event(move |_: &MouseExitEvent, phase, _window, cx| { | ||
| 613 | + if phase == gpui::DispatchPhase::Bubble { | ||
| 614 | + player.update(cx, |this, cx| this.drag_left_window(cx)); | ||
| 615 | + } | ||
| 616 | + }); | ||
| 617 | + }, | ||
| 618 | + ) | ||
| 619 | + .absolute() | ||
| 620 | + .size(px(0.)) | ||
| 621 | +} | ||
| 622 | + | ||
| 599 | /// The whole stance: spine, screen, time band, bench, ledger, dock, in the | 623 | /// The whole stance: spine, screen, time band, bench, ledger, dock, in the |
| 600 | /// order DESIGN §5 draws them, over the same key handler the legacy tree | 624 | /// order DESIGN §5 draws them, over the same key handler the legacy tree |
| 601 | /// uses (DESIGN §12 step 3): the darkroom draws its own regions but answers | 625 | /// uses (DESIGN §12 step 3): the darkroom draws its own regions but answers |
| @@ -769,6 +793,7 @@ pub(crate) fn render( | |||
| 769 | .size_full() | 793 | .size_full() |
| 770 | .flex() | 794 | .flex() |
| 771 | .bg(rgb(DARK_CANVAS())) | 795 | .bg(rgb(DARK_CANVAS())) |
| 796 | + .child(mouse_exit_listener(cx)) | ||
| 772 | .child(spine(player, cx)) | 797 | .child(spine(player, cx)) |
| 773 | .child( | 798 | .child( |
| 774 | div() | 799 | div() |