From 65d0e46e711947629fdea355a713d370dd604567 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 23:54:20 +0100 Subject: [PATCH 1/4] Two trials for a layer shown in a popup window A layer opened in a palette window shows in a popup window of its own, so its body runs in that window's pass while its host runs in the opener's. With the layer's memory kept across passes, a timed dismissal counts from the pass it appeared, which the opener's pass records too: the trial gives a menu a quarter-second timeout and requires it to close with CloseReason::Timeout with no input at all, its caller's binding to follow and its popup window to go with it. A menu a context opener opens in such a popup window hangs at the new pointer when its opener is right-clicked again, as an in-window menu does: the trial right-clicks the same opener at another point above the first and requires the menu's window to have moved by the pointer's move. Both trials use the file's existing palette helpers and one container, `Sheet`, which mounts a trial's props as its layer, records the closes it is given and takes the caller's open state when it has one. --- .../ui-contract/tests/it/runtime/windows.rs | 157 +++++++++++++++++- 1 file changed, 152 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/tests/it/runtime/windows.rs b/crates/ui-contract/tests/it/runtime/windows.rs index 25479c33f7..c4df2c63e6 100644 --- a/crates/ui-contract/tests/it/runtime/windows.rs +++ b/crates/ui-contract/tests/it/runtime/windows.rs @@ -3,21 +3,26 @@ //! container (in a window of its own, or in a full-screen or Wayland-maximized main window), the size of a //! content-sized window, the app id of child windows, a palette's level under a modal and its visibility while the main //! window is minimized, injected keys across a focus loss, non-finite injected points, a repeated injected press, the -//! window that has the keys, a wheel with no known pointer, what a layer in a popup window keeps while it is open, the -//! placement of a minimized window, the root frame decided again, a held close, `act`, and a hosted window's -//! Control-click and window-input policy. +//! window that has the keys, a wheel with no known pointer, what a layer in a popup window keeps while it is open, that +//! it closes after its timeout and where a second right-click on its opener hangs it, the placement of a minimized +//! window, the root frame decided again, a held close, `act`, and a hosted window's Control-click and window-input +//! policy. use craft_behavior::{Cursor, CursorIcon, PointerButton, Sense}; use craft_host::target::{Backend, Caps, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind}; use craft_keymap::{Key, Mods}; -use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Scroll, Show as _, ShowContainer as _}; +use craft_ui::contract::{ + Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Dismiss, Mount, Overlay, Props as _, Role, Scroll, Show as _, + ShowContainer as _, Trigger, +}; use craft_ui::runtime::InstallSpec; use craft_ui::runtime::focus::FocusPolicy; use craft_ui::runtime::overlay::CloseReason; use craft_ui::runtime::windows::{WindowHost, WindowLevel, WindowSpec}; use craft_ui::style::StyleCx; use craft_ui::testing::input::key_press; -use craft_ui::testing::pointer::{moved, press, release, wheel}; +use craft_ui::testing::layout::Block; +use craft_ui::testing::pointer::{moved, press, release, secondary, wheel}; use craft_ui::testing::windows::{FakeSystem, NoWindows}; use craft_ui::testing::{Fixture, trial}; use craft_ui_test_kit::contract::{PlainStyle, Probe, Seen}; @@ -501,6 +506,148 @@ fn a_layer_in_a_popup_window_keeps_its_scroll_until_it_closes() { assert!((top.get() - start).abs() < 0.5, "opened again, it starts at the top: {} after {scrolled}, {start} unscrolled", top.get()); } +/// A layer mounted from the trial's `props`, with the caller's open state when it has one, adding how it closed to +/// `closed`. +#[derive(craft_ui::contract::Component)] +#[component(container)] +struct Sheet<'a> { + #[common] + common: Common, + #[container] + props: ContainerProps, + open: Option>, + closed: &'a RefCell>, +} + +impl Component for Sheet<'_> { + const ROLE: Role = Role::GROUP; + type Style = PlainStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: SheetStyleKey) -> PlainStyle { + PlainStyle::min(Vec2::new(120.0, 60.0)) + } + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + +impl Container for Sheet<'_> { + fn open(&mut self) -> Option> { + self.open.as_mut().map(Bind::reborrow) + } + + fn closed(&mut self, why: CloseReason) { + self.closed.borrow_mut().push(why); + } +} + +/// A layer shown in a popup window of a palette window closes after its timeout with no input at all: the timeout +/// counts from the pass the layer appeared, and its body runs in the popup's pass, which stamps its appearance in that +/// window's record, while its host decides the window in the palette's pass, where the opener's record never held it. +#[trial] +fn a_layer_in_a_popup_window_closes_after_its_timeout() { + let windows = on_x11(); + windows.root_info(focus(true)); + windows.child_info(focus(true)); + // A menu that closes by itself a quarter second after it appears: fifteen frames at the kit's sixty a second. + const TIMEOUT: f32 = 0.25; + let overlay = Overlay::menu().dismiss(Dismiss::new().timeout(Some(TIMEOUT))); + let (open, closed) = (Cell::new(false), RefCell::new(Vec::new())); + let frame = || { + let mut is_open = open.get(); + let out = windows.frame(vec![], vec![], |ui| { + Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| { + let props = ContainerProps::new().mount(Mount::Layer(overlay.clone())); + Sheet { common: Common::new(), props, open: Some(Bind::bound(&mut is_open)), closed: &closed }.id_salt("sheet").show(ui, |_, _| {}); + }); + }); + open.set(is_open); + out + }; + let palette = builder_titled(&frame(), "tool").0; + open.set(true); + let mut out = frame(); + for _ in 0..2 { + out = frame(); + } + assert!(popup_window(&out, palette).is_some(), "the layer opened in the palette shows in a popup window"); + assert!(open.get(), "the layer is open early in its timeout: {:?}", closed.borrow()); + assert_eq!(*closed.borrow(), [], "early in its timeout, nothing closed the layer"); + // Well past a quarter second of frames, with no input at all. + for _ in 0..30 { + out = frame(); + } + assert!(!open.get(), "the layer closed after its timeout with no input: {:?}", closed.borrow()); + assert_eq!(*closed.borrow(), [CloseReason::Timeout], "the timeout closed it, and no other rule did"); + assert_eq!(popup_window(&out, palette), None, "its popup window closed with it"); +} + +/// A second right-click on a context opener hangs its menu at the new pointer while the menu stays open, also when the +/// menu shows in a popup window of a palette window: the pointer the layer opened at goes when its opener fires again. +#[trial] +fn a_second_right_click_hangs_a_menu_in_a_popup_window_at_the_new_pointer() { + let windows = on_x11(); + windows.root_info(focus(true)); + windows.child_info(focus(true)); + let (opener_at, closed) = (RefCell::new(Seen::default()), RefCell::new(Vec::new())); + let frame = |events: Vec| { + windows.frame(vec![], events, |ui| { + Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| { + let opener = Probe::new(&opener_at).size(Vec2::new(240.0, 140.0)).sense(Sense::CLICK).id_salt("opener").show(ui); + let props = ContainerProps::new().mount(Mount::Layer(Overlay::menu().opened_by(&opener, Trigger::Context))); + Sheet { common: Common::new(), props, open: None, closed: &closed }.id_salt("rows").show(ui, |ui, _| { + for _ in 0..3 { + Block::new(Vec2::new(80.0, 24.0)).show(ui); + } + }); + }); + }) + }; + // Where the menu shows: the window of its own that the frame opened besides the palette's. + let menu_window = |out: &Out| -> Rect { + let palette = builder_titled(out, "tool").0; + let popup = popup_window(out, palette).expect("the menu shows in a popup window of the palette's"); + let facts = windows.facts(popup); + facts.outer_rect.or(facts.inner_rect).expect("the menu's window is placed") + }; + for _ in 0..2 { + frame(vec![]); + } + let at = opener_at.borrow().rect; + assert!(at.height() > 0.0, "the opener showed: {at:?}"); + // Two points well inside the opener, the second above the first where the menu hanging below it does not reach: + // the palette's body lies within its window's points, and either way both right-clicks land on the opener. + let (first, second) = (at.center() + Vec2::new(0.0, 20.0), at.center() - Vec2::new(30.0, 20.0)); + // A right-click on the opener opens the menu at that point. + frame(vec![moved(first)]); + frame(vec![secondary(first, true)]); + let mut out = frame(vec![secondary(first, false)]); + for _ in 0..2 { + out = frame(vec![]); + } + assert!(closed.borrow().is_empty(), "the right-click opened the menu and closed nothing: {:?}", closed.borrow()); + let opened = menu_window(&out); + // A second right-click on the same opener, while the menu is open, hangs the menu at the new pointer. + frame(vec![moved(second)]); + frame(vec![secondary(second, true)]); + let mut out = frame(vec![secondary(second, false)]); + for _ in 0..2 { + out = frame(vec![]); + } + // The pointer the layer opened at goes when its opener fires again, so the menu hangs where the pointer is now. No + // rule but an outside press closed it on the way. + assert!(closed.borrow().iter().all(|why| *why == CloseReason::Outside), "only an outside press closed the menu: {:?}", closed.borrow()); + let after = menu_window(&out); + let shift = after.min - opened.min; + let pointer = second - first; + assert!( + (shift - pointer).length() < 1.0, + "the menu hangs where the pointer is now: it stood at {opened:?}, stands at {after:?}, and the pointer moved {pointer:?}" + ); +} + /// A popup that a press in another window of the app opened stays open, also when its opener runs a second pass of the /// frame it opens in, and a later press there closes it. #[trial] From 991a18321be99369bb5bdd10586800a9d2aa34bc Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 23:56:00 +0100 Subject: [PATCH 2/4] The second trial checks the pointer move before the second right-click A menu shown in a popup window keeps the place its context opener hung it at while the pointer moves over that opener: the pointer the layer opened at is remembered, not taken again every pass. The trial now moves the pointer to the point it right-clicks next and requires the menu's window to stand where the first right-click put it, then right-clicks and requires the move. Without the layer's memory kept across passes, the popup's host took the pointer again in every pass, so the menu followed it there before any press. --- crates/ui-contract/tests/it/runtime/windows.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ui-contract/tests/it/runtime/windows.rs b/crates/ui-contract/tests/it/runtime/windows.rs index c4df2c63e6..5dd64a9f42 100644 --- a/crates/ui-contract/tests/it/runtime/windows.rs +++ b/crates/ui-contract/tests/it/runtime/windows.rs @@ -629,8 +629,14 @@ fn a_second_right_click_hangs_a_menu_in_a_popup_window_at_the_new_pointer() { } assert!(closed.borrow().is_empty(), "the right-click opened the menu and closed nothing: {:?}", closed.borrow()); let opened = menu_window(&out); + // The pointer moves over the opener with no press: a menu that shows keeps the place its opener hung it at. + let out = frame(vec![moved(second)]); + let stayed = menu_window(&out); + assert!( + (stayed.min - opened.min).length() < 1.0, + "the menu stays where it opened while the pointer moves over its opener: it stood at {opened:?}, stands at {stayed:?}" + ); // A second right-click on the same opener, while the menu is open, hangs the menu at the new pointer. - frame(vec![moved(second)]); frame(vec![secondary(second, true)]); let mut out = frame(vec![secondary(second, false)]); for _ in 0..2 { From 2c272c2a8d87eb8df12ad5c75cea2286cf25c11c Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Thu, 26 Nov 2026 00:01:09 +0100 Subject: [PATCH 3/4] Popup-window trials: import Dismiss from contract::overlay --- crates/ui-contract/tests/it/runtime/windows.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/tests/it/runtime/windows.rs b/crates/ui-contract/tests/it/runtime/windows.rs index 5dd64a9f42..aa340fa480 100644 --- a/crates/ui-contract/tests/it/runtime/windows.rs +++ b/crates/ui-contract/tests/it/runtime/windows.rs @@ -11,9 +11,9 @@ use craft_behavior::{Cursor, CursorIcon, PointerButton, Sense}; use craft_host::target::{Backend, Caps, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind}; use craft_keymap::{Key, Mods}; +use craft_ui::contract::overlay::Dismiss; use craft_ui::contract::{ - Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Dismiss, Mount, Overlay, Props as _, Role, Scroll, Show as _, - ShowContainer as _, Trigger, + Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Scroll, Show as _, ShowContainer as _, Trigger, }; use craft_ui::runtime::InstallSpec; use craft_ui::runtime::focus::FocusPolicy; From e61e8dab7523d8eb241b6bba6a64ca7734557c3f Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Thu, 26 Nov 2026 00:02:09 +0100 Subject: [PATCH 4/4] Popup-window trials: drop the second right-click trial, which main's native palette trial covers --- .../ui-contract/tests/it/runtime/windows.rs | 80 +------------------ 1 file changed, 4 insertions(+), 76 deletions(-) diff --git a/crates/ui-contract/tests/it/runtime/windows.rs b/crates/ui-contract/tests/it/runtime/windows.rs index aa340fa480..d2fd339f50 100644 --- a/crates/ui-contract/tests/it/runtime/windows.rs +++ b/crates/ui-contract/tests/it/runtime/windows.rs @@ -4,16 +4,15 @@ //! content-sized window, the app id of child windows, a palette's level under a modal and its visibility while the main //! window is minimized, injected keys across a focus loss, non-finite injected points, a repeated injected press, the //! window that has the keys, a wheel with no known pointer, what a layer in a popup window keeps while it is open, that -//! it closes after its timeout and where a second right-click on its opener hangs it, the placement of a minimized -//! window, the root frame decided again, a held close, `act`, and a hosted window's Control-click and window-input -//! policy. +//! it closes after its timeout, the placement of a minimized window, the root frame decided again, a held close, `act`, +//! and a hosted window's Control-click and window-input policy. use craft_behavior::{Cursor, CursorIcon, PointerButton, Sense}; use craft_host::target::{Backend, Caps, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind}; use craft_keymap::{Key, Mods}; use craft_ui::contract::overlay::Dismiss; use craft_ui::contract::{ - Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Scroll, Show as _, ShowContainer as _, Trigger, + Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Scroll, Show as _, ShowContainer as _, }; use craft_ui::runtime::InstallSpec; use craft_ui::runtime::focus::FocusPolicy; @@ -21,8 +20,7 @@ use craft_ui::runtime::overlay::CloseReason; use craft_ui::runtime::windows::{WindowHost, WindowLevel, WindowSpec}; use craft_ui::style::StyleCx; use craft_ui::testing::input::key_press; -use craft_ui::testing::layout::Block; -use craft_ui::testing::pointer::{moved, press, release, secondary, wheel}; +use craft_ui::testing::pointer::{moved, press, release, wheel}; use craft_ui::testing::windows::{FakeSystem, NoWindows}; use craft_ui::testing::{Fixture, trial}; use craft_ui_test_kit::contract::{PlainStyle, Probe, Seen}; @@ -584,76 +582,6 @@ fn a_layer_in_a_popup_window_closes_after_its_timeout() { assert_eq!(popup_window(&out, palette), None, "its popup window closed with it"); } -/// A second right-click on a context opener hangs its menu at the new pointer while the menu stays open, also when the -/// menu shows in a popup window of a palette window: the pointer the layer opened at goes when its opener fires again. -#[trial] -fn a_second_right_click_hangs_a_menu_in_a_popup_window_at_the_new_pointer() { - let windows = on_x11(); - windows.root_info(focus(true)); - windows.child_info(focus(true)); - let (opener_at, closed) = (RefCell::new(Seen::default()), RefCell::new(Vec::new())); - let frame = |events: Vec| { - windows.frame(vec![], events, |ui| { - Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| { - let opener = Probe::new(&opener_at).size(Vec2::new(240.0, 140.0)).sense(Sense::CLICK).id_salt("opener").show(ui); - let props = ContainerProps::new().mount(Mount::Layer(Overlay::menu().opened_by(&opener, Trigger::Context))); - Sheet { common: Common::new(), props, open: None, closed: &closed }.id_salt("rows").show(ui, |ui, _| { - for _ in 0..3 { - Block::new(Vec2::new(80.0, 24.0)).show(ui); - } - }); - }); - }) - }; - // Where the menu shows: the window of its own that the frame opened besides the palette's. - let menu_window = |out: &Out| -> Rect { - let palette = builder_titled(out, "tool").0; - let popup = popup_window(out, palette).expect("the menu shows in a popup window of the palette's"); - let facts = windows.facts(popup); - facts.outer_rect.or(facts.inner_rect).expect("the menu's window is placed") - }; - for _ in 0..2 { - frame(vec![]); - } - let at = opener_at.borrow().rect; - assert!(at.height() > 0.0, "the opener showed: {at:?}"); - // Two points well inside the opener, the second above the first where the menu hanging below it does not reach: - // the palette's body lies within its window's points, and either way both right-clicks land on the opener. - let (first, second) = (at.center() + Vec2::new(0.0, 20.0), at.center() - Vec2::new(30.0, 20.0)); - // A right-click on the opener opens the menu at that point. - frame(vec![moved(first)]); - frame(vec![secondary(first, true)]); - let mut out = frame(vec![secondary(first, false)]); - for _ in 0..2 { - out = frame(vec![]); - } - assert!(closed.borrow().is_empty(), "the right-click opened the menu and closed nothing: {:?}", closed.borrow()); - let opened = menu_window(&out); - // The pointer moves over the opener with no press: a menu that shows keeps the place its opener hung it at. - let out = frame(vec![moved(second)]); - let stayed = menu_window(&out); - assert!( - (stayed.min - opened.min).length() < 1.0, - "the menu stays where it opened while the pointer moves over its opener: it stood at {opened:?}, stands at {stayed:?}" - ); - // A second right-click on the same opener, while the menu is open, hangs the menu at the new pointer. - frame(vec![secondary(second, true)]); - let mut out = frame(vec![secondary(second, false)]); - for _ in 0..2 { - out = frame(vec![]); - } - // The pointer the layer opened at goes when its opener fires again, so the menu hangs where the pointer is now. No - // rule but an outside press closed it on the way. - assert!(closed.borrow().iter().all(|why| *why == CloseReason::Outside), "only an outside press closed the menu: {:?}", closed.borrow()); - let after = menu_window(&out); - let shift = after.min - opened.min; - let pointer = second - first; - assert!( - (shift - pointer).length() < 1.0, - "the menu hangs where the pointer is now: it stood at {opened:?}, stands at {after:?}, and the pointer moved {pointer:?}" - ); -} - /// A popup that a press in another window of the app opened stays open, also when its opener runs a second pass of the /// frame it opens in, and a later press there closes it. #[trial]