From aeb566db73a2526e22145af17f6b5ed927eb6fbb Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 15 Nov 2012 10:32:31 +0200 Subject: [PATCH] Windows: Fix autocapture for multiple buttons Automatic capture of mouse events on button press was released when the first button was released, even if multiple buttons were pressed. Changed it so that the capture is released when the last button is released. Task-number: QTBUG-28007 Change-Id: Icee59aacaf0ba947820c40cb7ede00193ff46a14 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowsmousehandler.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 0fb67d0e98f..2f624c3e167 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -189,6 +189,7 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, } QWindowsWindow *platformWindow = static_cast(window->handle()); + const Qt::MouseButtons buttons = keyStateToMouseButtons((int)msg.wParam); // If the window was recently resized via mouse doubleclick on the frame or title bar, // we don't get WM_LBUTTONDOWN or WM_LBUTTONDBLCLK for the second click, @@ -199,7 +200,7 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONDBLCLK) { m_leftButtonDown = true; } else { - const bool actualLeftDown = keyStateToMouseButtons((int)msg.wParam) & Qt::LeftButton; + const bool actualLeftDown = buttons & Qt::LeftButton; if (!m_leftButtonDown && actualLeftDown) { // Autocapture the mouse for current window to and ignore further events until release. // Capture is necessary so we don't get WM_MOUSELEAVEs to confuse matters. @@ -236,7 +237,8 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, } else if (platformWindow->hasMouseCapture() && platformWindow->testFlag(QWindowsWindow::AutoMouseCapture) && (msg.message == WM_LBUTTONUP || msg.message == WM_MBUTTONUP - || msg.message == WM_RBUTTONUP || msg.message == WM_XBUTTONUP)) { + || msg.message == WM_RBUTTONUP || msg.message == WM_XBUTTONUP) + && !buttons) { platformWindow->setMouseGrabEnabled(false); if (QWindowsContext::verboseEvents) qDebug() << "Releasing automatic mouse capture " << window; @@ -299,8 +301,7 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, m_windowUnderMouse = currentWindowUnderMouse; } - QWindowSystemInterface::handleMouseEvent(window, winEventPosition, globalPosition, - keyStateToMouseButtons((int)msg.wParam), + QWindowSystemInterface::handleMouseEvent(window, winEventPosition, globalPosition, buttons, QWindowsKeyMapper::queryKeyboardModifiers()); return true; }