Skip to content

Commit

Permalink
clean up TrySendMouseEvent and other PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Mar 10, 2020
1 parent fcd2cad commit 7184a01
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 51 deletions.
60 changes: 44 additions & 16 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<short>(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);
}
Expand Down Expand Up @@ -1073,7 +1095,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// macro directly with a VirtualKeyModifiers
const auto shiftEnabled = WI_IsFlagSet(modifiers, static_cast<uint32_t>(VirtualKeyModifiers::Shift));

if (_TrySendMouseEvent(point, true))
if (_TrySendMouseEvent(point, false))
{
args.Handled(true);
return;
Expand Down Expand Up @@ -1121,6 +1143,12 @@ 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, true))
{
args.Handled(true);
return;
}

if (ctrlPressed && shiftPressed)
{
_MouseTransparencyHandler(delta);
Expand Down
4 changes: 1 addition & 3 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
32 changes: 0 additions & 32 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 7184a01

Please sign in to comment.