From c52ba7dec6386e11befb62e81e4c0c970a9c5e3e Mon Sep 17 00:00:00 2001 From: flyingcat Date: Tue, 11 Jun 2024 05:19:07 +0800 Subject: [PATCH] Make subsequent windows open in the foreground (#17368) Sometimes subsequent WT windows open in the background behind other applications. This PR tries to fix it. Refs #15895 Refs #15479 Mysterious bug (and annoying). There are even some discussions about happening to the first startup, not just subsequent ones. Sometimes the window may show up without animation too. So I don't think this is the final solution, but it did get solved on my computer, for now. ## Validation Steps Performed 0. Quit all WT windows if some. 1. Open File Explorer, click "Open in Terminal" in context menu. 2. Move the newly opened window and minimize it. 3. Back to step 1 and repeat several times. 4. All the windows should open in the foreground correctly (yet possibly without animation). --------- Co-authored-by: Mike Griese --- src/cascadia/Remoting/WindowManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cascadia/Remoting/WindowManager.cpp b/src/cascadia/Remoting/WindowManager.cpp index a9d3a42e018..88c3a0218d1 100644 --- a/src/cascadia/Remoting/WindowManager.cpp +++ b/src/cascadia/Remoting/WindowManager.cpp @@ -130,6 +130,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation // We connected to a monarch instance, not us though. This won't hit // in isolated mode. + LOG_IF_FAILED(CoAllowSetForegroundWindow(winrt::get_unknown(_monarch), nullptr)); + // Send the commandline over to the monarch process if (_proposeToMonarch(args)) {