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 7 commits
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
13 changes: 13 additions & 0 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
LockConsole();
auto Unlock = wil::scope_exit([&] { UnlockConsole(); });

const auto oldQuickEditMode{ WI_IsFlagSet(gci.Flags, CONSOLE_QUICK_EDIT_MODE) };

if (WI_IsAnyFlagSet(mode, PRIVATE_MODES))
{
WI_SetFlag(gci.Flags, CONSOLE_USE_PRIVATE_FLAGS);
Expand All @@ -357,6 +359,17 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
WI_ClearFlag(gci.Flags, CONSOLE_USE_PRIVATE_FLAGS);
}

const auto newQuickEditMode{ WI_IsFlagSet(gci.Flags, CONSOLE_QUICK_EDIT_MODE) };
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

// Mouse input should be received when mouse mode is on and quick edit mode is off
const auto oldMouseMode{ !oldQuickEditMode && WI_IsFlagSet(context.InputMode, ENABLE_MOUSE_INPUT) };
const auto newMouseMode{ !newQuickEditMode && WI_IsFlagSet(mode, ENABLE_MOUSE_INPUT) };

if (oldMouseMode != newMouseMode)
{
gci.GetActiveInputBuffer()->PassThroughWin32MouseRequest(newMouseMode);
}

context.InputMode = mode;
WI_ClearAllFlags(context.InputMode, PRIVATE_MODES);

Expand Down
24 changes: 24 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,28 @@ void InputBuffer::FlushAllButKeys()
_storage.erase(newEnd, _storage.end());
}

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

void InputBuffer::PassThroughWin32MouseRequest(bool enable)
{
if (_pTtyConnection)
{
if (enable)
{
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1003h"));
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1006h"));
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
LOG_IF_FAILED(_pTtyConnection->WriteTerminalW(L"\x1b[?1003l"));
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
5 changes: 5 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,15 @@ class InputBuffer final : public ConsoleObjectHeader

bool IsInVirtualTerminalInputMode() const;
Microsoft::Console::VirtualTerminal::TerminalInput& GetTerminalInput();
void SetTerminalConnection(_In_ Microsoft::Console::ITerminalOutputConnection* const pTtyConnection);
void PassThroughWin32MouseRequest(bool enable);

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