Skip to content

Commit

Permalink
Pass foreground rights to the emperor (#18325)
Browse files Browse the repository at this point in the history
Forgetti di spaghetti in #18215.

Closes #18324

## Validation Steps Performed

* Launch through the start menu
* Explicitly minimize
* Then...
  * Launch through the start menu again ✅
  * Launch via wtd.exe in Win+R ✅
  * Launch via wtd.exe in another Terminal ✅
  * Launch via handoff ✅
  • Loading branch information
lhecker authored Dec 13, 2024
1 parent 19460f9 commit 5006045
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ static wil::unique_mutex acquireMutexOrAttemptHandoff(const wchar_t* className,
.cbData = gsl::narrow<DWORD>(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<LPARAM>(&cds), SMTO_ABORTIFHUNG | SMTO_ERRORONEXIT, 5000, nullptr))
{
return {};
Expand Down

0 comments on commit 5006045

Please sign in to comment.