Skip to content

Commit

Permalink
comments comments comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 31, 2022
1 parent 1a1caf9 commit 5be7f76
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,11 +1683,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

// Method Description:
// - When the control gains focus, it needs to tell ConPTY about this.
// Usually, these sequences are reserved for applications that
// specifically request SET_FOCUS_EVENT_MOUSE, ?1004h. ConPTY uses this
// sequence REGARDLESS to communicate if the control was focused or not.
// - Even if a client application disables this mode, the Terminal & conpty
// should always request this from the hostind terminal (and just ignore
// internally to ConPTY).
// - Full support for this sequence is tracked in GH#11682.
// - This is related to work done for GH#2988.
void ControlCore::GotFocus()
{
_connection.WriteInput(L"\x1b[I");
}

// See GotFocus.
void ControlCore::LostFocus()
{
_connection.WriteInput(L"\x1b[O");
Expand Down
4 changes: 3 additions & 1 deletion src/host/CursorBlinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ void CursorBlinker::TimerRoutine(SCREEN_INFORMATION& ScreenInfo) const noexcept
auto& cursor = buffer.GetCursor();
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
auto* const pAccessibilityNotifier = ServiceLocator::LocateAccessibilityNotifier();
const bool inConpty{ gci.IsInVtIoMode() };

if (!WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS))
// GH#2988: ConPTY can now be focused, but it doesn't need to do any of this work either.
if (inConpty || !WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS))
{
goto DoScroll;
}
Expand Down
17 changes: 17 additions & 0 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,26 @@ void ConhostInternalGetSet::UpdateSoftFont(const gsl::span<const uint16_t> bitPa
}
}

// 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:
// - bitPattern - An array of scanlines representing all the glyphs in the font.
// - cellSize - The cell size for an individual glyph.
// - centeringHint - The horizontal extent that glyphs are offset from center.
// Return Value:
// - <none>
void ConhostInternalGetSet::FocusChanged(const bool focused)
{
auto& g = ServiceLocator::LocateGlobals();
auto& gci = g.getConsoleInformation();
WI_UpdateFlag(gci.Flags, CONSOLE_HAS_FOCUS, focused);
gci.ProcessHandleList.ModifyConsoleProcessFocus(focused);

// Theoretically, this could be propogated as a focus event as well, to the
// input buffer. That should be considered when implementing GH#11682.
}
17 changes: 15 additions & 2 deletions src/server/IoDispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,22 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
return pReceiveMsg;
}

// For future code archeologists: GH#2988
//
// Here, the console calls ConsoleControl(ConsoleSetForeground,...) with a
// flag depending on if the console is focused or not. This is surprisingly
// load bearing. This allows windows spawned by console processes to bring
// themselves to the foreground _when the console is focused_.
// (Historically, this is also called in the WndProc, when focus changes).
//
// Notably, before 2022, ConPTY was _never_ focused, so windows could never
// bring themselves to the foreground when run from a ConPTY console. We're
// not blanket granting the SetForeground right to all console apps when run
// in ConPTY. It's the responsibility of the hosting terminal emulator to
// always tell ConPTY when a particular instance is focused.
const bool hasFocus{ WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS) };
const auto grantFG{ hasFocus };
gci.ProcessHandleList.ModifyConsoleProcessFocus(grantFG);
const auto grantSetForeground{ hasFocus };
gci.ProcessHandleList.ModifyConsoleProcessFocus(grantSetForeground);

// Create the handles.

Expand Down

1 comment on commit 5be7f76

@github-actions

This comment was marked as outdated.

Please sign in to comment.