From 3d841556bf4b01cd0a2831a191163f0c19ef15e8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 30 May 2018 10:27:03 +0200 Subject: Windows QPA: Fix release button event type after moving windows Check whether the mouse is inside the window and report MouseButtonRelease or QEvent::NonClientAreaMouseButtonRelease, respectively. The inside case is triggered by programmatically starting a size move via QPlatformWindow::startSystemResize() (QSizeGrip) and was overlooked in 7c3ecf85a770cd7fef01ece935f88d8894de09b2. Complements 45894408913f62f6f25a302d8ed07af57ac7db5d, 7c3ecf85a770cd7fef01ece935f88d8894de09b2. Change-Id: I8f714dc768a163878c2b4a075470bcee2dfbd802 Reviewed-by: Gatis Paeglis Reviewed-by: Andre de la Rocha --- .../platforms/windows/qwindowsmousehandler.cpp | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/plugins/platforms/windows') diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index bec935cd80..add01f65cc 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -180,24 +180,31 @@ Qt::MouseButtons QWindowsMouseHandler::queryMouseButtons() void QWindowsMouseHandler::handleExitSizeMove(QWindow *window) { - // When moving a window by dragging the title bar, no WM_NCLBUTTONUP is - // received after WM_NCLBUTTONDOWN, WM_NCMOUSEMOVE (due to internal - // mouse capture), which can leave the left mouse button 'pressed' - // in QGuiApplication's state. Intercept WM_EXITSIZEMOVE to sync the buttons. + // Windows can be moved/resized by: + // 1) User moving a window by dragging the title bar: Causes a sequence + // of WM_NCLBUTTONDOWN, WM_NCMOUSEMOVE but no WM_NCLBUTTONUP, + // leaving the left mouse button 'pressed' + // 2) User choosing Resize/Move from System menu and using mouse/cursor keys: + // No mouse events are received + // 3) Programmatically via QSizeGrip calling QPlatformWindow::startSystemResize/Move(): + // Mouse is left in pressed state after press on size grip (inside window), + // no further mouse events are received + // For cases 1,3, intercept WM_EXITSIZEMOVE to sync the buttons. const Qt::MouseButtons currentButtons = QWindowsMouseHandler::queryMouseButtons(); const Qt::MouseButtons appButtons = QGuiApplication::mouseButtons(); if (currentButtons == appButtons) return; const Qt::KeyboardModifiers keyboardModifiers = QWindowsKeyMapper::queryKeyboardModifiers(); const QPoint globalPos = QWindowsCursor::mousePosition(); - const QPoint localPos = window->handle()->mapFromGlobal(globalPos); + const QPlatformWindow *platWin = window->handle(); + const QPoint localPos = platWin->mapFromGlobal(globalPos); + const QEvent::Type type = platWin->geometry().contains(globalPos) + ? QEvent::MouseButtonRelease : QEvent::NonClientAreaMouseButtonRelease; for (Qt::MouseButton button : {Qt::LeftButton, Qt::RightButton, Qt::MiddleButton}) { if (appButtons.testFlag(button) && !currentButtons.testFlag(button)) { QWindowSystemInterface::handleMouseEvent(window, localPos, globalPos, - currentButtons, button, - QEvent::NonClientAreaMouseButtonRelease, - keyboardModifiers, - Qt::MouseEventNotSynthesized); + currentButtons, button, type, + keyboardModifiers); } } } -- cgit v1.2.3