From 463cea0615a22be2f7d6c30512211f9eda97ff28 Mon Sep 17 00:00:00 2001 From: bherbruck Date: Wed, 21 Oct 2026 09:17:10 -0400 Subject: [PATCH] Windows: ask for the foreground once, when the first frame is on screen (#4284) Co-authored-by: Claude Sonnet 5.5 --- apps/solidcraft/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rs index b05116240..4c5df386f 100644 --- a/apps/solidcraft/src/main.rs +++ b/apps/solidcraft/src/main.rs @@ -47,6 +47,8 @@ struct App { starting: Option, /// Frames begun; the second one means the first was drawn (startup is over). frames: u32, + /// Started over the control channel: the window doesn't ask for the foreground. + take_focus_unwanted: bool, #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] space_mouse: space_mouse::SpaceMouse, } @@ -59,6 +61,14 @@ impl eframe::App for App { // A second frame right away, which means the first was presented: the app is up. ctx.request_repaint(); if self.frames == 2 { + // The window is shown only once its first frame is presented, and Windows then + // keeps a window of a process started from a shortcut or an installer behind the + // others. Ask for the foreground once, now that it is on screen; never again, so + // later frames don't take the focus from whatever the user moved to. Automation + // over the control channel keeps the focus where it is. + if !self.take_focus_unwanted { + ctx.send_viewport_cmd(egui::ViewportCommand::Focus); + } solidcraft_engine::crash::phase(solidcraft_engine::crash::RUNNING); if let Some(dir) = self.starting.take() { startup::started(&dir); @@ -703,6 +713,7 @@ fn main() -> eframe::Result { solve: app, starting, frames: 0, + take_focus_unwanted: control_port.is_some(), #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] space_mouse, }))