[PR #15187] Fix Peasant::ActivateWindow being called with an all 0 GUID #30486

Open
opened 2026-01-31 09:41:06 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/15187

State: closed
Merged: Yes


WM_ACTIVATE is sent on window creation, whereas WM_SHOWWINDOW is
sent when the window is shown. Before we call Peasant::ActivateWindow
in the WM_ACTIVATE handler, we try to get the virtual desktop GUID of
our window, but since it's not shown yet during startup, there's also
no GUID that can be retrieved. This results in an error log message and
an all 0 GUID to be sent via Peasant::ActivateWindow.
The GUID of the window that actually spawned on the other hand is never
reported until the first time you reactivate it again, leading to a
number of subtle bugs around window activity.

Additionally, this commit fixes a race condition and pointer unsafety,
by pulling all relevant member variables onto the coroutine's stack,
before it yields itself to a background thread.

Validation Steps Performed

  • Set a trace breakpoint on _peasantNotifyActivateWindow
  • GUID is non-zero
**Original Pull Request:** https://github.com/microsoft/terminal/pull/15187 **State:** closed **Merged:** Yes --- `WM_ACTIVATE` is sent on window creation, whereas `WM_SHOWWINDOW` is sent when the window is shown. Before we call `Peasant::ActivateWindow` in the `WM_ACTIVATE` handler, we try to get the virtual desktop GUID of our window, but since it's not shown yet during startup, there's also no GUID that can be retrieved. This results in an error log message and an all 0 GUID to be sent via `Peasant::ActivateWindow`. The GUID of the window that actually spawned on the other hand is never reported until the first time you reactivate it again, leading to a number of subtle bugs around window activity. Additionally, this commit fixes a race condition and pointer unsafety, by pulling all relevant member variables onto the coroutine's stack, before it yields itself to a background thread. ## Validation Steps Performed - Set a trace breakpoint on `_peasantNotifyActivateWindow` - GUID is non-zero ✅
claunia added the pull-request label 2026-01-31 09:41:06 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30486