Skip to content

Commit

Permalink
Properly mix selection and VTMM story
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Mar 12, 2020
1 parent b483c66 commit 5c720be
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -905,8 +914,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
const auto altEnabled = WI_IsFlagSet(modifiers, static_cast<uint32_t>(VirtualKeyModifiers::Menu));
const auto shiftEnabled = WI_IsFlagSet(modifiers, static_cast<uint32_t>(VirtualKeyModifiers::Shift));

if (_TrySendMouseEvent(point))
if (_CanSendVTMouseInput())
{
_TrySendMouseEvent(point);
args.Handled(true);
return;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -1147,12 +1167,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
const auto ctrlPressed = WI_IsFlagSet(modifiers, static_cast<uint32_t>(VirtualKeyModifiers::Control));
const auto shiftPressed = WI_IsFlagSet(modifiers, static_cast<uint32_t>(VirtualKeyModifiers::Shift));

if (_TrySendMouseEvent(point))
{
args.Handled(true);
return;
}

if (ctrlPressed && shiftPressed)
{
_MouseTransparencyHandler(delta);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ void Terminal::TrySnapOnInput()
}
}

// Routine Description:
// - Relays if we are tracking mouse input
// Parameters:
// - <none>
// 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
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/terminal/input/mouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// - <none>
// 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
Expand Down
2 changes: 2 additions & 0 deletions src/terminal/input/terminalInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c720be

Please sign in to comment.