From 9dd16495251e393aa05387c955697ecc7efd64be Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 29 Mar 2022 10:42:52 -0500 Subject: [PATCH 1/9] Doesn't build. Want to merge in the ConGetSet change first, cause _obviously_ that's gonna blow this diff up. --- src/terminal/adapter/IInteractDispatch.hpp | 2 ++ src/terminal/adapter/InteractDispatch.cpp | 9 +++++++++ src/terminal/adapter/InteractDispatch.hpp | 2 ++ src/terminal/parser/InputStateMachineEngine.cpp | 6 ++++++ src/terminal/parser/InputStateMachineEngine.hpp | 2 ++ 5 files changed, 21 insertions(+) diff --git a/src/terminal/adapter/IInteractDispatch.hpp b/src/terminal/adapter/IInteractDispatch.hpp index acbaf5ff23a..97b22b3edde 100644 --- a/src/terminal/adapter/IInteractDispatch.hpp +++ b/src/terminal/adapter/IInteractDispatch.hpp @@ -42,5 +42,7 @@ namespace Microsoft::Console::VirtualTerminal const size_t col) = 0; virtual bool IsVtInputEnabled() const = 0; + + virtual bool FocusChanged(const bool focused) const = 0; }; } diff --git a/src/terminal/adapter/InteractDispatch.cpp b/src/terminal/adapter/InteractDispatch.cpp index 81b7290dc7c..6102298b92f 100644 --- a/src/terminal/adapter/InteractDispatch.cpp +++ b/src/terminal/adapter/InteractDispatch.cpp @@ -168,3 +168,12 @@ bool InteractDispatch::IsVtInputEnabled() const { return _pConApi->IsVtInputEnabled(); } + +bool InteractDispatch::FocusChanged(const bool focused) const +{ + // * TODO!: plumb through to conapi and then gci.ProcessHandleList.ModifyConsoleProcessFocus(focused); + // * We should assume this is false by default? + // * TODO!: ConPTY should ask for this mode? Yea? Lets make sure that VTE will send that sequence even without other mouse sequences enabled. + // - in the past, this is something we've made opt-in (request cursor, for example. Maybe also the other mouse modes, can't recall) + // * gotta make sure that we can always handle the focus events, even if the client hasn't requested them. +} diff --git a/src/terminal/adapter/InteractDispatch.hpp b/src/terminal/adapter/InteractDispatch.hpp index d903d83e9c6..e521244eb2e 100644 --- a/src/terminal/adapter/InteractDispatch.hpp +++ b/src/terminal/adapter/InteractDispatch.hpp @@ -35,6 +35,8 @@ namespace Microsoft::Console::VirtualTerminal bool IsVtInputEnabled() const override; + bool FocusChanged(const bool focused) const override; + private: std::unique_ptr _pConApi; }; diff --git a/src/terminal/parser/InputStateMachineEngine.cpp b/src/terminal/parser/InputStateMachineEngine.cpp index 40a9d0c4094..2dc695c72c4 100644 --- a/src/terminal/parser/InputStateMachineEngine.cpp +++ b/src/terminal/parser/InputStateMachineEngine.cpp @@ -426,6 +426,12 @@ bool InputStateMachineEngine::ActionCsiDispatch(const VTID id, const VTParameter case CsiActionCodes::DTTERM_WindowManipulation: success = _pDispatch->WindowManipulation(parameters.at(0), parameters.at(1), parameters.at(2)); break; + case CsiActionCodes::FocusIn: + success = _pDispatch->FocusChanged(true); + break; + case CsiActionCodes::FocusOut: + success = _pDispatch->FocusChanged(false); + break; case CsiActionCodes::Win32KeyboardInput: { // Use WriteCtrlKey here, even for keys that _aren't_ control keys, diff --git a/src/terminal/parser/InputStateMachineEngine.hpp b/src/terminal/parser/InputStateMachineEngine.hpp index 8409617204a..c4a814a1eeb 100644 --- a/src/terminal/parser/InputStateMachineEngine.hpp +++ b/src/terminal/parser/InputStateMachineEngine.hpp @@ -58,6 +58,8 @@ namespace Microsoft::Console::VirtualTerminal ArrowLeft = VTID("D"), Home = VTID("H"), End = VTID("F"), + FocusIn = VTID("I"), + FocusOut = VTID("O"), MouseDown = VTID(" Date: Thu, 31 Mar 2022 09:04:26 -0500 Subject: [PATCH 2/9] cherry-pick 479c6c9f08cf273768e64f9f7fbc74a2c231b815 --- src/cascadia/TerminalControl/ControlCore.cpp | 10 ++++++++++ src/cascadia/TerminalControl/ControlCore.h | 3 +++ src/cascadia/TerminalControl/ControlInteractivity.cpp | 4 ++++ src/host/outputStream.cpp | 7 +++++++ src/host/outputStream.hpp | 2 ++ src/server/IoDispatchers.cpp | 4 +++- src/terminal/adapter/InteractDispatch.cpp | 3 ++- src/terminal/adapter/conGetSet.hpp | 2 ++ 8 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 820686d322b..d5621f8cea7 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1683,6 +1683,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation } } + void ControlCore::GotFocus() + { + _connection.WriteInput(L"\x1b[I"); + } + + void ControlCore::LostFocus() + { + _connection.WriteInput(L"\x1b[O"); + } + bool ControlCore::_isBackgroundTransparent() { // If we're: diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index a8cd204f1ef..823a078b8d1 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -81,6 +81,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation void PasteText(const winrt::hstring& hstr); bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference& formats); + void GotFocus(); + void LostFocus(); + void ToggleShaderEffects(); void AdjustOpacity(const double adjustment); void ResumeRendering(); diff --git a/src/cascadia/TerminalControl/ControlInteractivity.cpp b/src/cascadia/TerminalControl/ControlInteractivity.cpp index de992e1b379..2dd00457289 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.cpp +++ b/src/cascadia/TerminalControl/ControlInteractivity.cpp @@ -111,6 +111,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation THROW_IF_FAILED(_uiaEngine->Enable()); } + _core->GotFocus(); + _updateSystemParameterSettings(); } @@ -120,6 +122,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation { THROW_IF_FAILED(_uiaEngine->Disable()); } + + _core->LostFocus(); } // Method Description diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index 1b3ba0a2608..d24a3e2837c 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -892,3 +892,10 @@ void ConhostInternalGetSet::UpdateSoftFont(const gsl::span bitPa pRender->UpdateSoftFont(bitPattern, cellSize, centeringHint); } } + +void ConhostInternalGetSet::FocusChanged(const bool focused) +{ + auto& g = ServiceLocator::LocateGlobals(); + auto& gci = g.getConsoleInformation(); + gci.ProcessHandleList.ModifyConsoleProcessFocus(focused); +} diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index 458e1ab550f..0bdfee83e54 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -116,6 +116,8 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: const SIZE cellSize, const size_t centeringHint) override; + void FocusChanged(const bool focused) override; + private: void _modifyLines(const size_t count, const bool insert); diff --git a/src/server/IoDispatchers.cpp b/src/server/IoDispatchers.cpp index e19526cccf5..fd0cc9b51d5 100644 --- a/src/server/IoDispatchers.cpp +++ b/src/server/IoDispatchers.cpp @@ -456,7 +456,9 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API return pReceiveMsg; } - gci.ProcessHandleList.ModifyConsoleProcessFocus(WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS)); + const bool hasFocus{ WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS) }; + const auto grantFG{ hasFocus }; + gci.ProcessHandleList.ModifyConsoleProcessFocus(grantFG); // Create the handles. diff --git a/src/terminal/adapter/InteractDispatch.cpp b/src/terminal/adapter/InteractDispatch.cpp index 6102298b92f..fe44d0acb02 100644 --- a/src/terminal/adapter/InteractDispatch.cpp +++ b/src/terminal/adapter/InteractDispatch.cpp @@ -171,9 +171,10 @@ bool InteractDispatch::IsVtInputEnabled() const bool InteractDispatch::FocusChanged(const bool focused) const { - // * TODO!: plumb through to conapi and then gci.ProcessHandleList.ModifyConsoleProcessFocus(focused); // * We should assume this is false by default? // * TODO!: ConPTY should ask for this mode? Yea? Lets make sure that VTE will send that sequence even without other mouse sequences enabled. // - in the past, this is something we've made opt-in (request cursor, for example. Maybe also the other mouse modes, can't recall) // * gotta make sure that we can always handle the focus events, even if the client hasn't requested them. + _pConApi->FocusChanged(focused); + return true; } diff --git a/src/terminal/adapter/conGetSet.hpp b/src/terminal/adapter/conGetSet.hpp index 1cfe0d2613b..c048a66cbb9 100644 --- a/src/terminal/adapter/conGetSet.hpp +++ b/src/terminal/adapter/conGetSet.hpp @@ -111,5 +111,7 @@ namespace Microsoft::Console::VirtualTerminal virtual void UpdateSoftFont(const gsl::span bitPattern, const SIZE cellSize, const size_t centeringHint) = 0; + + virtual void FocusChanged(const bool focused) = 0; }; } From 5be7f76586e2a9d7363145171383b00fe1a44f0f Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 31 Mar 2022 10:09:55 -0500 Subject: [PATCH 3/9] comments comments comments --- src/cascadia/TerminalControl/ControlCore.cpp | 11 +++++++++++ src/host/CursorBlinker.cpp | 4 +++- src/host/outputStream.cpp | 17 +++++++++++++++++ src/server/IoDispatchers.cpp | 17 +++++++++++++++-- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index d5621f8cea7..8669f71a374 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -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"); diff --git a/src/host/CursorBlinker.cpp b/src/host/CursorBlinker.cpp index f3aee7a4798..e15456d2e1c 100644 --- a/src/host/CursorBlinker.cpp +++ b/src/host/CursorBlinker.cpp @@ -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; } diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index d24a3e2837c..931e3d44280 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -893,9 +893,26 @@ void ConhostInternalGetSet::UpdateSoftFont(const gsl::span 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: +// - 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. } diff --git a/src/server/IoDispatchers.cpp b/src/server/IoDispatchers.cpp index fd0cc9b51d5..52ac5f0b2a9 100644 --- a/src/server/IoDispatchers.cpp +++ b/src/server/IoDispatchers.cpp @@ -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. From 37adb94c90454d7b8f8c5ad6671b5edac34c8f39 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 31 Mar 2022 10:15:02 -0500 Subject: [PATCH 4/9] remove a todo --- src/terminal/adapter/InteractDispatch.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/terminal/adapter/InteractDispatch.cpp b/src/terminal/adapter/InteractDispatch.cpp index fe44d0acb02..1f6718dc224 100644 --- a/src/terminal/adapter/InteractDispatch.cpp +++ b/src/terminal/adapter/InteractDispatch.cpp @@ -169,12 +169,18 @@ bool InteractDispatch::IsVtInputEnabled() const return _pConApi->IsVtInputEnabled(); } +// Method Description: +// - Plumbs through to ConGetSet::FocusChanged. See that method for details. +// Arguments: +// - focused: if the terminal is now focused +// Return Value: +// - true always. bool InteractDispatch::FocusChanged(const bool focused) const { - // * We should assume this is false by default? - // * TODO!: ConPTY should ask for this mode? Yea? Lets make sure that VTE will send that sequence even without other mouse sequences enabled. - // - in the past, this is something we've made opt-in (request cursor, for example. Maybe also the other mouse modes, can't recall) - // * gotta make sure that we can always handle the focus events, even if the client hasn't requested them. + // When we do GH#11682, we should make sure that ConPTY requests this mode + // from the terminal when it starts up, and ConPTY never unsets that flag. + // It should only ever internally disable the events from flowing to the + // client application. _pConApi->FocusChanged(focused); return true; } From 172acd2f8b08ecca2d883de77dd2acdaf55bd48b Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 31 Mar 2022 10:20:55 -0500 Subject: [PATCH 5/9] you knew there'd be typos --- src/cascadia/TerminalControl/ControlCore.cpp | 2 +- src/host/outputStream.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 8669f71a374..f8f9748f40f 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1689,7 +1689,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // 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 + // should always request this from the hosting 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. diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index 931e3d44280..63851b59c49 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -913,6 +913,6 @@ void ConhostInternalGetSet::FocusChanged(const bool focused) 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 + // Theoretically, this could be propagated as a focus event as well, to the // input buffer. That should be considered when implementing GH#11682. } From e6e566932cae99e78cc12ca0d122cdc3b422034d Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 13 Apr 2022 12:41:15 -0500 Subject: [PATCH 6/9] what? I always run the tests locally i dunno what you're talking about.... --- src/terminal/adapter/ut_adapter/adapterTest.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 5fb239682a4..15d7caa6358 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -422,6 +422,11 @@ class TestGetSet final : public ConGetSet VERIFY_ARE_EQUAL(_expectedCellSize.cy, cellSize.cy); } + void FocusChanged(const bool /*focused*/) + { + Log::Comment(L"FocusChanged MOCK called..."); + } + void ReparentWindow(const uint64_t /*handle*/) { Log::Comment(L"ReparentWindow MOCK called..."); From 440323d59c477181d49883468c8699e9b243e219 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 13 Apr 2022 14:21:45 -0500 Subject: [PATCH 7/9] this should have always been in this branch --- src/terminal/parser/InputStateMachineEngine.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/terminal/parser/InputStateMachineEngine.cpp b/src/terminal/parser/InputStateMachineEngine.cpp index 2dc695c72c4..7fcec6b92da 100644 --- a/src/terminal/parser/InputStateMachineEngine.cpp +++ b/src/terminal/parser/InputStateMachineEngine.cpp @@ -362,9 +362,14 @@ bool InputStateMachineEngine::ActionCsiDispatch(const VTID id, const VTParameter // win32-input-mode, and if they did, then we'll just translate the // INPUT_RECORD back to the same sequence we say here later on, when the // client reads it. + // + // Focus events in conpty are special, so don't flush those through either. + // See GH#12799, GH#12900 for details if (_pDispatch->IsVtInputEnabled() && _pfnFlushToInputQueue && - id != CsiActionCodes::Win32KeyboardInput) + id != CsiActionCodes::Win32KeyboardInput && + id != CsiActionCodes::FocusIn && + id != CsiActionCodes::FocusOut) { return _pfnFlushToInputQueue(); } From 3b4675c6842575167d5b1b8ddc2635b458e88c24 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 14 Apr 2022 14:41:17 -0500 Subject: [PATCH 8/9] oh my god I've done it again --- src/terminal/parser/ut_parser/InputEngineTest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/terminal/parser/ut_parser/InputEngineTest.cpp b/src/terminal/parser/ut_parser/InputEngineTest.cpp index 0cd5c025e7f..245564577c8 100644 --- a/src/terminal/parser/ut_parser/InputEngineTest.cpp +++ b/src/terminal/parser/ut_parser/InputEngineTest.cpp @@ -332,6 +332,8 @@ class Microsoft::Console::VirtualTerminal::TestInteractDispatch final : public I virtual bool IsVtInputEnabled() const override; + virtual bool FocusChanged(const bool focused) const override; + private: std::function>&)> _pfnWriteInputCallback; TestState* _testState; // non-ownership pointer @@ -399,6 +401,11 @@ bool TestInteractDispatch::IsVtInputEnabled() const return true; } +bool TestInteractDispatch::FocusChanged(const bool /*focused*/) const +{ + return false; +} + void InputEngineTest::C0Test() { auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1); From f71af7861f9cda929e5126d98905e7a1f0d925e1 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 15 Apr 2022 06:26:17 -0500 Subject: [PATCH 9/9] lucky day, these can get moved around now --- src/host/outputStream.cpp | 24 ------------------- src/host/outputStream.hpp | 2 -- src/terminal/adapter/InteractDispatch.cpp | 17 +++++++++++-- src/terminal/adapter/conGetSet.hpp | 2 -- .../adapter/ut_adapter/adapterTest.cpp | 5 ---- 5 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index ca6d77c61d1..3955cfd9350 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -370,30 +370,6 @@ void ConhostInternalGetSet::NotifyAccessibilityChange(const til::rect& changedRe } } -// 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: -// - -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 propagated as a focus event as well, to the - // input buffer. That should be considered when implementing GH#11682. -} - void ConhostInternalGetSet::ReparentWindow(const uint64_t handle) { // This will initialize s_interactivityFactory for us. It will also diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index b55e769acab..1fc1db2cfb1 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -67,8 +67,6 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: void NotifyAccessibilityChange(const til::rect& changedRect) override; - void FocusChanged(const bool focused) override; - void ReparentWindow(const uint64_t handle); private: diff --git a/src/terminal/adapter/InteractDispatch.cpp b/src/terminal/adapter/InteractDispatch.cpp index 24b2a84d2b6..c93092c4102 100644 --- a/src/terminal/adapter/InteractDispatch.cpp +++ b/src/terminal/adapter/InteractDispatch.cpp @@ -183,7 +183,12 @@ bool InteractDispatch::IsVtInputEnabled() const } // Method Description: -// - Plumbs through to ConGetSet::FocusChanged. See that method for details. +// - 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: @@ -194,6 +199,14 @@ bool InteractDispatch::FocusChanged(const bool focused) const // from the terminal when it starts up, and ConPTY never unsets that flag. // It should only ever internally disable the events from flowing to the // client application. - _pConApi->FocusChanged(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 propagated as a focus event as well, to the + // input buffer. That should be considered when implementing GH#11682. + return true; } diff --git a/src/terminal/adapter/conGetSet.hpp b/src/terminal/adapter/conGetSet.hpp index ba6113b789d..8c62e932c93 100644 --- a/src/terminal/adapter/conGetSet.hpp +++ b/src/terminal/adapter/conGetSet.hpp @@ -67,8 +67,6 @@ namespace Microsoft::Console::VirtualTerminal virtual void NotifyAccessibilityChange(const til::rect& changedRect) = 0; - virtual void FocusChanged(const bool focused) = 0; - virtual void ReparentWindow(const uint64_t handle) = 0; }; } diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 3ecacbda3c7..1483429e25b 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -211,11 +211,6 @@ class TestGetSet final : public ConGetSet Log::Comment(L"NotifyAccessibilityChange MOCK called..."); } - void FocusChanged(const bool /*focused*/) - { - Log::Comment(L"FocusChanged MOCK called..."); - } - void ReparentWindow(const uint64_t /*handle*/) { Log::Comment(L"ReparentWindow MOCK called...");