Merge main into fix/dxf-hatch-pattern-gradient

This commit is contained in:
dotCooCoo committed 2026-12-05 02:20:05 -08:00
commit cc1749993d
4 files changed
+169 -1

No files matched your search

+4
View File
@@ -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;
+144 -1
View File
@@ -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<dyn FnMut()>;
#[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<super::Viewports<HWND>> = 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<H>(Mutex<HashMap<egui::ViewportId, Option<H>>>);
impl<H> Default for Viewports<H> {
fn default() -> Self {
Self(Mutex::new(HashMap::new()))
}
}
#[cfg_attr(not(all(windows, feature = "wgpu")), allow(dead_code))]
impl<H> Viewports<H> {
/// 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<H>) {
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<egui::ViewportId, Option<H>>> {
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<u32>, viewports: &[egui::ViewportId]) -> Vec<Option<u32>> {
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() {
+6
View File
@@ -1076,6 +1076,12 @@ fn run(app: &mut VectorcraftApp, actions: Vec<Action<String>>, reveal: Option<St
if layout_of(&app.ui).opens_in_flyout(&panel) {
app.ui.open_panel = Some(panel);
} else {
// An open flyout is a popup layer of the main window, and palette windows stay hidden while one shows: a
// floating window revealed with a flyout open (a built-in workspace opens its panel's flyout) would open
// hidden, so the flyout closes.
if floating_window(layout_of(&app.ui), &panel).is_some() {
app.ui.open_panel = None;
}
app.dock_rt.raise = Some(panel);
}
}
@@ -601,6 +601,21 @@ fn a_panel_floated_in_any_built_in_workspace_opens_a_shown_window() {
}
}
/// Palette windows hide while the main window shows a popup, which an open flyout is: a built-in workspace opens its
/// panel's flyout, and a panel floated then closes it, so its window shows.
#[test]
fn floating_a_panel_closes_the_open_flyout_that_would_hide_its_window() {
let mut h = Harness::new();
h.app.run("window.workspace", json!({"name": "Essentials Classic"})).unwrap();
h.frames(3);
assert_eq!(h.app.ui.open_panel.as_deref(), Some("color"), "Essentials Classic opens its Color flyout");
h.app.run("window.panel.float", json!({"panel": "tools", "x": 200, "y": 200})).unwrap();
h.frames(6);
assert_eq!(h.app.ui.open_panel, None, "the flyout closed");
let viewport = h.viewport("tools");
assert!(h.host.borrow().windows[&viewport].visible, "the tools window shows");
}
/// A panel opened from the Window menu floats in an OS window that keeps showing while the art on
/// the canvas is selected and moved, and the Selection tool's move ends where it is released.
#[test]