Skip to content

Commit

Permalink
Reintroduce the check for VT_INPUT_MODE in AdaptDispatch (#6485)
Browse files Browse the repository at this point in the history
This commit reverts the removal of the "SSH hack" in #5383. It was
originally added as a solution to #4911, when we realized that SSH would
request the SS3 cursor key encoding but we weren't equipped to handle
it.

A number of folks have filed issues that, in summary, say "when I use
SSH, I can't select/copy/paste text". It turns out that SSH will _also_
pass through requests for mouse input. Terminal dutifully responds to
those requests, of course, by disabling mouse selection/copy/paste. SSH
is **NOT** actually in VT_INPUT_MODE, so it will never receive the mouse
messages.

It's important to note that even with #376 fixed, we are still required
to keep this check. With the closure of #376, we'll be able to convert
VT mouse input back into Win32 mouse input for Win32 applications . . .
but SSH also doesn't know how to handle Win32 mouse input.

Fixes #6476.
Fixes #6196.
Fixes #5704.
Fixes #5608.

(cherry picked from commit 5e2c4c6)
  • Loading branch information
DHowett committed Jun 24, 2020
1 parent 0dfe1be commit 6ff8ba7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,7 @@ bool AdaptDispatch::SetKeypadMode(const bool fApplicationMode)
bool success = true;
success = _pConApi->PrivateSetKeypadMode(fApplicationMode);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand All @@ -1083,8 +1082,7 @@ bool AdaptDispatch::SetCursorKeysMode(const bool applicationMode)
bool success = true;
success = _pConApi->PrivateSetCursorKeysMode(applicationMode);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand Down Expand Up @@ -1880,8 +1878,7 @@ bool AdaptDispatch::EnableVT200MouseMode(const bool enabled)
bool success = true;
success = _pConApi->PrivateEnableVT200MouseMode(enabled);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand All @@ -1901,8 +1898,7 @@ bool AdaptDispatch::EnableUTF8ExtendedMouseMode(const bool enabled)
bool success = true;
success = _pConApi->PrivateEnableUTF8ExtendedMouseMode(enabled);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand All @@ -1922,8 +1918,7 @@ bool AdaptDispatch::EnableSGRExtendedMouseMode(const bool enabled)
bool success = true;
success = _pConApi->PrivateEnableSGRExtendedMouseMode(enabled);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand All @@ -1942,8 +1937,7 @@ bool AdaptDispatch::EnableButtonEventMouseMode(const bool enabled)
bool success = true;
success = _pConApi->PrivateEnableButtonEventMouseMode(enabled);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand All @@ -1963,8 +1957,7 @@ bool AdaptDispatch::EnableAnyEventMouseMode(const bool enabled)
bool success = true;
success = _pConApi->PrivateEnableAnyEventMouseMode(enabled);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand All @@ -1984,8 +1977,7 @@ bool AdaptDispatch::EnableAlternateScroll(const bool enabled)
bool success = true;
success = _pConApi->PrivateEnableAlternateScroll(enabled);

// If we're a conpty, always return false
if (_pConApi->IsConsolePty())
if (_ShouldPassThroughInputModeChange())
{
return false;
}
Expand Down Expand Up @@ -2181,3 +2173,22 @@ bool AdaptDispatch::WindowManipulation(const DispatchTypes::WindowManipulationTy

return success;
}

// Routine Description:
// - Determines whether we should pass any sequence that manipulates
// TerminalInput's input generator through the PTY. It encapsulates
// a check for whether the PTY is in use.
// Return value:
// True if the request should be passed.
bool AdaptDispatch::_ShouldPassThroughInputModeChange() const
{
// If we're a conpty, AND WE'RE IN VT INPUT MODE, always pass input mode requests
// The VT Input mode check is to work around ssh.exe v7.7, which uses VT
// output, but not Input.
// The original comment said, "Once the conpty supports these types of input,
// this check can be removed. See GH#4911". Unfortunately, time has shown
// us that SSH 7.7 _also_ requests mouse input and that can have a user interface
// impact on the actual connected terminal. We can't remove this check,
// because SSH <=7.7 is out in the wild on all versions of Windows <=2004.
return _pConApi->IsConsolePty() && _pConApi->PrivateIsVtInputEnabled();
}
2 changes: 2 additions & 0 deletions src/terminal/adapter/adaptDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ namespace Microsoft::Console::VirtualTerminal
void _ResetTabStops() noexcept;
void _InitTabStopsForWidth(const size_t width);

bool _ShouldPassThroughInputModeChange() const;

std::vector<bool> _tabStopColumns;
bool _initDefaultTabStops = true;

Expand Down

0 comments on commit 6ff8ba7

Please sign in to comment.