Skip to content

Commit

Permalink
Both these fixes should be in this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Apr 7, 2022
1 parent 72e3ed4 commit 6ab1fb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
40 changes: 22 additions & 18 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,30 +934,34 @@ void ConhostInternalGetSet::FocusChanged(const bool focused)
// _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&& const auto psuedoHwnd{ ServiceLocator::LocatePseudoWindow(reinterpret_cast<HWND>(handle)) })
if (focused)
{
// They want focus, we found a pseudohwnd.

if (const auto ownerHwnd{ ::GetParent(psuedoHwnd) })
if (const auto psuedoHwnd{ ServiceLocator::LocatePseudoWindow() })
{
// We have an owner from a previous call to ReparentWindow
// They want focus, we found a pseudohwnd.

if (const auto currentFgWindow{ ::GetForegroundWindow() })
// Note: ::GetParent(psuedoHwnd) will return 0. GetAncestor works though.
if (const auto ownerHwnd{ ::GetAncestor(psuedoHwnd, GA_PARENT) })
{
// 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 };
const auto currentFgThreadId{ GetWindowThreadProcessId(currentFgWindow, &currentFgPid) };
const auto ownerThreadId{ GetWindowThreadProcessId(ownerHwnd, &ownerPid) };
// We have an owner from a previous call to ReparentWindow

if (ownerPid == currentFgPid)
if (const auto currentFgWindow{ ::GetForegroundWindow() })
{
// Huzzah, the app that owns us is actually the FG
// process. They're allowed to grand FG rights.
shouldActuallyFocus = true;
// 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 };
const auto currentFgThreadId{ GetWindowThreadProcessId(currentFgWindow, &currentFgPid) };
const auto ownerThreadId{ 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;
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/terminal/parser/InputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ bool InputStateMachineEngine::ActionCsiDispatch(const VTID id, const VTParameter
// client reads it.
if (_pDispatch->IsVtInputEnabled() &&
_pfnFlushToInputQueue &&
id != CsiActionCodes::Win32KeyboardInput)
id != CsiActionCodes::Win32KeyboardInput &&
id != CsiActionCodes::FocusIn &&
id != CsiActionCodes::FocusOut)
{
return _pfnFlushToInputQueue();
}
Expand Down

1 comment on commit 6ab1fb2

@github-actions

This comment was marked as outdated.

Please sign in to comment.