-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Ensure a terminal requesting FG rights actually has them #12899
Merged
Merged
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9dd1649
Doesn't build. Want to merge in the ConGetSet change first, cause _ob…
zadjii-msft 1a1caf9
cherry-pick 479c6c9f08cf273768e64f9f7fbc74a2c231b815
zadjii-msft 5be7f76
comments comments comments
zadjii-msft 37adb94
remove a todo
zadjii-msft 172acd2
you knew there'd be typos
zadjii-msft 0d17cd7
Merge branch 'main' into dev/migrie/b/2988-focus-foreground
zadjii-msft 3e0c15a
Merge branch 'dev/migrie/f/z-order-owner' into dev/migrie/b/2988-focu…
zadjii-msft 72e3ed4
check the ownership for FG rights. NOT TESTED
zadjii-msft 6ab1fb2
Both these fixes should be in this branch
zadjii-msft f12b8c1
Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-foc…
zadjii-msft ac53c8a
Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-foc…
zadjii-msft 9688573
Merge branch 'dev/migrie/b/2988-focus-foreground' into dev/migrie/b/2…
zadjii-msft e7c95d2
it builds again
zadjii-msft 2fc0b45
sure, spel
zadjii-msft e6e5669
what? I always run the tests locally i dunno what you're talking abou…
zadjii-msft 440323d
this should have always been in this branch
zadjii-msft 456429f
Merge branch 'dev/migrie/b/2988-focus-foreground' into dev/migrie/b/2…
zadjii-msft 8ae577e
oh my god I've done it again
zadjii-msft 434b6c3
GA_ROOT is probably better
zadjii-msft 3b4675c
oh my god I've done it again
zadjii-msft 9706b59
Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-foc…
zadjii-msft f71af78
lucky day, these can get moved around now
zadjii-msft 6afc170
Merge branch 'dev/migrie/b/2988-focus-foreground' into dev/migrie/b/2…
zadjii-msft 5a81184
Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-foc…
zadjii-msft 2883cb8
minor typos
zadjii-msft a371498
that's what I get for adding comments
zadjii-msft 54c59fa
thanks I guess
zadjii-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,3 +181,75 @@ bool InteractDispatch::IsVtInputEnabled() const | |
{ | ||
return _pConApi->IsVtInputEnabled(); | ||
} | ||
|
||
// Method Description: | ||
// - Inform the console that the window is focused. This is used by ConPTY. | ||
// Terminals can send ConPTY a FocusIn/FocusOut sequence on the input pipe, | ||
// which will end up here. This will update the console's internal tracker if | ||
// it's focused or not, as to match the end-terminal's state. | ||
// - Used to call ConsoleControl(ConsoleSetForeground,...). | ||
// - Full support for this sequence is tracked in GH#11682. | ||
// Arguments: | ||
// - focused: if the terminal is now focused | ||
// Return Value: | ||
// - true always. | ||
bool InteractDispatch::FocusChanged(const bool focused) const | ||
{ | ||
auto& g = ServiceLocator::LocateGlobals(); | ||
auto& gci = g.getConsoleInformation(); | ||
|
||
if (gci.IsInVtIoMode()) | ||
{ | ||
bool shouldActuallyFocus = false; | ||
|
||
// From https://github.com/microsoft/terminal/pull/12799#issuecomment-1086289552 | ||
// Make sure that the process that's telling us it's focused, actually | ||
// _is_ in the FG. We don't want to allow malicious.exe to say "yep I'm | ||
// in the foreground, also, here's a popup" if it isn't actually in the | ||
// FG. | ||
if (focused) | ||
{ | ||
if (const auto psuedoHwnd{ ServiceLocator::LocatePseudoWindow() }) | ||
{ | ||
// They want focus, we found a pseudo hwnd. | ||
|
||
// Note: ::GetParent(psuedoHwnd) will return 0. GetAncestor works though. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pseudo |
||
// GA_PARENT and GA_ROOT seemingly return the same thing for | ||
// Terminal. We're going with GA_ROOT since it seems | ||
// semantically more correct here. | ||
if (const auto ownerHwnd{ ::GetAncestor(psuedoHwnd, GA_ROOT) }) | ||
{ | ||
// We have an owner from a previous call to ReparentWindow | ||
|
||
if (const auto currentFgWindow{ ::GetForegroundWindow() }) | ||
{ | ||
// There is a window in the foreground (it's possible there | ||
// isn't one) | ||
|
||
// Get the PID of the current FG window, and compare with our owner's PID. | ||
DWORD currentFgPid{ 0 }; | ||
DWORD ownerPid{ 0 }; | ||
GetWindowThreadProcessId(currentFgWindow, ¤tFgPid); | ||
GetWindowThreadProcessId(ownerHwnd, &ownerPid); | ||
|
||
if (ownerPid == currentFgPid) | ||
{ | ||
// Huzzah, the app that owns us is actually the FG | ||
// process. They're allowed to grand FG rights. | ||
shouldActuallyFocus = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
WI_UpdateFlag(gci.Flags, CONSOLE_HAS_FOCUS, shouldActuallyFocus); | ||
gci.ProcessHandleList.ModifyConsoleProcessFocus(shouldActuallyFocus); | ||
} | ||
// Does nothing outside of ConPTY. If there's a real HWND, then the HWND is solely in charge. | ||
|
||
// Theoretically, this could be propagated as a focus event as well, to the | ||
// input buffer. That should be considered when implementing GH#11682. | ||
|
||
return true; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
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 even HAVE an InteractDispatch if we're not in VtIo mode?