Skip to content

Commit

Permalink
ConPTY: Inject W32IM sequences (#17757)
Browse files Browse the repository at this point in the history
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 ✅
  • Loading branch information
lhecker authored Aug 21, 2024
1 parent 1cb3445 commit a40a4ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/host/_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
9 changes: 8 additions & 1 deletion src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/terminal/parser/stateMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit a40a4ea

Please sign in to comment.