From 6996cc7878c60fe7ded1c59ad61a03036f4ed5cb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 01:13:30 -0800 Subject: [PATCH 1/2] Windows: floating panels and dialogs draw where the pointer is on OpenGL Part of #10797. On the OpenGL backend, Preferences and floating panels drew their content offset down and right by a title bar and border, while clicks landed at the unshifted positions. These windows draw their own title bar, so winit makes them undecorated, but it still gives them the WS_CAPTION and WS_BORDER styles, and on these systems the frame stays reserved for the window surface. The guard added for #1758 removes the two styles from the main window only. A viewport hook now records every undecorated window other than the main one as eframe creates it, and runs the same guard on it at creation and before each of its frames, so the styles stay off when winit puts them back. Windows with the system title bar are left alone, and a window's record is dropped with the window. --- apps/vectorcraft/src/main.rs | 4 + apps/vectorcraft/src/window_frame.rs | 145 ++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 1 deletion(-) diff --git a/apps/vectorcraft/src/main.rs b/apps/vectorcraft/src/main.rs index d772397ce3..63135d00e5 100644 --- a/apps/vectorcraft/src/main.rs +++ b/apps/vectorcraft/src/main.rs @@ -799,6 +799,10 @@ fn main() -> std::process::ExitCode { // window, so eframe's windows are recorded as it makes and drops them (`quit_windows`). #[cfg(target_os = "linux")] let options = eframe::NativeOptions { viewport_hooks: Some(std::sync::Arc::new(quit_windows::Hooks)), ..options }; + // Floating panels and dialogs that draw their own title bar stay borderless on Windows, as the + // main window does (`window_frame`, #10797). + #[cfg(all(windows, feature = "wgpu"))] + let options = eframe::NativeOptions { viewport_hooks: Some(std::sync::Arc::new(window_frame::Hooks)), ..options }; #[cfg(feature = "wgpu")] let options = { let mut options = options; diff --git a/apps/vectorcraft/src/window_frame.rs b/apps/vectorcraft/src/window_frame.rs index e69806ac29..ba5d3d298d 100644 --- a/apps/vectorcraft/src/window_frame.rs +++ b/apps/vectorcraft/src/window_frame.rs @@ -22,10 +22,20 @@ //! monitor. In PhotoCraft the taskbar then did not show when the pointer reached its edge //! (storytold/photocraft#4845). On each edge with an auto-hidden taskbar the guard stops the window //! one pixel short of the monitor instead, as PhotoCraft does (storytold/photocraft#6878). +//! +//! Floating panels and dialogs that draw their own title bar (Preferences, a floating Color panel) +//! are undecorated winit windows as well, and on the same systems their content was drawn offset +//! by the caption and border too (#10797). `Hooks` records those windows as eframe makes them and +//! runs the same guard on each one in each of its frames. + +use std::collections::HashMap; +use std::sync::{Mutex, MutexGuard, PoisonError}; /// Run once per frame; a no-op once the window is borderless. pub type WindowFrameFn = Box; +#[cfg(all(windows, feature = "wgpu"))] +pub use platform::Hooks; pub use platform::service; #[cfg(all(windows, feature = "wgpu"))] @@ -49,6 +59,33 @@ mod platform { Some(Box::new(move || reapply(&hwnd))) } + /// The undecorated windows of floating panels and dialogs, which [`Hooks`] records. + static SECONDARY: std::sync::LazyLock> = std::sync::LazyLock::new(super::Viewports::default); + + /// Keeps the undecorated windows of floating panels and dialogs borderless, as [`service`] + /// keeps the main window: the guard runs when eframe makes such a window and before each of its + /// frames. Set as [`eframe::NativeOptions::viewport_hooks`]. + pub struct Hooks; + + impl eframe::ViewportHooks for Hooks { + fn window_created(&self, viewport: egui::ViewportId, window: &winit::window::Window) { + let hwnd = match window.window_handle().map(|h| h.as_raw()) { + Ok(RawWindowHandle::Win32(h)) => find_window(h.hwnd.get()), + _ => None, + }; + SECONDARY.created(viewport, window.is_decorated(), hwnd); + SECONDARY.with(viewport, reapply); + } + + fn window_destroyed(&self, viewport: egui::ViewportId) { + SECONDARY.destroyed(viewport); + } + + fn raw_input(&self, _ctx: &egui::Context, raw_input: &mut egui::RawInput) { + SECONDARY.with(raw_input.viewport_id, reapply); + } + } + /// One pass of the per-frame guard: the styles winit put back come off again, and a parked /// maximize stays clear of the taskbar. fn reapply(hwnd: &HWND) { @@ -152,6 +189,55 @@ mod platform { } } +/// The windows of the undecorated floating panels and dialogs, by viewport, while eframe holds +/// them. A record holds `None` while [`Viewports::with`] has its window out. Platform-neutral so +/// it is tested everywhere. +#[cfg_attr(not(all(windows, feature = "wgpu")), allow(dead_code))] +struct Viewports(Mutex>>); + +impl Default for Viewports { + fn default() -> Self { + Self(Mutex::new(HashMap::new())) + } +} + +#[cfg_attr(not(all(windows, feature = "wgpu")), allow(dead_code))] +impl Viewports { + /// eframe made `viewport`'s window, with `handle`. It is recorded when it is an undecorated + /// window other than the main one, which [`service`] keeps; otherwise any earlier record of the + /// viewport is removed, so a window made again with the system title bar is left alone. + fn created(&self, viewport: egui::ViewportId, decorated: bool, handle: Option) { + let mut windows = self.lock(); + match handle { + Some(handle) if viewport != egui::ViewportId::ROOT && !decorated => windows.insert(viewport, Some(handle)), + _ => windows.remove(&viewport), + }; + } + + /// eframe dropped `viewport`'s window. + fn destroyed(&self, viewport: egui::ViewportId) { + self.lock().remove(&viewport); + } + + /// Runs `f` on `viewport`'s recorded window, if any. The window is taken out of its record + /// while `f` runs, so window messages that `f` sends and that reach the hooks again do not wait + /// on the lock. It goes back only if the record is still there and empty: a window dropped or + /// made again for the viewport in the meantime wins. + fn with(&self, viewport: egui::ViewportId, f: impl FnOnce(&H)) { + let Some(handle) = self.lock().get_mut(&viewport).and_then(Option::take) else { + return; + }; + f(&handle); + if let Some(slot @ None) = self.lock().get_mut(&viewport) { + *slot = Some(handle); + } + } + + fn lock(&self) -> MutexGuard<'_, HashMap>> { + self.0.lock().unwrap_or_else(PoisonError::into_inner) + } +} + /// How far a parked maximize reaches past a monitor or work-area edge: the resize border (about /// 8 pt at 100 %, more with DPI). Past that, a maximized window's rect is not parked but being /// dragged or snapped, and is left alone. @@ -260,7 +346,64 @@ fn short_of_autohide_taskbars(rect: Rect, monitor: Rect, work: Rect, taskbars: & #[cfg(test)] mod tests { - use super::{Edge, clamped_rect, short_of_autohide_taskbars, taskbar_edge}; + use super::{Edge, Viewports, clamped_rect, short_of_autohide_taskbars, taskbar_edge}; + + fn viewport(name: &str) -> egui::ViewportId { + egui::ViewportId::from_hash_of(name) + } + + /// The windows `with` reaches for each viewport, in order. + fn reached(windows: &Viewports, viewports: &[egui::ViewportId]) -> Vec> { + viewports + .iter() + .map(|&id| { + let mut seen = None; + windows.with(id, |&h| seen = Some(h)); + seen + }) + .collect() + } + + /// Floating panels and dialogs with their own title bar are kept borderless (#10797); the main + /// window, which `service` keeps, and windows with the system title bar are not recorded. + #[test] + fn undecorated_floating_windows_are_recorded_until_dropped() { + let windows = Viewports::default(); + let (prefs, color, hang) = (viewport("Preferences"), viewport("Color"), viewport("Not responding")); + windows.created(egui::ViewportId::ROOT, false, Some(1)); + windows.created(prefs, false, Some(7)); + windows.created(color, false, Some(9)); + windows.created(hang, true, Some(11)); + assert_eq!(reached(&windows, &[egui::ViewportId::ROOT, prefs, color, hang]), [None, Some(7), Some(9), None]); + // Each frame reaches the window again. + assert_eq!(reached(&windows, &[prefs]), [Some(7)]); + windows.destroyed(prefs); + assert_eq!(reached(&windows, &[prefs, color]), [None, Some(9)]); + // A window made again with the system title bar, or without a handle, is left alone. + windows.created(color, true, Some(13)); + assert_eq!(reached(&windows, &[color]), [None]); + windows.created(color, false, Some(15)); + windows.created(color, false, None); + assert_eq!(reached(&windows, &[color]), [None]); + } + + /// A window dropped or made again while the guard runs on the old one is not brought back. + #[test] + fn a_window_dropped_or_made_again_during_the_guard_wins() { + let windows = Viewports::default(); + let prefs = viewport("Preferences"); + windows.created(prefs, false, Some(7)); + windows.with(prefs, |_| windows.destroyed(prefs)); + assert_eq!(reached(&windows, &[prefs]), [None]); + windows.created(prefs, false, Some(7)); + windows.with(prefs, |_| windows.created(prefs, false, Some(8))); + assert_eq!(reached(&windows, &[prefs]), [Some(8)]); + // The guard can reach the hooks again for the same viewport without waiting on itself. + let mut inner = None; + windows.with(prefs, |_| windows.with(prefs, |&h| inner = Some(h))); + assert_eq!(inner, None); + assert_eq!(reached(&windows, &[prefs]), [Some(8)]); + } #[test] fn a_maximize_covering_the_taskbar_is_trimmed_to_the_work_area() { From 5ee0ebc7be6a54ce57e82b4614e99364eb8ace0c Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sat, 5 Dec 2026 11:09:44 +0100 Subject: [PATCH 2/2] Panels: a floating window revealed with a flyout open shows (#10934) Palette windows hide while the main window shows a popup, and an open flyout is one. A built-in workspace now opens its panel's flyout when it is switched to, so a panel floated by a command in Essentials Classic (Color's flyout) and the other workspaces that open one opened its window hidden, and a_panel_floated_in_any_built_in_workspace_opens_a_shown_window failed on main. The command that reveals a floating window now closes the open flyout. Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 --- crates/ui-egui/src/panel_docking.rs | 6 ++++++ crates/ui-egui/src/panel_docking/native_tests.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index 37090a916d..e5b0110b77 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -1076,6 +1076,12 @@ fn run(app: &mut VectorcraftApp, actions: Vec>, reveal: Option