Skip to content

Commit cc95e48

Browse files
committed
Use Core.Point for mouse wheel delta
1 parent 4d7ddb4 commit cc95e48

File tree

11 files changed

+64
-66
lines changed

11 files changed

+64
-66
lines changed

src/cascadia/TerminalControl/ControlInteractivity.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +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,
489-
const int32_t delta,
488+
const Core::Point delta,
490489
const Core::Point pixelPosition,
491490
const Control::MouseButtonState buttonState)
492491
{
@@ -507,9 +506,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
507506
// PointerPoint to work with. So, we're just going to do a
508507
// mousewheel event manually
509508
return _sendMouseEventHelper(terminalPosition,
510-
horizontal ? WM_MOUSEHWHEEL : WM_MOUSEWHEEL,
509+
delta.X != 0 ? WM_MOUSEHWHEEL : WM_MOUSEWHEEL,
511510
modifiers,
512-
::base::saturated_cast<short>(delta),
511+
::base::saturated_cast<short>(delta.X != 0 ? delta.X : delta.Y),
513512
buttonState);
514513
}
515514

@@ -518,15 +517,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
518517

519518
if (ctrlPressed && shiftPressed && _core->Settings().ScrollToChangeOpacity())
520519
{
521-
_mouseTransparencyHandler(delta);
520+
_mouseTransparencyHandler(delta.X != 0 ? delta.X : delta.Y);
522521
}
523522
else if (ctrlPressed && !shiftPressed && _core->Settings().ScrollToZoom())
524523
{
525-
_mouseZoomHandler(delta);
524+
_mouseZoomHandler(delta.X != 0 ? delta.X : delta.Y);
526525
}
527526
else
528527
{
529-
_mouseScrollHandler(delta, pixelPosition, WI_IsFlagSet(buttonState, MouseButtonState::IsLeftButtonDown));
528+
_mouseScrollHandler(delta.X != 0 ? delta.X : delta.Y, pixelPosition, WI_IsFlagSet(buttonState, MouseButtonState::IsLeftButtonDown));
530529
}
531530
return false;
532531
}
@@ -660,15 +659,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation
660659
return _core->IsVtMouseModeEnabled();
661660
}
662661

663-
bool ControlInteractivity::_shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const int32_t delta)
662+
bool ControlInteractivity::_shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const Core::Point delta)
664663
{
665664
// If the user is holding down Shift, suppress mouse events
666665
// TODO GH#4875: disable/customize this functionality
667666
if (modifiers.IsShiftPressed())
668667
{
669668
return false;
670669
}
671-
return _core->ShouldSendAlternateScroll(WM_MOUSEWHEEL, delta) || _core->ShouldSendAlternateScroll(WM_MOUSEHWHEEL, delta);
670+
if (delta.X != 0)
671+
{
672+
return _core->ShouldSendAlternateScroll(WM_MOUSEHWHEEL, delta.X);
673+
}
674+
else
675+
{
676+
return _core->ShouldSendAlternateScroll(WM_MOUSEWHEEL, delta.Y);
677+
}
672678
}
673679

674680
// Method Description:

src/cascadia/TerminalControl/ControlInteractivity.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +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,
78-
const int32_t delta,
77+
const Core::Point delta,
7978
const Core::Point pixelPosition,
8079
const Control::MouseButtonState state);
8180

@@ -154,7 +153,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
154153

155154
void _hyperlinkHandler(const std::wstring_view uri);
156155
bool _canSendVTMouseInput(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers);
157-
bool _shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const int32_t delta);
156+
bool _shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const Core::Point delta);
158157

159158
til::point _getTerminalPosition(const til::point pixelPosition, bool roundToNearestCell);
160159

src/cascadia/TerminalControl/ControlInteractivity.idl

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

6262
Boolean MouseWheel(Microsoft.Terminal.Core.ControlKeyStates modifiers,
63-
Boolean horizontal,
64-
Int32 delta,
63+
Microsoft.Terminal.Core.Point delta,
6564
Microsoft.Terminal.Core.Point pixelPosition,
6665
MouseButtonState state);
6766

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, Boolean horizontal, Int32 delta, Boolean leftButtonDown, Boolean midButtonDown, Boolean rightButtonDown);
14+
Boolean OnMouseWheel(Windows.Foundation.Point coord, Microsoft.Terminal.Core.Point delta, Boolean leftButtonDown, Boolean midButtonDown, Boolean rightButtonDown);
1515
}
1616
}

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,9 +2160,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
21602160
RestorePointerCursor.raise(*this, nullptr);
21612161

21622162
const auto point = args.GetCurrentPoint(*this);
2163+
auto delta = point.Properties().MouseWheelDelta();
21632164
auto result = _interactivity.MouseWheel(ControlKeyStates{ args.KeyModifiers() },
2164-
point.Properties().IsHorizontalMouseWheel(),
2165-
point.Properties().MouseWheelDelta(),
2165+
point.Properties().IsHorizontalMouseWheel() ?
2166+
Core::Point{ delta, 0 } : Core::Point{ 0, delta },
21662167
_toTerminalOrigin(point.Position()),
21672168
TermControl::GetPressedMouseButtons(point));
21682169
if (result)
@@ -2182,8 +2183,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
21822183
// - delta: the mouse wheel delta that triggered this event.
21832184
// - state: the state for each of the mouse buttons individually (pressed/unpressed)
21842185
bool TermControl::OnMouseWheel(const Windows::Foundation::Point location,
2185-
const bool horizontal,
2186-
const int32_t delta,
2186+
const Core::Point delta,
21872187
const bool leftButtonDown,
21882188
const bool midButtonDown,
21892189
const bool rightButtonDown)
@@ -2195,7 +2195,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
21952195
WI_SetFlagIf(state, Control::MouseButtonState::IsMiddleButtonDown, midButtonDown);
21962196
WI_SetFlagIf(state, Control::MouseButtonState::IsRightButtonDown, rightButtonDown);
21972197

2198-
return _interactivity.MouseWheel(modifiers, horizontal, delta, _toTerminalOrigin(location), state);
2198+
return _interactivity.MouseWheel(modifiers, delta, _toTerminalOrigin(location), state);
21992199
}
22002200

22012201
// Method Description:

src/cascadia/TerminalControl/TermControl.h

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

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

151-
bool OnMouseWheel(const Windows::Foundation::Point location, const bool horizontal, const int32_t delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);
151+
bool OnMouseWheel(const Windows::Foundation::Point location, const winrt::Microsoft::Terminal::Core::Point delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);
152152

153153
~TermControl();
154154

src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ namespace ControlUnitTests
170170

171171
// The mouse location and buttons don't matter here.
172172
interactivity->MouseWheel(modifiers,
173-
false,
174-
30,
173+
Core::Point{ 30, 0 },
175174
Core::Point{ 0, 0 },
176175
buttonState);
177176
}
@@ -189,8 +188,7 @@ namespace ControlUnitTests
189188

190189
// The mouse location and buttons don't matter here.
191190
interactivity->MouseWheel(modifiers,
192-
false,
193-
-30,
191+
Core::Point{ -30, 0 },
194192
Core::Point{ 0, 0 },
195193
buttonState);
196194
}
@@ -247,8 +245,7 @@ namespace ControlUnitTests
247245
expectedTop = 20;
248246

249247
interactivity->MouseWheel(modifiers,
250-
false,
251-
WHEEL_DELTA,
248+
Core::Point{ WHEEL_DELTA, 0 },
252249
Core::Point{ 0, 0 },
253250
buttonState);
254251

@@ -257,21 +254,18 @@ namespace ControlUnitTests
257254
{
258255
expectedTop--;
259256
interactivity->MouseWheel(modifiers,
260-
false,
261-
WHEEL_DELTA,
257+
Core::Point{ WHEEL_DELTA, 0 },
262258
Core::Point{ 0, 0 },
263259
buttonState);
264260
}
265261
Log::Comment(L"Scrolling up more should do nothing");
266262
expectedTop = 0;
267263
interactivity->MouseWheel(modifiers,
268-
false,
269-
WHEEL_DELTA,
264+
Core::Point{ WHEEL_DELTA, 0 },
270265
Core::Point{ 0, 0 },
271266
buttonState);
272267
interactivity->MouseWheel(modifiers,
273-
false,
274-
WHEEL_DELTA,
268+
Core::Point{ WHEEL_DELTA, 0 },
275269
Core::Point{ 0, 0 },
276270
buttonState);
277271

@@ -281,22 +275,19 @@ namespace ControlUnitTests
281275
Log::Comment(NoThrowString().Format(L"---scroll down #%d---", i));
282276
expectedTop++;
283277
interactivity->MouseWheel(modifiers,
284-
false,
285-
-WHEEL_DELTA,
278+
Core::Point{ -WHEEL_DELTA, 0 },
286279
Core::Point{ 0, 0 },
287280
buttonState);
288281
Log::Comment(NoThrowString().Format(L"internal scrollbar pos:%f", interactivity->_internalScrollbarPosition));
289282
}
290283
Log::Comment(L"Scrolling down more should do nothing");
291284
expectedTop = 21;
292285
interactivity->MouseWheel(modifiers,
293-
false,
294-
-WHEEL_DELTA,
286+
Core::Point{ -WHEEL_DELTA, 0 },
295287
Core::Point{ 0, 0 },
296288
buttonState);
297289
interactivity->MouseWheel(modifiers,
298-
false,
299-
-WHEEL_DELTA,
290+
Core::Point{ -WHEEL_DELTA, 0 },
300291
Core::Point{ 0, 0 },
301292
buttonState);
302293
}
@@ -453,8 +444,7 @@ namespace ControlUnitTests
453444

454445
Log::Comment(L"Scroll up a line, with the left mouse button selected");
455446
interactivity->MouseWheel(modifiers,
456-
false,
457-
WHEEL_DELTA,
447+
Core::Point{ WHEEL_DELTA, 0 },
458448
cursorPosition1.to_core_point(),
459449
leftMouseDown);
460450

@@ -502,55 +492,55 @@ namespace ControlUnitTests
502492
const Core::Point mousePos{ 0, 0 };
503493
Control::MouseButtonState state{};
504494

505-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 1/5
495+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 1/5
506496
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
507497

508498
Log::Comment(L"Scroll up 4 more times. Once we're at 3/5 scrolls, "
509499
L"we'll round the internal scrollbar position to scrolling to the next row.");
510-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 2/5
500+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 2/5
511501
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
512-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 3/5
502+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 3/5
513503
VERIFY_ARE_EQUAL(20, core->ScrollOffset());
514-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 4/5
504+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 4/5
515505
VERIFY_ARE_EQUAL(20, core->ScrollOffset());
516-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 5/5
506+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 5/5
517507
VERIFY_ARE_EQUAL(20, core->ScrollOffset());
518508

519509
Log::Comment(L"Jump to line 5, so we can scroll down from there.");
520510
interactivity->UpdateScrollbar(5);
521511
VERIFY_ARE_EQUAL(5, core->ScrollOffset());
522512
Log::Comment(L"Scroll down 5 times, at which point we should accumulate a whole row of delta.");
523-
interactivity->MouseWheel(modifiers, false, -delta, mousePos, state); // 1/5
513+
interactivity->MouseWheel(modifiers, Core::Point{ -delta, 0 }, mousePos, state); // 1/5
524514
VERIFY_ARE_EQUAL(5, core->ScrollOffset());
525-
interactivity->MouseWheel(modifiers, false, -delta, mousePos, state); // 2/5
515+
interactivity->MouseWheel(modifiers, Core::Point{ -delta, 0 }, mousePos, state); // 2/5
526516
VERIFY_ARE_EQUAL(5, core->ScrollOffset());
527-
interactivity->MouseWheel(modifiers, false, -delta, mousePos, state); // 3/5
517+
interactivity->MouseWheel(modifiers, Core::Point{ -delta, 0 }, mousePos, state); // 3/5
528518
VERIFY_ARE_EQUAL(6, core->ScrollOffset());
529-
interactivity->MouseWheel(modifiers, false, -delta, mousePos, state); // 4/5
519+
interactivity->MouseWheel(modifiers, Core::Point{ -delta, 0 }, mousePos, state); // 4/5
530520
VERIFY_ARE_EQUAL(6, core->ScrollOffset());
531-
interactivity->MouseWheel(modifiers, false, -delta, mousePos, state); // 5/5
521+
interactivity->MouseWheel(modifiers, Core::Point{ -delta, 0 }, mousePos, state); // 5/5
532522
VERIFY_ARE_EQUAL(6, core->ScrollOffset());
533523

534524
Log::Comment(L"Jump to the bottom.");
535525
interactivity->UpdateScrollbar(21);
536526
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
537527
Log::Comment(L"Scroll a bit, then emit a line of text. We should reset our internal scroll position.");
538-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 1/5
528+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 1/5
539529
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
540-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 2/5
530+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 2/5
541531
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
542532

543533
conn->WriteInput(winrt_wstring_to_array_view(L"Foo\r\n"));
544534
VERIFY_ARE_EQUAL(22, core->ScrollOffset());
545-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 1/5
535+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 1/5
546536
VERIFY_ARE_EQUAL(22, core->ScrollOffset());
547-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 2/5
537+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 2/5
548538
VERIFY_ARE_EQUAL(22, core->ScrollOffset());
549-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 3/5
539+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 3/5
550540
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
551-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 4/5
541+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 4/5
552542
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
553-
interactivity->MouseWheel(modifiers, false, delta, mousePos, state); // 5/5
543+
interactivity->MouseWheel(modifiers, Core::Point{ delta, 0 }, mousePos, state); // 5/5
554544
VERIFY_ARE_EQUAL(21, core->ScrollOffset());
555545
}
556546

@@ -719,8 +709,7 @@ namespace ControlUnitTests
719709
{
720710
expectedTop--;
721711
interactivity->MouseWheel(modifiers,
722-
false,
723-
WHEEL_DELTA,
712+
Core::Point{ WHEEL_DELTA, 0 },
724713
Core::Point{ 0, 0 },
725714
noMouseDown);
726715
}

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, const bool horizontal)
748+
void AppHost::_WindowMouseWheeled(const winrt::Windows::Foundation::Point coord, const winrt::Microsoft::Terminal::Core::Point delta)
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, horizontal, delta, lButtonDown, mButtonDown, rButtonDown))
775+
if (control.OnMouseWheel(offsetPoint, 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, const bool horizontal);
76+
void _WindowMouseWheeled(const winrt::Windows::Foundation::Point coord, const winrt::Microsoft::Terminal::Core::Point delta);
7777
void _WindowActivated(bool activated);
7878
void _WindowMoved();
7979

0 commit comments

Comments
 (0)