Repository: microsoft/terminal
File: src/terminal/adapter/InteractDispatch.cpp (C++)

Code before:
    RETURN_IF_FAILED(gci.GetVtIo()->SetCursorPosition(coordCursor));

    // Finally, attempt to set the adjusted cursor position back into the console.
    cursor.SetPosition(coordCursor);
    cursor.SetHasMoved(true);
    return true;
}

// Routine Description:
// - Checks if the InputBuffer is willing to accept VT Input directly
// Arguments:
// - <none>
// Return value:
// - true if enabled (see IsInVirtualTerminalInputMode). false otherwise.
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 was added 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.

Review comment (suggestion):
We can just kill this line. Otherwise we're gonna litter our code with historical artifacts pointing to GitHub issues that we could relegate to `git blame` :)

Code after:
    RETURN_IF_FAILED(gci.GetVtIo()->SetCursorPosition(coordCursor));

    // Finally, attempt to set the adjusted cursor position back into the console.
    cursor.SetPosition(coordCursor);
    cursor.SetHasMoved(true);
    return true;
}

// Routine Description:
// - Checks if the InputBuffer is willing to accept VT Input directly
// Arguments:
// - <none>
// Return value:
// - true if enabled (see IsInVirtualTerminalInputMode). false otherwise.
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,...).
// 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();

    // This should likely always be true - we shouldn't ever have an
    // InteractDispatch outside ConPTY mode, but just in case...
    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 pseudoHwnd{ ServiceLocator::LocatePseudoWindow() })
            {
                // They want focus, we found a pseudo hwnd.