ConPTY: Inject W32IM sequences (#17757)

Does what it says on the tin.

Part of #17737

## Validation Steps Performed
* In WSL run
  `printf "\e[?9001h"; sleep 1; printf "\e[?9001l"; read`
* Wait 1s and press Enter
* Run `showkey -a`
* Esc works 
This commit is contained in:
Leonard Hecker 2024-08-21 18:31:32 +02:00 committed by GitHub
parent 1cb3445834
commit a40a4ea094
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 5 deletions

View File

@ -371,9 +371,10 @@ void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str)
write(offset, injection.offset);
offset = injection.offset;
static constexpr std::array<std::string_view, 2> mapping{ {
static constexpr std::array<std::string_view, 3> mapping{ {
{ "\x1b[?1004h\x1b[?9001h" }, // RIS: Focus Event Mode + Win32 Input Mode
{ "\x1b[?1004h" } // DECSET_FOCUS: Focus Event Mode
{ "\x1b[?1004h" }, // DECSET_FOCUS: Focus Event Mode
{ "\x1b[?9001h" }, // Win32 Input Mode
} };
static_assert(static_cast<size_t>(InjectionType::Count) == mapping.size(), "you need to update the mapping array");

View File

@ -1999,7 +1999,10 @@ bool AdaptDispatch::_ModeParamsHelper(const DispatchTypes::ModeParams param, con
case DispatchTypes::ModeParams::FOCUS_EVENT_MODE:
_terminalInput.SetInputMode(TerminalInput::Mode::FocusEvent, enable);
// ConPTY always wants to know about focus events, so let it know that it needs to re-enable this mode.
_api.GetStateMachine().InjectSequence(InjectionType::DECSET_FOCUS);
if (!enable)
{
_api.GetStateMachine().InjectSequence(InjectionType::DECSET_FOCUS);
}
return true;
case DispatchTypes::ModeParams::ALTERNATE_SCROLL:
_terminalInput.SetInputMode(TerminalInput::Mode::AlternateScroll, enable);
@ -2020,6 +2023,10 @@ bool AdaptDispatch::_ModeParamsHelper(const DispatchTypes::ModeParams param, con
// It also makes more sense to not bubble it up, because this mode is specifically for INPUT_RECORD interop
// and thus entirely between a PTY's input records and its INPUT_RECORD-aware VT-aware console clients.
// Returning true here will mark this as being handled and avoid this.
if (!enable)
{
_api.GetStateMachine().InjectSequence(InjectionType::W32IM);
}
return true;
default:
// If no functions to call, overall dispatch was a failure.

View File

@ -42,8 +42,9 @@ namespace Microsoft::Console::VirtualTerminal
// parser tells it the positions of any such relevant VT sequences.
enum class InjectionType : size_t
{
RIS,
DECSET_FOCUS,
RIS, // All of the below
DECSET_FOCUS, // CSI ? 1004 h
W32IM, // CSI ? 9001 h
Count,
};