SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Windows OpenGL: use the system title bar so the picture lines up with clicks (#2063) (#4403)
raykholo138bb0261ca8
diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rsindex f9164f6834..3ef7c08b41 100644--- a/apps/solidcraft/src/main.rs+++ b/apps/solidcraft/src/main.rs@@ -559,7 +559,8 @@ const FLOAT_DEPTH_BITS: u8 = 32;const STENCIL_BITS: u8 = 8;const MSAA: u16 = 4;-fn app_viewport() -> Result<egui::ViewportBuilder, eframe::Error> {+/// `custom_titlebar`: no OS decorations, the application bar is the title bar.+fn app_viewport(custom_titlebar: bool) -> Result<egui::ViewportBuilder, eframe::Error> {// Let macOS use the bundle's layered icon; eframe's default bitmap would replace it.#[cfg(target_os = "macos")]let icon = egui::IconData::default();@@ -572,7 +573,7 @@ fn app_viewport() -> Result<egui::ViewportBuilder, eframe::Error> {.with_inner_size([1600.0, 1000.0]).with_min_inner_size([960.0, 600.0]).with_drag_and_drop(true)- .with_decorations(!CUSTOM_TITLEBAR)+ .with_decorations(!custom_titlebar).with_fullsize_content_view(true).with_titlebar_shown(false).with_title_shown(false)@@ -664,10 +665,16 @@ fn main() -> eframe::Result {// module on Windows, and on every system the startup step the app was in.#[cfg(target_os = "windows")]native_crash::install();+ // Windows with only OpenGL to start: the system title bar instead of ours (#2063).+ let started = match &wgpu_options.wgpu_setup {+ eframe::egui_wgpu::WgpuSetup::CreateNew(setup) => setup.instance_descriptor.backends,+ _ => eframe::wgpu::Backends::all(),+ };+ let custom_titlebar = CUSTOM_TITLEBAR && !startup::system_title_bar(cfg!(target_os = "windows"), started);eframe::egui_wgpu::set_startup_hook(startup_step);solidcraft_engine::crash::phase("window");let options = eframe::NativeOptions {- viewport: app_viewport()?,+ viewport: app_viewport(custom_titlebar)?,// The window's pass (egui's) has no depth and one sample: the viewport draws its scene// offscreen with its own depth and MSAA, then blits it, so the UI pass pays for neither.depth_buffer: 0,@@ -731,7 +738,7 @@ fn main() -> eframe::Result {mark("fonts");let mut app = SolveApp::new(Session::default(), services(cc));app.apply_off_thread = Some(solidcraft_ui_egui::dialogs::APPLY_AT_ONCE);- app.custom_titlebar = CUSTOM_TITLEBAR;+ app.custom_titlebar = custom_titlebar;#[cfg(target_os = "windows")]{// Windows: the taskbar button shows the mark even when slow first frames keep the@@ -741,8 +748,8 @@ fn main() -> eframe::Result {}// The OS hit test offers the resize border, at the window's DPI, from the first// message (#1381).- app.native_resize_border = CUSTOM_TITLEBAR && native_frame::install(cc);- if CUSTOM_TITLEBAR && !app.native_resize_border {+ app.native_resize_border = custom_titlebar && native_frame::install(cc);+ if custom_titlebar && !app.native_resize_border {eprintln!("SolidCraft window: no native resize border; egui edge zones instead");}}@@ -1011,7 +1018,7 @@ mod icon_tests {#[cfg(target_os = "macos")]#[test]fn macos_preserves_the_bundle_icon_instead_of_setting_a_runtime_bitmap() {- let viewport = super::app_viewport().expect("viewport");+ let viewport = super::app_viewport(super::CUSTOM_TITLEBAR).expect("viewport");assert_eq!(viewport.icon.as_deref(), Some(&eframe::egui::IconData::default()));assert_eq!(viewport.app_id.as_deref(), Some(super::APP_ID));}@@ -1019,7 +1026,7 @@ mod icon_tests {#[cfg(not(target_os = "macos"))]#[test]fn desktop_viewport_supplies_the_original_mark_to_the_window() {- let viewport = super::app_viewport().expect("viewport");+ let viewport = super::app_viewport(super::CUSTOM_TITLEBAR).expect("viewport");let icon = viewport.icon.expect("running window must have an icon");assert_eq!((icon.width, icon.height), (64, 64));assert_eq!(icon.rgba, super::app_icon::rgba(64).expect("original mark"));diff --git a/apps/solidcraft/src/startup.rs b/apps/solidcraft/src/startup.rsindex a88c4e9ca1..7ff747ddea 100644--- a/apps/solidcraft/src/startup.rs+++ b/apps/solidcraft/src/startup.rs@@ -220,6 +220,17 @@ pub fn window_instance_flags(flags: eframe::wgpu::InstanceFlags, intel_mac: boolif intel_mac && env.map(str::trim).is_none_or(str::is_empty) { flags - eframe::wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL } else { flags }}+/// Windows with OpenGL: the window keeps the system title bar (#2063). The window without OS+/// decorations keeps its caption style while having no frame, and some OpenGL drivers (older+/// Intel HD/UHD) then show the picture a caption's height lower than the window, so it no longer+/// lines up with the pointer. Direct3D 12 and Vulkan draw it in place and keep the application bar+/// as the title bar. `backends` are the ones wgpu starts: OpenGL alone is decided before the+/// window opens.+pub fn system_title_bar(windows: bool, backends: eframe::wgpu::Backends) -> bool {+ use eframe::wgpu::Backends;+ windows && backends.contains(Backends::GL) && !backends.intersects(Backends::DX12 | Backends::VULKAN)+}+/// The message shown when no window could be opened at all.pub fn no_window_message(error: &str, settings: Option<&Path>) -> String {let folder = settings.map(|d| d.display().to_string()).unwrap_or_else(|| "the SolidCraft settings folder".into());@@ -347,6 +358,18 @@ mod tests {assert_eq!(choose_backends(true, false, false, Some(""), probe(&[Backends::GL])), Some(Backends::GL));}+ #[test]+ fn only_opengl_on_windows_gets_the_system_title_bar() {+ use eframe::wgpu::Backends;+ assert!(system_title_bar(true, Backends::GL));+ for b in [Backends::DX12, Backends::VULKAN, Backends::DX12 | Backends::GL, Backends::VULKAN | Backends::GL, Backends::all()] {+ assert!(!system_title_bar(true, b), "{b:?}");+ }+ for b in [Backends::GL, Backends::VULKAN, Backends::METAL] {+ assert!(!system_title_bar(false, b), "{b:?}");+ }+ }+#[test]fn wgpu_backend_the_preference_and_the_software_renderer_override_the_order() {use eframe::wgpu::Backends;diff --git a/docs/book/src/guide/troubleshooting.md b/docs/book/src/guide/troubleshooting.mdindex 100c0091fe..74f971667e 100644--- a/docs/book/src/guide/troubleshooting.md+++ b/docs/book/src/guide/troubleshooting.md@@ -95,6 +95,11 @@ from the Start menu after you sign in again. From 0.11.1 the setting can also li`graphics.json` in the settings folder, as `{"msaa": 4, "backend": "dx12"}` (`auto` is theorder above). Safe mode ignores it and always uses the software renderer.+With OpenGL on Windows, the window has the Windows title bar above SolidCraft's application bar+instead of using the application bar as its title bar. Some OpenGL drivers (older Intel HD and+UHD graphics) otherwise show the picture a title bar's height lower than the window, so clicks+land above what they point at.+## SolidCraft restarted, saying the graphics device was resetWhen the graphics driver stops responding, the system resets it (on Windows, "Display driver