From f451d4800595caf00b6aa61408006cd100a6d416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Wed, 25 Mar 2015 13:37:31 +0000 Subject: Windows: Add support for horizontal scroll on some touchpads. While most (all?) touchpads send WM_MOUSEWHEEL for vertical scroll the story is quite different for horizontal scroll. Some of them send WM_HSCROLL instead of WM_MOUSEHWHEEL. Some of them even send left/right key event but those are lost cases. Task-number: QTBUG-45120 Change-Id: I3bf86e25a6f4f3ba03ac7e89a23f4b7bc432f2de Reviewed-by: Friedemann Kleint --- .../platforms/windows/qwindowsmousehandler.cpp | 73 +++++++++++++++++----- 1 file changed, 56 insertions(+), 17 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsmousehandler.cpp') diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 0fa34041d6..0ce8c09fc4 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -375,6 +376,31 @@ static bool isValidWheelReceiver(QWindow *candidate) return false; } +static void redirectWheelEvent(QWindow *window, const QPoint &globalPos, int delta, + Qt::Orientation orientation, Qt::KeyboardModifiers mods) +{ + // Redirect wheel event to one of the following, in order of preference: + // 1) The window under mouse + // 2) The window receiving the event + // If a window is blocked by modality, it can't get the event. + + QWindow *receiver = QWindowsScreen::windowAt(globalPos, CWP_SKIPINVISIBLE); + bool handleEvent = true; + if (!isValidWheelReceiver(receiver)) { + receiver = window; + if (!isValidWheelReceiver(receiver)) + handleEvent = false; + } + + if (handleEvent) { + const QPoint posDip = QWindowsGeometryHint::mapFromGlobal(receiver, globalPos) / QWindowsScaling::factor(); + QWindowSystemInterface::handleWheelEvent(receiver, + posDip, globalPos / QWindowsScaling::factor(), + delta / QWindowsScaling::factor(), + orientation, mods); + } +} + bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND, MSG msg, LRESULT *) { @@ -397,27 +423,40 @@ bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND, if (msg.message == WM_MOUSEHWHEEL) delta = -delta; - // Redirect wheel event to one of the following, in order of preference: - // 1) The window under mouse - // 2) The window receiving the event - // If a window is blocked by modality, it can't get the event. const QPoint globalPos(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); - QWindow *receiver = QWindowsScreen::windowAt(globalPos, CWP_SKIPINVISIBLE); - bool handleEvent = true; - if (!isValidWheelReceiver(receiver)) { - receiver = window; - if (!isValidWheelReceiver(receiver)) - handleEvent = false; - } + redirectWheelEvent(window, globalPos, delta, orientation, mods); - if (handleEvent) { - const QPoint posDip = QWindowsGeometryHint::mapFromGlobal(receiver, globalPos) / QWindowsScaling::factor(); - QWindowSystemInterface::handleWheelEvent(receiver, - posDip, globalPos / QWindowsScaling::factor(), - delta / QWindowsScaling::factor(), - orientation, mods); + return true; +} + +bool QWindowsMouseHandler::translateScrollEvent(QWindow *window, HWND, + MSG msg, LRESULT *) +{ + // This is a workaround against some touchpads that send WM_HSCROLL instead of WM_MOUSEHWHEEL. + // We could also handle vertical scroll here but there's no reason to, there's no bug for vertical + // (broken vertical scroll would have been noticed long time ago), so lets keep the change small + // and minimize the chance for regressions. + + int delta = 0; + switch (LOWORD(msg.wParam)) { + case SB_LINELEFT: + delta = 120; + break; + case SB_LINERIGHT: + delta = -120; + break; + case SB_PAGELEFT: + delta = 240; + break; + case SB_PAGERIGHT: + delta = -240; + break; + default: + return false; } + redirectWheelEvent(window, QCursor::pos(), delta, Qt::Horizontal, Qt::NoModifier); + return true; } -- cgit v1.2.3