From 6172b742bf21237b4dc2b7d3a71b8b75b16ff6fd Mon Sep 17 00:00:00 2001 From: Cyb3rDudu Date: Wed, 25 Nov 2026 14:10:02 +0700 Subject: [PATCH 1/3] fix(ui): act on the title bar's Close caption click The app bar discarded the title bar's output, so a click on the caption Close button was reported and never acted on: on a desktop that shows the app's own frame (GNOME/Wayland), the button did nothing. Send the viewport Close command when the bar reports it, as the page band's Close does. The unsaved-changes prompt runs from the close request the command raises, as an OS close does. --- crates/ui-egui/src/chrome.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 52d92c7df6..8d32f185c0 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -139,11 +139,17 @@ pub fn app_bar(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut VectorcraftApp) { let end = |ui: &mut Ui, _: &mut BodyCx<'_>| trailing(ui, &mut app.borrow_mut()); // A nightly's window and Dock entry carry its own name, so they never read as the stable app's. let title = if crate::os_window::stable_services_allowed() { tl!("VectorCraft") } else { crate::os_window::name() }; - let _ = if titled { + let out = if titled { TitleBar::new().surface(SurfaceKind::Background).show_titled(ui, Title::new(title), start, end) } else { TitleBar::new().surface(SurfaceKind::Background).show_fitted(ui, start, end) }; + // The title bar reports a caption Close click in its output and never acts on it; acting here + // keeps the click from being dropped (the unsaved-changes prompt runs from the close request + // the command raises, as an OS close does). + if out.close_requested { + ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close); + } } /// The OS window title: the active document's name suffixed with the app name (a `*` prefix From a7e20825daeb6d2fa6f2bb06a92aff75357d5f0b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 09:38:16 -0800 Subject: [PATCH 2/3] Title bar: send the caption Close through the window host The close the Close caption button asks for goes through WindowHost::act with WindowAction::Close, the sender the title bar uses for Minimize and Maximize, in place of a raw ViewportCommand::Close. --- crates/ui-egui/src/chrome.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 8d32f185c0..fff73831e2 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -10,7 +10,7 @@ use craft::ui::contract::{Bind, BodyCx, Props, Show, ShowContainer}; use craft::ui::display::Picture; use craft::ui::layout_components::Row; use craft::ui::primitives::IconSpec; -use craft::ui::runtime::windows::WindowHost; +use craft::ui::runtime::windows::{WindowAction, WindowHost}; use craft::ui::shell::{Frame, Title, TitleBar}; use craft::ui::style::{SurfaceKind, Variant}; use egui::Ui; @@ -144,11 +144,12 @@ pub fn app_bar(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut VectorcraftApp) { } else { TitleBar::new().surface(SurfaceKind::Background).show_fitted(ui, start, end) }; - // The title bar reports a caption Close click in its output and never acts on it; acting here - // keeps the click from being dropped (the unsaved-changes prompt runs from the close request - // the command raises, as an OS close does). + // The title bar reports a caption Close click in its output and never acts on it. The window host sends the close, + // and a close of the main window goes through the app's close guard, so the unsaved-changes prompt runs as it does + // for an OS close. if out.close_requested { - ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close); + let ctx = ui.ctx().clone(); + WindowHost::of(&ctx).act(ctx.viewport_id(), WindowAction::Close); } } From 5c342b79d899181330339363ad757275433c1f18 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 09:38:16 -0800 Subject: [PATCH 3/3] Tests: the title bar's Close caption button closes the window The test opens the app with the integrated title bar used on Windows, clicks the Close caption button and checks that the main window is asked to close, then that a modified document keeps the window open with the Unsaved Changes question. It fails without the fix. --- crates/ui-egui/src/chrome/tests.rs | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 0caf6ca592..32049e3f15 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -473,6 +473,59 @@ fn the_app_bar_gives_up_its_right_hand_controls_in_order() { assert!(widest.zip(narrowest).is_some_and(|(w, n)| n >= w - 0.5), "the search keeps its width until it goes: {search_widths:?}"); } +/// A click on the title bar's Close caption button asks the window to close, and the close reaches the app's close guard +/// as an OS close does: with a modified document the window stays and the Unsaved Changes question shows. +#[test] +fn the_title_bars_close_button_closes_the_window() { + use craft::window::policy::{Backend, Desktop, Frame, Os, Runtime, TitleBarPref, WindowKind, decide}; + crate::i18n::set_current(crate::i18n::Lang::EN); + // The window the desktop host opens on Windows: decorations off, and the title bar draws the caption buttons. + let desktop = Desktop::detect(Backend::X11); + let decision = decide(Os::Windows, Runtime::Native, Backend::X11, &desktop, WindowKind::Main, TitleBarPref::Integrated, None); + assert!(matches!(decision.frame, Frame::Integrated(_)), "{:?}", decision.frame); + let ctx = egui::Context::default(); + craft::ui::shell::embed::install(&ctx, craft::ui::testing::install_spec().frame(decision), &crate::ui_fonts()).expect("the runtime installs"); + craft::ui::testing::windows::set_os(&ctx, Os::Windows); + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.session.add_document(vectorcraft_doc::Document::new(612.0, 792.0), None); + app.sync_views(); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap(); + let room = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 600.0)); + let frame = |app: &mut crate::VectorcraftApp, events: Vec| { + let out = crate::testing::app_frame(app, &ctx, egui::RawInput { screen_rect: Some(room), events, ..Default::default() }); + out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|root| root.commands.contains(&egui::ViewportCommand::Close)) + }; + // The Close button sits at the bar's right end, flush with the window's top right corner. + let at = egui::pos2(room.right() - 4.0, 4.0); + let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + let mut closed = false; + for events in [vec![], vec![], vec![egui::Event::PointerMoved(at)]] { + closed |= frame(&mut app, events); + } + assert!(!closed, "no close before the click"); + for events in [vec![button(true)], vec![button(false)], vec![]] { + closed |= frame(&mut app, events); + } + assert!(closed, "the Close caption button asks the main window to close"); + // The host answers the close with the window's close event, which `embed::logic` takes to the app's close guard. + let mut raw = egui::RawInput { screen_rect: Some(room), ..Default::default() }; + raw.viewports.entry(egui::ViewportId::ROOT).or_default().events.push(egui::ViewportEvent::Close); + let mut decision = None; + ctx.run_ui(raw, |ui| { + app.ui(ui); + craft::ui::shell::embed::logic(ui.ctx(), || { + let answer = app.close_decision(); + decision = Some(answer); + answer + }); + }) + .textures_delta + .clear(); + assert_eq!(decision, Some(craft::ui::shell::embed::CloseDecision::Hold), "the modified document keeps the window open"); + let asks = app.dialogs().is_some_and(|dialogs| dialogs.with(|host| host.get::().is_some())); + assert!(asks, "the close asks about the modified document"); +} + /// A text the status bar painted, with where it lies. #[derive(Debug)] struct StatusText {