From 13b9bf4d46f8a0fd71014b24c2e704de8900c493 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 18 Nov 2026 01:52:13 +0100 Subject: [PATCH] A press whose pointer left the window still drags: window edges resize when pulled out (#2132) winit reports the pointer leaving the window while the button is held, and the press machine marked the open press abandoned, which also stopped its drag from starting. A window's resize grip lies inside the window and starts the OS resize on DragStart, so pulling an edge outward left the window before slop and the resize never started. Leaving the window now ends only the press's click. --- crates/behavior/src/press.rs | 29 +++++++++++++++++-- .../tests/it/runtime/window_move.rs | 23 +++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index ccd3b1694..ba4a4d7f3 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -471,6 +471,11 @@ struct Open { dragging: bool, /// Moved past slop on a target that senses no drag: the click is gone and nothing starts. abandoned: bool, + /// The pointer left the window ([`PointerEvent::Gone`]): the click is gone, but a target that senses a drag still + /// starts it from the moves that follow. The button is still down and the window keeps getting the pointer's moves + /// and release while it is outside, so a press near a window edge (a window's resize grip) that leaves the window + /// before it passes slop still drags. + left: bool, /// A pass reported the press: later passes within slop report `Held`, not `Down`. reported: bool, /// A pass reported the drag's start: later passes report `Drag`. @@ -489,7 +494,7 @@ impl Open { /// A release now is a click. fn clicks(&self) -> bool { - !self.dragging && !self.abandoned && self.sense.contains(Sense::CLICK) + !self.dragging && !self.abandoned && !self.left && self.sense.contains(Sense::CLICK) } } @@ -568,7 +573,7 @@ impl PressMachine { } PointerEvent::Gone => { if let Some(open) = &mut self.open { - open.abandoned = true; + open.left = true; } } PointerEvent::Pressed { button, pos: at, time, clicks } => { @@ -607,6 +612,7 @@ impl PressMachine { start: PressStart::new(at, button, time, clicks), dragging: false, abandoned: false, + left: false, reported: false, drag_reported: false, released_at: None, @@ -739,6 +745,25 @@ mod tests { assert!(machine.target().is_none(), "the release ends the press"); } + /// The pointer leaving the window (a press on a window's edge grip pulled outward) ends the press's click but not + /// its drag: the window keeps getting the held button's moves from outside, and they start the drag once past slop. + /// The resize from a window edge used to fail whenever the pointer left the window before it passed slop. + #[test] + fn a_press_whose_pointer_left_the_window_still_drags_but_no_longer_clicks() { + let moved = |x: f32| PointerEvent::Moved { at: pos2(x, 0.0), sample: None }; + let up = |x: f32| PointerEvent::released(pos2(x, 0.0)); + let gone = PointerEvent::Gone; + let out = [moved(SLOP / 2.0), gone]; + assert_eq!(phases(&[&[press(0.0, 1.0)], &out, &[moved(SLOP * 2.0)], &[moved(SLOP * 3.0)], &[up(SLOP * 3.0)]], Sense::DRAG), "D H S G R"); + assert_eq!(phases(&[&[press(0.0, 1.0)], &out, &[up(SLOP / 2.0)]], Sense::CLICK), "D H R", "a click target loses its click"); + assert_eq!( + phases(&[&[press(0.0, 1.0)], &out, &[moved(0.0)], &[up(0.0)]], Sense::CLICK | Sense::DRAG), + "D H H R", + "coming back does not bring the click back" + ); + assert_eq!(phases(&[&[press(0.0, 1.0)], &[moved(0.0)], &[up(0.0)]], Sense::CLICK), "D H R!", "a press that stays in still clicks"); + } + #[test] fn held_reports_the_pointer_of_its_pass_within_slop() { let mut machine = PressMachine::new(); diff --git a/crates/ui-contract/tests/it/runtime/window_move.rs b/crates/ui-contract/tests/it/runtime/window_move.rs index 8913ebddb..7fb2b94d9 100644 --- a/crates/ui-contract/tests/it/runtime/window_move.rs +++ b/crates/ui-contract/tests/it/runtime/window_move.rs @@ -122,6 +122,29 @@ fn root_drag(chrome: WindowChrome, at: Pos2, by: Vec2) -> (Vec, (drag(at, by, |events| rig.frame(&windows, events, vec![])), rig) } +/// A grip pulled out of the window resizes it: winit reports the pointer leaving the window (`PointerGone`) while the +/// button is held, before the press has passed slop, and the moves from outside still start the drag. The resize used +/// to start only when the pointer passed slop inside the window, so a quick outward pull on an edge did nothing. +#[trial] +fn a_grip_pulled_out_of_the_window_still_resizes_it() { + let windows = root(WindowChrome::Integrated); + let rig = Rig::new(Mount::window(Resize::GRIPS)); + for _ in 0..4 { + rig.frame(&windows, vec![], vec![]); + } + let edge = pos2(2.0, ROOT.y / 2.0); + let mut sent = rig.frame(&windows, vec![moved(edge)], vec![]); + sent.extend(rig.frame(&windows, vec![press(edge)], vec![])); + // The first move lands outside the window, within slop of the press; winit reports the leave with it. + sent.extend(rig.frame(&windows, vec![moved(edge - vec2(3.0, 0.0)), Event::PointerGone], vec![])); + for step in 2..=4 { + sent.extend(rig.frame(&windows, vec![moved(edge - vec2(5.0 * step as f32, 0.0))], vec![])); + } + sent.extend(rig.frame(&windows, vec![release(edge - vec2(20.0, 0.0))], vec![])); + sent.extend(rig.frame(&windows, vec![], vec![])); + assert_eq!(resizes(&sent), [ResizeDirection::West], "a pull out of the left edge resizes from the west: {sent:?}"); +} + #[trial] fn a_window_mounts_edges_resize_the_window_and_the_childs_press_keeps_its_click() { let (sent, _) = root_drag(WindowChrome::Integrated, pos2(1.0, ROOT.y / 2.0), vec2(20.0, 0.0));