From 98a2fbf98d4239251d11435b9391066c9a3c1d05 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 10 Mar 2020 16:00:35 -0700 Subject: [PATCH] clean up TrySendMouseEvent and other PR comments --- src/cascadia/TerminalControl/TermControl.cpp | 60 ++++++++++++++----- src/cascadia/TerminalCore/Terminal.cpp | 4 +- src/cascadia/TerminalCore/TerminalApi.cpp | 2 + .../TerminalCore/TerminalDispatch.cpp | 32 ---------- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index d846a3c797cd..242525bcd327 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -21,6 +21,7 @@ using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml::Input; using namespace winrt::Windows::UI::Xaml::Automation::Peers; using namespace winrt::Windows::UI::Core; +using namespace winrt::Windows::UI::Input; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Terminal::Settings; using namespace winrt::Windows::ApplicationModel::DataTransfer; @@ -817,34 +818,55 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // Arguments: // - point: the PointerPoint object representing a mouse event from our XAML input handler // - goingDown: true, if the button was pressed. False, if it was released. + // Mouse moved events must only be encoded as the button being pressed, not released. bool TermControl::_TrySendMouseEvent(Windows::UI::Input::PointerPoint const& point, bool goingDown) { + // If the user is holding down Shift, suppress mouse events + // TODO GH#4875: disable/customize this functionality + const auto modifiers = _GetPressedModifierKeys(); + if (modifiers.IsShiftPressed()) + { + return false; + } + const auto props = point.Properties(); // Get the terminal position relative to the viewport const auto terminalPosition = _GetTerminalPosition(point.Position()); - // Which mouse buttons were pressed + // Which mouse button changed state (and how) unsigned int uiButton{}; - - if (props.IsLeftButtonPressed()) + switch (props.PointerUpdateKind()) { - uiButton = goingDown ? WM_LBUTTONDOWN : WM_LBUTTONUP; - } - else if (props.IsMiddleButtonPressed()) - { - uiButton = goingDown ? WM_MBUTTONDOWN : WM_MBUTTONUP; - } - else if (props.IsRightButtonPressed()) - { - uiButton = goingDown ? WM_RBUTTONDOWN : WM_RBUTTONUP; + case PointerUpdateKind::LeftButtonPressed: + uiButton = WM_LBUTTONDOWN; + break; + case PointerUpdateKind::LeftButtonReleased: + uiButton = WM_LBUTTONUP; + break; + case PointerUpdateKind::MiddleButtonPressed: + uiButton = WM_MBUTTONDOWN; + break; + case PointerUpdateKind::MiddleButtonReleased: + uiButton = WM_MBUTTONUP; + break; + case PointerUpdateKind::RightButtonPressed: + uiButton = WM_RBUTTONDOWN; + break; + case PointerUpdateKind::RightButtonReleased: + uiButton = WM_RBUTTONUP; + break; + default: + uiButton = WM_MOUSEMOVE; } - // Which modifier keys are pressed - const auto modifiers = _GetPressedModifierKeys(); - // Mouse wheel data const short sWheelDelta = ::base::saturated_cast(props.MouseWheelDelta()); + if (sWheelDelta != 0 && !props.IsHorizontalMouseWheel()) + { + // if we have a mouse wheel delta and it wasn't a horizontal wheel motion + uiButton = WM_MOUSEWHEEL; + } return _terminal->SendMouseEvent(terminalPosition, uiButton, modifiers, sWheelDelta); } @@ -1073,7 +1095,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // macro directly with a VirtualKeyModifiers const auto shiftEnabled = WI_IsFlagSet(modifiers, static_cast(VirtualKeyModifiers::Shift)); - if (_TrySendMouseEvent(point, true)) + if (_TrySendMouseEvent(point, false)) { args.Handled(true); return; @@ -1121,6 +1143,12 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation const auto ctrlPressed = WI_IsFlagSet(modifiers, static_cast(VirtualKeyModifiers::Control)); const auto shiftPressed = WI_IsFlagSet(modifiers, static_cast(VirtualKeyModifiers::Shift)); + if (_TrySendMouseEvent(point, true)) + { + args.Handled(true); + return; + } + if (ctrlPressed && shiftPressed) { _MouseTransparencyHandler(delta); diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index ecc787c28e26..bd66807e6cec 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -300,9 +300,7 @@ bool Terminal::SendKeyEvent(const WORD vkey, const WORD scanCode, const ControlK // - false if we did not translate the key, and it should be processed into a character. bool Terminal::SendMouseEvent(const COORD viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta) { - const COORD bufferPos = _ConvertToBufferCell(viewportPos); - - return _terminalInput->HandleMouse(bufferPos, uiButton, GET_KEYSTATE_WPARAM(states.Value()), wheelDelta); + return _terminalInput->HandleMouse(viewportPos, uiButton, GET_KEYSTATE_WPARAM(states.Value()), wheelDelta); } bool Terminal::SendCharEvent(const wchar_t ch) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 22e7765dbbb3..75d0198c88d0 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -565,5 +565,7 @@ bool Terminal::EnableAlternateScrollMode(const bool enabled) noexcept bool Terminal::IsVtInputEnabled() const noexcept { + // We should never be getting this call in Terminal. + FAIL_FAST(); return true; } diff --git a/src/cascadia/TerminalCore/TerminalDispatch.cpp b/src/cascadia/TerminalCore/TerminalDispatch.cpp index 3a9f698893a3..a854bc1028a7 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.cpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.cpp @@ -221,10 +221,6 @@ CATCH_LOG_RETURN_FALSE() // - True if handled successfully. False otherwise. bool TerminalDispatch::SetKeypadMode(const bool fApplicationMode) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.SetKeypadMode(fApplicationMode); return false; } @@ -236,10 +232,6 @@ bool TerminalDispatch::SetKeypadMode(const bool fApplicationMode) noexcept // - True if handled successfully. False otherwise. bool TerminalDispatch::SetCursorKeysMode(const bool applicationMode) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.SetCursorKeysMode(applicationMode); return false; } @@ -252,10 +244,6 @@ bool TerminalDispatch::SetCursorKeysMode(const bool applicationMode) noexcept // True if handled successfully. False otherwise. bool TerminalDispatch::EnableVT200MouseMode(const bool enabled) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.EnableVT200MouseMode(enabled); return false; } @@ -269,10 +257,6 @@ bool TerminalDispatch::EnableVT200MouseMode(const bool enabled) noexcept // True if handled successfully. False otherwise. bool TerminalDispatch::EnableUTF8ExtendedMouseMode(const bool enabled) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.EnableUTF8ExtendedMouseMode(enabled); return false; } @@ -286,10 +270,6 @@ bool TerminalDispatch::EnableUTF8ExtendedMouseMode(const bool enabled) noexcept // True if handled successfully. False otherwise. bool TerminalDispatch::EnableSGRExtendedMouseMode(const bool enabled) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.EnableSGRExtendedMouseMode(enabled); return false; } @@ -302,10 +282,6 @@ bool TerminalDispatch::EnableSGRExtendedMouseMode(const bool enabled) noexcept // True if handled successfully. False otherwise. bool TerminalDispatch::EnableButtonEventMouseMode(const bool enabled) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.EnableButtonEventMouseMode(enabled); return false; } @@ -319,10 +295,6 @@ bool TerminalDispatch::EnableButtonEventMouseMode(const bool enabled) noexcept // True if handled successfully. False otherwise. bool TerminalDispatch::EnableAnyEventMouseMode(const bool enabled) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.EnableAnyEventMouseMode(enabled); return false; } @@ -336,10 +308,6 @@ bool TerminalDispatch::EnableAnyEventMouseMode(const bool enabled) noexcept // True if handled successfully. False otherwise. bool TerminalDispatch::EnableAlternateScroll(const bool enabled) noexcept { - // TODO GH#XXXX: - // This is a temporary replacement to enable passhthrough - // mode for Windows Terminal. Replace with proper _pConApi - // call below when ConPty has been properly updated. _terminalApi.EnableAlternateScrollMode(enabled); return false; }