From c808bd0b60543127686231ce9ebbb2b6331387b2 Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Wed, 12 Aug 2020 07:48:32 -0300 Subject: Windows QPA: Fix omitted Drop event In some rare cases, when a mouse button was released while the mouse was static, a drag and drop operation would not be completed until the mouse was moved. Probably due to a Windows bug, the mouse button state supplied through the arguments of the IDropSource callbacks, called from the internal DoDragDrop() loop, would not reflect the actual mouse button state in this case. This change makes the callback implementation use the actual mouse button state provided by GetAsyncKeyState(). Fixes: QTBUG-85300 Pick-to: 5.15 Change-Id: I3405bdf7076ddc46415cd274a502434bdc0d2f3f Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsdrag.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'src/plugins/platforms/windows') diff --git a/src/plugins/platforms/windows/qwindowsdrag.cpp b/src/plugins/platforms/windows/qwindowsdrag.cpp index 1c27e4e85b..f46adf9132 100644 --- a/src/plugins/platforms/windows/qwindowsdrag.cpp +++ b/src/plugins/platforms/windows/qwindowsdrag.cpp @@ -190,20 +190,6 @@ static inline Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState) return modifiers; } -static inline Qt::MouseButtons toQtMouseButtons(DWORD keyState) -{ - Qt::MouseButtons buttons = Qt::NoButton; - - if (keyState & MK_LBUTTON) - buttons |= Qt::LeftButton; - if (keyState & MK_RBUTTON) - buttons |= Qt::RightButton; - if (keyState & MK_MBUTTON) - buttons |= Qt::MidButton; - - return buttons; -} - static Qt::KeyboardModifiers lastModifiers = Qt::NoModifier; static Qt::MouseButtons lastButtons = Qt::NoButton; @@ -386,7 +372,10 @@ void QWindowsOleDropSource::createCursors() QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QWindowsOleDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState) { - Qt::MouseButtons buttons = toQtMouseButtons(grfKeyState); + // In some rare cases, when a mouse button is released but the mouse is static, + // grfKeyState will not be updated with these released buttons until the mouse + // is moved. So we use the async key state given by queryMouseButtons() instead. + Qt::MouseButtons buttons = QWindowsMouseHandler::queryMouseButtons(); SCODE result = S_OK; if (fEscapePressed || QWindowsDrag::isCanceled()) { @@ -505,7 +494,7 @@ void QWindowsOleDropTarget::handleDrag(QWindow *window, DWORD grfKeyState, const Qt::DropActions actions = translateToQDragDropActions(*pdwEffect); lastModifiers = toQtKeyboardModifiers(grfKeyState); - lastButtons = toQtMouseButtons(grfKeyState); + lastButtons = QWindowsMouseHandler::queryMouseButtons(); const QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(window, windowsDrag->dropData(), @@ -603,7 +592,7 @@ QWindowsOleDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, QWindowsDrag *windowsDrag = QWindowsDrag::instance(); lastModifiers = toQtKeyboardModifiers(grfKeyState); - lastButtons = toQtMouseButtons(grfKeyState); + lastButtons = QWindowsMouseHandler::queryMouseButtons(); const QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(m_window, windowsDrag->dropData(), -- cgit v1.2.3