From 1e0bd859f6ca96b2a011f7b79b0a3c1906038a7a Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Fri, 13 Dec 2024 17:35:25 +0100 Subject: [PATCH] Pass foreground rights to the emperor --- src/cascadia/WindowsTerminal/WindowEmperor.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index 66bc375d0af..6c25d4c8ade 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -170,6 +170,14 @@ static wil::unique_mutex acquireMutexOrAttemptHandoff(const wchar_t* className, .cbData = gsl::narrow(payload.size()), .lpData = payload.data(), }; + + // Allow the existing instance to gain foreground rights. + DWORD processId = 0; + if (GetWindowThreadProcessId(hwnd, &processId) && processId) + { + AllowSetForegroundWindow(processId); + } + if (SendMessageTimeoutW(hwnd, WM_COPYDATA, 0, reinterpret_cast(&cds), SMTO_ABORTIFHUNG | SMTO_ERRORONEXIT, 5000, nullptr)) { return {};