[1.22] Fix teardown when 'allowHeadless' is enabled #18869
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Fixes a bug where
Monarch::_peasants
would not be updated when the last window was closed andcompatibility.allowHeadless
was enabled.Detailed Description of the Pull Request / Additional comments
The bug was originally caused by
Monarch::_peasants
still holding on to a reference to itself in the list. Normally, aPeasant
was removed from the list via theWindowManager::SignalClose()
(akaMonarch::SignalClose()
) function. However,AppHost::_CloseRequested()
would omit that call when the last window was closing.Normally, that makes sense. It's the last window, so let's call
AppHost::_quit()
-->WindowManager::QuitAll()
-->Monarch::QuitAll()
, where we just callPeasant::Quit()
on all the peasants and the monarch and we call it a day. Everything should be cleaned up and if we need a new session, we'll create a newMonarch
anyways.Problem is, when
compatibility.allowHeadless
is enabled, theWindowEmperor
doesn't actually close! We want theWindowEmperor
to stick around because that's the "headless" part we're allowing. SeeWindowEmperor::_decrementWindowCount()
:terminal/src/cascadia/WindowsTerminal/WindowEmperor.cpp
Lines 296 to 308 in bbd6427
The fix here was to avoid the
QuitAll()
code path mentioned above ifcompatibility.allowHeadless
is enabled. Just treat this as a normal teardown otherwise so that theWindowEmperor
creates a newMonarch
when we need it.Validation Steps Performed
✅ The scenario from the bug works:
compatibility.allowHeadless
windowingBehavior
touseExisting
✅ when all windows are closed, we still have the background process
Closes #18827