diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 7cb506a7c47..ee4e9020ba3 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -820,14 +820,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // - point: the PointerPoint object representing a mouse event from our XAML input handler bool TermControl::_TrySendMouseEvent(Windows::UI::Input::PointerPoint const& point) { - // 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 @@ -867,9 +859,26 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation uiButton = WM_MOUSEWHEEL; } + const auto modifiers = _GetPressedModifierKeys(); return _terminal->SendMouseEvent(terminalPosition, uiButton, modifiers, sWheelDelta); } + // Method Description: + // - Checks if we can send vt mouse input. + // Arguments: + // - point: the PointerPoint object representing a mouse event from our XAML input handler + bool TermControl::_CanSendVTMouseInput() + { + // 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; + } + return _terminal->IsTrackingMouseInput(); + } + // Method Description: // - handle a mouse click event. Begin selection process. // Arguments: @@ -905,8 +914,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation const auto altEnabled = WI_IsFlagSet(modifiers, static_cast(VirtualKeyModifiers::Menu)); const auto shiftEnabled = WI_IsFlagSet(modifiers, static_cast(VirtualKeyModifiers::Shift)); - if (_TrySendMouseEvent(point)) + if (_CanSendVTMouseInput()) { + _TrySendMouseEvent(point); args.Handled(true); return; } @@ -999,8 +1009,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation if (ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse || ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Pen) { - if (_TrySendMouseEvent(point)) + if (_CanSendVTMouseInput()) { + _TrySendMouseEvent(point); args.Handled(true); return; } @@ -1091,8 +1102,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation if (ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse || ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Pen) { - if (_TrySendMouseEvent(point)) + if (_CanSendVTMouseInput()) { + _TrySendMouseEvent(point); args.Handled(true); return; } @@ -1138,6 +1150,14 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation Input::PointerRoutedEventArgs const& args) { const auto point = args.GetCurrentPoint(*this); + + if (_CanSendVTMouseInput()) + { + _TrySendMouseEvent(point); + args.Handled(true); + return; + } + const auto delta = point.Properties().MouseWheelDelta(); // Get the state of the Ctrl & Shift keys @@ -1147,12 +1167,6 @@ 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)) - { - args.Handled(true); - return; - } - if (ctrlPressed && shiftPressed) { _MouseTransparencyHandler(delta); diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 57518296f8e..57606506bee 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -212,6 +212,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation ::Microsoft::Terminal::Core::ControlKeyStates _GetPressedModifierKeys() const; bool _TrySendKeyEvent(const WORD vkey, const WORD scanCode, ::Microsoft::Terminal::Core::ControlKeyStates modifiers); bool _TrySendMouseEvent(Windows::UI::Input::PointerPoint const& point); + bool _CanSendVTMouseInput(); const COORD _GetTerminalPosition(winrt::Windows::Foundation::Point cursorPosition); const unsigned int _NumberOfClicks(winrt::Windows::Foundation::Point clickPos, Timestamp clickTime); diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index cab140eecd7..fb15bb59e55 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -222,6 +222,17 @@ void Terminal::TrySnapOnInput() } } +// Routine Description: +// - Relays if we are tracking mouse input +// Parameters: +// - +// Return value: +// - true, if we are tracking mouse input. False, otherwise +bool Terminal::IsTrackingMouseInput() const +{ + return _terminalInput->IsTrackingMouseInput(); +} + // Method Description: // - Send this particular key event to the terminal. The terminal will translate // the key and the modifiers pressed into the appropriate VT sequence for that diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 3ab121acf9f..6c7583349fe 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -119,6 +119,7 @@ class Microsoft::Terminal::Core::Terminal final : int GetScrollOffset() noexcept override; void TrySnapOnInput() override; + bool IsTrackingMouseInput() const; #pragma endregion #pragma region IBaseData(base to IRenderData and IUiaData) diff --git a/src/terminal/input/mouseInput.cpp b/src/terminal/input/mouseInput.cpp index 88c8ad2e64a..03fd089cb59 100644 --- a/src/terminal/input/mouseInput.cpp +++ b/src/terminal/input/mouseInput.cpp @@ -264,6 +264,17 @@ static constexpr short _encodeDefaultCoordinate(const short sCoordinateValue) no return sCoordinateValue + 32; } +// Routine Description: +// - Relays if we are tracking mouse input +// Parameters: +// - +// Return value: +// - true, if we are tracking mouse input. False, otherwise +bool TerminalInput::IsTrackingMouseInput() const +{ + return (_mouseInputState.trackingMode != TrackingMode::None); +} + // Routine Description: // - Attempt to handle the given mouse coordinates and windows button as a VT-style mouse event. // If the event should be transmitted in the selected mouse mode, then we'll try and diff --git a/src/terminal/input/terminalInput.hpp b/src/terminal/input/terminalInput.hpp index b0b5860c128..b0108ce8e20 100644 --- a/src/terminal/input/terminalInput.hpp +++ b/src/terminal/input/terminalInput.hpp @@ -44,6 +44,8 @@ namespace Microsoft::Console::VirtualTerminal const unsigned int button, const short modifierKeyState, const short delta); + + bool IsTrackingMouseInput() const; #pragma endregion #pragma region MouseInputState Management