-
Notifications
You must be signed in to change notification settings - Fork 9k
Use a new API to propagate foreground state to child processes #19192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
| _UpdateBackground(profile); | ||
| } | ||
|
|
||
| _adjustProcessPriorityGivenFocusState(_activated); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to debounce it? Not sure what the API cost is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. Happy to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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());There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr the cost is in the order of 10us/op, as it crosses a syscall (and this is the typical cost).
…rols; duplicateHandle; document safety
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
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
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.