Skip to content

Commit e326ed1

Browse files
committed
Add support for horizontal mouse wheel events
This adds support for horizontal mouse wheel events (WM_MOUSEHWHEEL). With this change, applications running in the terminal can now receive and respond to horizontal scroll inputs from the mouse/trackpad. Fixes: #19245
1 parent 1b2aad6 commit e326ed1

File tree

17 files changed

+72
-27
lines changed

17 files changed

+72
-27
lines changed

src/cascadia/TerminalControl/ControlInteractivity.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
485485
// - modifiers: The modifiers pressed during this event, in the form of a VirtualKeyModifiers
486486
// - delta: the mouse wheel delta that triggered this event.
487487
bool ControlInteractivity::MouseWheel(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
488+
const bool horizontal,
488489
const int32_t delta,
489490
const Core::Point pixelPosition,
490491
const Control::MouseButtonState buttonState)
@@ -506,7 +507,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
506507
// PointerPoint to work with. So, we're just going to do a
507508
// mousewheel event manually
508509
return _sendMouseEventHelper(terminalPosition,
509-
WM_MOUSEWHEEL,
510+
horizontal ? WM_MOUSEHWHEEL : WM_MOUSEWHEEL,
510511
modifiers,
511512
::base::saturated_cast<short>(delta),
512513
buttonState);
@@ -667,7 +668,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
667668
{
668669
return false;
669670
}
670-
return _core->ShouldSendAlternateScroll(WM_MOUSEWHEEL, delta);
671+
return _core->ShouldSendAlternateScroll(WM_MOUSEWHEEL, delta) || _core->ShouldSendAlternateScroll(WM_MOUSEHWHEEL, delta);
671672
}
672673

673674
// Method Description:

src/cascadia/TerminalControl/ControlInteractivity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
7474
void TouchReleased();
7575

7676
bool MouseWheel(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
77+
const bool horizontal,
7778
const int32_t delta,
7879
const Core::Point pixelPosition,
7980
const Control::MouseButtonState state);

src/cascadia/TerminalControl/ControlInteractivity.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace Microsoft.Terminal.Control
6060
void TouchReleased();
6161

6262
Boolean MouseWheel(Microsoft.Terminal.Core.ControlKeyStates modifiers,
63+
Boolean horizontal,
6364
Int32 delta,
6465
Microsoft.Terminal.Core.Point pixelPosition,
6566
MouseButtonState state);

src/cascadia/TerminalControl/IMouseWheelListener.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ namespace Microsoft.Terminal.Control
1111
[uuid("65b8b8c5-988f-43ff-aba9-e89368da1598")]
1212
interface IMouseWheelListener
1313
{
14-
Boolean OnMouseWheel(Windows.Foundation.Point coord, Int32 delta, Boolean leftButtonDown, Boolean midButtonDown, Boolean rightButtonDown);
14+
Boolean OnMouseWheel(Windows.Foundation.Point coord, Boolean horizontal, Int32 delta, Boolean leftButtonDown, Boolean midButtonDown, Boolean rightButtonDown);
1515
}
1616
}

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,14 +2164,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
21642164
RestorePointerCursor.raise(*this, nullptr);
21652165

21662166
const auto point = args.GetCurrentPoint(*this);
2167-
// GH#10329 - we don't need to handle horizontal scrolls. Only vertical ones.
2168-
// So filter out the horizontal ones.
2169-
if (point.Properties().IsHorizontalMouseWheel())
2170-
{
2171-
return;
2172-
}
2173-
21742167
auto result = _interactivity.MouseWheel(ControlKeyStates{ args.KeyModifiers() },
2168+
point.Properties().IsHorizontalMouseWheel(),
21752169
point.Properties().MouseWheelDelta(),
21762170
_toTerminalOrigin(point.Position()),
21772171
TermControl::GetPressedMouseButtons(point));
@@ -2192,6 +2186,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
21922186
// - delta: the mouse wheel delta that triggered this event.
21932187
// - state: the state for each of the mouse buttons individually (pressed/unpressed)
21942188
bool TermControl::OnMouseWheel(const Windows::Foundation::Point location,
2189+
const bool horizontal,
21952190
const int32_t delta,
21962191
const bool leftButtonDown,
21972192
const bool midButtonDown,
@@ -2204,7 +2199,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
22042199
WI_SetFlagIf(state, Control::MouseButtonState::IsMiddleButtonDown, midButtonDown);
22052200
WI_SetFlagIf(state, Control::MouseButtonState::IsRightButtonDown, rightButtonDown);
22062201

2207-
return _interactivity.MouseWheel(modifiers, delta, _toTerminalOrigin(location), state);
2202+
return _interactivity.MouseWheel(modifiers, horizontal, delta, _toTerminalOrigin(location), state);
22082203
}
22092204

22102205
// Method Description:

src/cascadia/TerminalControl/TermControl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
147147

148148
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);
149149

150-
bool OnMouseWheel(const Windows::Foundation::Point location, const int32_t delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);
150+
bool OnMouseWheel(const Windows::Foundation::Point location, const bool horizontal, const int32_t delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);
151151

152152
~TermControl();
153153

src/cascadia/WindowsTerminal/AppHost.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ void AppHost::_RaiseVisualBell(const winrt::Windows::Foundation::IInspectable&,
745745
// - delta: the wheel delta that triggered this event.
746746
// Return Value:
747747
// - <none>
748-
void AppHost::_WindowMouseWheeled(const winrt::Windows::Foundation::Point coord, const int32_t delta)
748+
void AppHost::_WindowMouseWheeled(const winrt::Windows::Foundation::Point coord, const int32_t delta, const bool horizontal)
749749
{
750750
if (_windowLogic)
751751
{
@@ -772,7 +772,7 @@ void AppHost::_WindowMouseWheeled(const winrt::Windows::Foundation::Point coord,
772772
const auto mButtonDown = WI_IsFlagSet(GetKeyState(VK_MBUTTON), KeyPressed);
773773
const auto rButtonDown = WI_IsFlagSet(GetKeyState(VK_RBUTTON), KeyPressed);
774774

775-
if (control.OnMouseWheel(offsetPoint, delta, lButtonDown, mButtonDown, rButtonDown))
775+
if (control.OnMouseWheel(offsetPoint, horizontal, delta, lButtonDown, mButtonDown, rButtonDown))
776776
{
777777
// If the element handled the mouse wheel event, don't
778778
// continue to iterate over the remaining controls.

src/cascadia/WindowsTerminal/AppHost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class AppHost : public std::enable_shared_from_this<AppHost>
7373

7474
void _RaiseVisualBell(const winrt::Windows::Foundation::IInspectable& sender,
7575
const winrt::Windows::Foundation::IInspectable& arg);
76-
void _WindowMouseWheeled(const winrt::Windows::Foundation::Point coord, const int32_t delta);
76+
void _WindowMouseWheeled(const winrt::Windows::Foundation::Point coord, const int32_t delta, const bool horizontal);
7777
void _WindowActivated(bool activated);
7878
void _WindowMoved();
7979

src/cascadia/WindowsTerminal/IslandWindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ void IslandWindow::_OnGetMinMaxInfo(const WPARAM /*wParam*/, const LPARAM lParam
595595
WindowCloseButtonClicked.raise();
596596
return 0;
597597
}
598+
case WM_MOUSEHWHEEL:
598599
case WM_MOUSEWHEEL:
599600
try
600601
{
@@ -626,7 +627,7 @@ void IslandWindow::_OnGetMinMaxInfo(const WPARAM /*wParam*/, const LPARAM lParam
626627
const auto wheelDelta = static_cast<short>(HIWORD(wparam));
627628

628629
// Raise an event, so any listeners can handle the mouse wheel event manually.
629-
MouseScrolled.raise(real, wheelDelta);
630+
MouseScrolled.raise(real, wheelDelta, message == WM_MOUSEHWHEEL);
630631
return 0;
631632
}
632633
CATCH_LOG();

src/cascadia/WindowsTerminal/IslandWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class IslandWindow :
7474

7575
til::event<winrt::delegate<>> DragRegionClicked;
7676
til::event<winrt::delegate<>> WindowCloseButtonClicked;
77-
til::event<winrt::delegate<void(winrt::Windows::Foundation::Point, int32_t)>> MouseScrolled;
77+
til::event<winrt::delegate<void(winrt::Windows::Foundation::Point, int32_t, bool)>> MouseScrolled;
7878
til::event<winrt::delegate<void(bool)>> WindowActivated;
7979
til::event<winrt::delegate<void()>> NotifyNotificationIconPressed;
8080
til::event<winrt::delegate<void()>> NotifyWindowHidden;

0 commit comments

Comments
 (0)