Use a new API to propagate foreground state to child processes#19192
Merged
Use a new API to propagate foreground state to child processes#19192
Conversation
commit 8fbd544 Author: Dustin L. Howett <dustin@howett.net> Date: Wed Jun 4 18:12:19 2025 -0500 Uncommentary commit 8c08e0e Author: Dustin L. Howett <dustin@howett.net> Date: Wed Jun 4 18:12:02 2025 -0500 Commentary commit b07bc3a Merge: b3615d5 155d8a9 Author: Dustin L. Howett <dustin@howett.net> Date: Wed Jun 4 18:04:14 2025 -0500 Merge remote-tracking branch 'origin/main' into dev/duhowett/propagate-priority commit b3615d5 Author: Dustin Howett <duhowett@microsoft.com> Date: Tue Aug 13 14:33:32 2024 -0500 yott yeet commit 596a17b Author: Dustin Howett <duhowett@microsoft.com> Date: Tue Aug 13 14:21:18 2024 -0500 Yeet yott Ensure that we have the right rights Move to TerminalThemeHelpers (cherry picked from commit 9670a53f8b92f08e67034704edd247a1f954643d)
7d806cb to
d3d1cff
Compare
DHowett
commented
Aug 11, 2025
DHowett
commented
Aug 12, 2025
lhecker
reviewed
Aug 12, 2025
| _UpdateBackground(profile); | ||
| } | ||
|
|
||
| _adjustProcessPriorityGivenFocusState(_activated); |
Member
There was a problem hiding this comment.
Do we need to debounce it? Not sure what the API cost is...
Member
Author
There was a problem hiding this comment.
Not sure. Happy to do it.
Member
There was a problem hiding this comment.
I think we should just loop it 1000 times and measure how long it takes. Do you happen to already have a debug build ready locally? I'd just do:
const auto beg = std::chron::high_resolution_clock::now();
for (int i = 0; i < 1000; ++i) _adjustProcessPriorityGivenFocusState(_activated);
const auto end = std::chron::high_resolution_clock::now();
const auto dur = std::chrono::duration<double>(end - beg).count();
OutputDebugStringA(fmt::format("{} ns/op\n", dur * 1e9 / 1000.0).c_str());
Member
There was a problem hiding this comment.
tl;dr the cost is in the order of 10us/op, as it crosses a syscall (and this is the typical cost).
DHowett
commented
Aug 12, 2025
lhecker
approved these changes
Aug 12, 2025
…rols; duplicateHandle; document safety
lhecker
approved these changes
Aug 12, 2025
lhecker
approved these changes
Aug 12, 2025
DHowett
added a commit
that referenced
this pull request
Aug 21, 2025
Windows 11 uses some additional signals to determine what the user cares about and give it a bit of a QoS boost. One of those signals is whether it is associated with a window that is in the foreground or which has input focus. Association today takes two forms: - Process has a window which is in the foreground or which has input focus - Process has a *parent* that meets the above criterion. Console applications that are spawned "inside" terminal by handoff do not fall into either bucket. They don't have a window. Their parent is `dllhost` or `explorer`, who is definitely not in focus. We are piloting a new API that allows us to associate those processes with Terminal's window. When Terminal is in focus, it will attach every process from the active tab to its QoS group. This means that whatever is running in that tab is put into the "foreground" bucket, and everything running in other background tabs is not. When Terminal is out of focus, it attaches every process to its QoS group. This ensures that they all go into the "background" bucket together, following the window. (cherry picked from commit 0d23624) Service-Card-Id: PVTI_lADOAF3p4s4Axadtzgdh6-Q Service-Version: 1.23
DHowett
pushed a commit
that referenced
this pull request
Sep 16, 2025
You can now create throttled functions which trigger both on the leading and trailing edge. This was then also ported to `ThrottledFunc` for `DispatcherQueue`s and used for title/taskbar updates. Closes #19188 * In CMD run: ```batch FOR /L %N IN () DO @echo %time% ``` * Doesn't hang the UI ✅ SERVICE NOTES This replays part of #19192 to make it compatible with throttled_func. (cherry picked from commit dbf740c) Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgdI2TQ PVTI_lADOAF3p4s4AxadtzgdSMv0 Service-Version: 1.23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Windows 11 uses some additional signals to determine what the user cares
about and give it a bit of a QoS boost. One of those signals is whether
it is associated with a window that is in the foreground or which has
input focus.
Association today takes two forms:
focus
Console applications that are spawned "inside" terminal by handoff do
not fall into either bucket. They don't have a window. Their parent is
dllhostorexplorer, who is definitely not in focus.We are piloting a new API that allows us to associate those processes
with Terminal's window.
When Terminal is in focus, it will attach every process from the active
tab to its QoS group. This means that whatever is running in that tab
is put into the "foreground" bucket, and everything running in other
background tabs is not.
When Terminal is out of focus, it attaches every process to its QoS
group. This ensures that they all go into the "background" bucket
together, following the window.