Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Conpty] Pass through request for mouse mode to the Terminal #9970

Merged
9 commits merged into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/host/VtIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ bool VtIo::IsUsingVt() const
{
g.pRender->AddRenderEngine(_pVtRenderEngine.get());
g.getConsoleInformation().GetActiveOutputBuffer().SetTerminalConnection(_pVtRenderEngine.get());
g.getConsoleInformation().GetActiveInputBuffer()->SetTerminalConnection(_pVtRenderEngine.get());
}
CATCH_RETURN();
}
Expand Down
10 changes: 10 additions & 0 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
// ECHO on with LINE off is invalid.
RETURN_HR_IF(E_INVALIDARG, WI_IsFlagSet(mode, ENABLE_ECHO_INPUT) && WI_IsFlagClear(mode, ENABLE_LINE_INPUT));
}
if (WI_IsFlagSet(mode, ENABLE_MOUSE_INPUT))
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
{
gci.GetActiveInputBuffer()->PassThroughEnableButtonEventMouseMode(true);
gci.GetActiveInputBuffer()->PassThroughEnableSGRExtendedMouseMode(true);
Copy link
Contributor Author

@PankajBhojwani PankajBhojwani Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only sending these 2 VT sequences seems to make far manager work, but I am not sure if we should be sending other VT sequences through as well/in different cases (like only button events versus all mouse events), since the console mode only has 1 umbrella ENABLE_MOUSE_INPUT mode and not more specific ones as far as I know

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try if Win32 Vim works? The lacking of mouse support in Win32 Vim is the root cause of several issues. It also drives me to NeoVim personally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want 1003 instead of 1002 -- that's the "any event" mode which includes hover (the win32 event model automatically reports hover!)

}
else
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
{
gci.GetActiveInputBuffer()->PassThroughEnableButtonEventMouseMode(true);
gci.GetActiveInputBuffer()->PassThroughEnableSGRExtendedMouseMode(true);
}

return S_OK;
}
Expand Down
37 changes: 37 additions & 0 deletions src/host/inputBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using Microsoft::Console::Interactivity::ServiceLocator;
using Microsoft::Console::VirtualTerminal::TerminalInput;
using namespace Microsoft::Console;

// Routine Description:
// - This method creates an input buffer.
Expand All @@ -25,6 +26,7 @@ using Microsoft::Console::VirtualTerminal::TerminalInput;
InputBuffer::InputBuffer() :
InputMode{ INPUT_BUFFER_DEFAULT_INPUT_MODE },
WaitQueue{},
_pTtyConnection(nullptr),
_termInput(std::bind(&InputBuffer::_HandleTerminalInputCallback, this, std::placeholders::_1))
{
// The _termInput's constructor takes a reference to this object's _HandleTerminalInputCallback.
Expand Down Expand Up @@ -218,6 +220,41 @@ void InputBuffer::FlushAllButKeys()
_storage.erase(newEnd, _storage.end());
}

void InputBuffer::SetTerminalConnection(_In_ ITerminalOutputConnection* const pTtyConnection)
{
this->_pTtyConnection = pTtyConnection;
}

void InputBuffer::PassThroughEnableButtonEventMouseMode(bool enable)
{
if (_pTtyConnection)
{
if (enable)
{
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1002h"));
}
else
{
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1002l"));
}
}
}

void InputBuffer::PassThroughEnableSGRExtendedMouseMode(bool enable)
{
if (_pTtyConnection)
{
if (enable)
{
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1006h"));
}
else
{
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1006l"));
}
}
}

// Routine Description:
// - This routine reads from the input buffer.
// - It can convert returned data to through the currently set Input CP, it can optionally return a wait condition
Expand Down
6 changes: 6 additions & 0 deletions src/host/inputBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Revision History:
#include "../server/ObjectHeader.h"
#include "../terminal/input/terminalInput.hpp"

#include "../inc/ITerminalOutputConnection.hpp"

#include <deque>

class InputBuffer final : public ConsoleObjectHeader
Expand Down Expand Up @@ -75,12 +77,16 @@ class InputBuffer final : public ConsoleObjectHeader

bool IsInVirtualTerminalInputMode() const;
Microsoft::Console::VirtualTerminal::TerminalInput& GetTerminalInput();
void SetTerminalConnection(_In_ Microsoft::Console::ITerminalOutputConnection* const pTtyConnection);
void PassThroughEnableButtonEventMouseMode(bool enable);
void PassThroughEnableSGRExtendedMouseMode(bool enable);
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

private:
std::deque<std::unique_ptr<IInputEvent>> _storage;
std::unique_ptr<IInputEvent> _readPartialByteSequence;
std::unique_ptr<IInputEvent> _writePartialByteSequence;
Microsoft::Console::VirtualTerminal::TerminalInput _termInput;
Microsoft::Console::ITerminalOutputConnection* _pTtyConnection;

// This flag is used in _HandleTerminalInputCallback
// If the InputBuffer leads to a _HandleTerminalInputCallback call,
Expand Down