Skip to content

Commit

Permalink
Try to fix Logitech mouse horizontal scrolling.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Oct 15, 2024
1 parent 338bc69 commit b453f87
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions scintilla/win32/ScintillaWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ inline bool KeyboardIsKeyDown(int key) noexcept {
constexpr sptr_t extendedKeyboard = 1 << 24;

constexpr bool KeyboardIsNumericKeypadFunction(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam) noexcept {
// Bit 24 is the extended keyboard flag and the numeric keypad is non-extended
if ((lParam & extendedKeyboard) != 0) {
// Not from the numeric keypad
return false;
Expand All @@ -185,6 +184,14 @@ constexpr bool KeyboardIsNumericKeypadFunction(Scintilla::uptr_t wParam, Scintil
}
}

inline bool IsMouseEvent() noexcept {
// Distinguishing Pen Input from Mouse and Touch
// https://learn.microsoft.com/en-us/windows/win32/tablet/system-events-and-mouse-messages
constexpr DWORD MI_WP_SIGNATURE = 0xFF515700;
constexpr DWORD SIGNATURE_MASK = 0xFFFFFF00;
return (::GetMessageExtraInfo() & SIGNATURE_MASK) != MI_WP_SIGNATURE;
}

inline CLIPFORMAT RegisterClipboardType(LPCWSTR lpszFormat) noexcept {
// Registered clipboard format values are 0xC000 through 0xFFFF.
// RegisterClipboardFormat() returns 32-bit unsigned and CLIPFORMAT is 16-bit
Expand Down Expand Up @@ -1763,17 +1770,25 @@ sptr_t ScintillaWin::MouseMessage(unsigned int iMessage, uptr_t wParam, sptr_t l
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}

MouseWheelDelta &wheelDelta = (iMessage == WM_MOUSEHWHEEL) ? horizontalWheelDelta : verticalWheelDelta;
if (wheelDelta.Accumulate(wParam)) {
int charsToScroll = charsPerScroll * wheelDelta.Actions();
sptr_t result = 0;
MouseWheelDelta *wheelDelta = &verticalWheelDelta;
if (iMessage == WM_MOUSEHWHEEL) {
wheelDelta = &horizontalWheelDelta;
// return 1 for Logitech mouse, https://www.pretentiousname.com/setpoint_hwheel/index.html
if (IsMouseEvent()) {
result = 1;
}
}
if (wheelDelta->Accumulate(wParam)) {
int charsToScroll = charsPerScroll * wheelDelta->Actions();
if (iMessage == WM_MOUSEHWHEEL) {
// horizontal wheelDelta has opposite sign/direction
// horizontal scroll is in reverse direction
charsToScroll = -charsToScroll;
}
const int widthToScroll = static_cast<int>(std::lround(charsToScroll * vs.aveCharWidth));
HorizontalScrollToClamped(xOffset + widthToScroll);
}
return 0;
return result;
}

// Either SCROLL or ZOOM. We handle the wheel steppings calculation
Expand Down

0 comments on commit b453f87

Please sign in to comment.