Windows/QPA: Fix receiving mouse clicks after double clicks in QQuickWidget

The Qt QPA does not handle native double clicks as such; change the plugin
not to send them.

For Ink, remove the doubleclick detection. For the old code path,
map them to Press.

Fixes: QTBUG-70999
Change-Id: I54b858f9e146bf325a861554d5ef74143db7d2b7
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Friedemann Kleint 2018-10-19 08:19:04 +02:00
parent 903666a602
commit c053885735
2 changed files with 10 additions and 32 deletions

View File

@ -207,26 +207,26 @@ static inline MouseEvent eventFromMsg(const MSG &msg)
return {QEvent::MouseButtonPress, Qt::LeftButton}; return {QEvent::MouseButtonPress, Qt::LeftButton};
case WM_LBUTTONUP: case WM_LBUTTONUP:
return {QEvent::MouseButtonRelease, Qt::LeftButton}; return {QEvent::MouseButtonRelease, Qt::LeftButton};
case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK: // Qt QPA does not handle double clicks, send as press
return {QEvent::MouseButtonDblClick, Qt::LeftButton}; return {QEvent::MouseButtonPress, Qt::LeftButton};
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
return {QEvent::MouseButtonPress, Qt::MidButton}; return {QEvent::MouseButtonPress, Qt::MidButton};
case WM_MBUTTONUP: case WM_MBUTTONUP:
return {QEvent::MouseButtonRelease, Qt::MidButton}; return {QEvent::MouseButtonRelease, Qt::MidButton};
case WM_MBUTTONDBLCLK: case WM_MBUTTONDBLCLK:
return {QEvent::MouseButtonDblClick, Qt::MidButton}; return {QEvent::MouseButtonPress, Qt::MidButton};
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
return {QEvent::MouseButtonPress, Qt::RightButton}; return {QEvent::MouseButtonPress, Qt::RightButton};
case WM_RBUTTONUP: case WM_RBUTTONUP:
return {QEvent::MouseButtonRelease, Qt::RightButton}; return {QEvent::MouseButtonRelease, Qt::RightButton};
case WM_RBUTTONDBLCLK: case WM_RBUTTONDBLCLK:
return {QEvent::MouseButtonDblClick, Qt::RightButton}; return {QEvent::MouseButtonPress, Qt::RightButton};
case WM_XBUTTONDOWN: case WM_XBUTTONDOWN:
return {QEvent::MouseButtonPress, extraButton(msg.wParam)}; return {QEvent::MouseButtonPress, extraButton(msg.wParam)};
case WM_XBUTTONUP: case WM_XBUTTONUP:
return {QEvent::MouseButtonRelease, extraButton(msg.wParam)}; return {QEvent::MouseButtonRelease, extraButton(msg.wParam)};
case WM_XBUTTONDBLCLK: case WM_XBUTTONDBLCLK:
return {QEvent::MouseButtonDblClick, extraButton(msg.wParam)}; return {QEvent::MouseButtonPress, extraButton(msg.wParam)};
case WM_NCMOUSEMOVE: case WM_NCMOUSEMOVE:
return {QEvent::NonClientAreaMouseMove, Qt::NoButton}; return {QEvent::NonClientAreaMouseMove, Qt::NoButton};
case WM_NCLBUTTONDOWN: case WM_NCLBUTTONDOWN:
@ -234,19 +234,19 @@ static inline MouseEvent eventFromMsg(const MSG &msg)
case WM_NCLBUTTONUP: case WM_NCLBUTTONUP:
return {QEvent::NonClientAreaMouseButtonRelease, Qt::LeftButton}; return {QEvent::NonClientAreaMouseButtonRelease, Qt::LeftButton};
case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDBLCLK:
return {QEvent::NonClientAreaMouseButtonDblClick, Qt::LeftButton}; return {QEvent::NonClientAreaMouseButtonPress, Qt::LeftButton};
case WM_NCMBUTTONDOWN: case WM_NCMBUTTONDOWN:
return {QEvent::NonClientAreaMouseButtonPress, Qt::MidButton}; return {QEvent::NonClientAreaMouseButtonPress, Qt::MidButton};
case WM_NCMBUTTONUP: case WM_NCMBUTTONUP:
return {QEvent::NonClientAreaMouseButtonRelease, Qt::MidButton}; return {QEvent::NonClientAreaMouseButtonRelease, Qt::MidButton};
case WM_NCMBUTTONDBLCLK: case WM_NCMBUTTONDBLCLK:
return {QEvent::NonClientAreaMouseButtonDblClick, Qt::MidButton}; return {QEvent::NonClientAreaMouseButtonPress, Qt::MidButton};
case WM_NCRBUTTONDOWN: case WM_NCRBUTTONDOWN:
return {QEvent::NonClientAreaMouseButtonPress, Qt::RightButton}; return {QEvent::NonClientAreaMouseButtonPress, Qt::RightButton};
case WM_NCRBUTTONUP: case WM_NCRBUTTONUP:
return {QEvent::NonClientAreaMouseButtonRelease, Qt::RightButton}; return {QEvent::NonClientAreaMouseButtonRelease, Qt::RightButton};
case WM_NCRBUTTONDBLCLK: case WM_NCRBUTTONDBLCLK:
return {QEvent::NonClientAreaMouseButtonDblClick, Qt::RightButton}; return {QEvent::NonClientAreaMouseButtonPress, Qt::RightButton};
default: // WM_MOUSELEAVE default: // WM_MOUSELEAVE
break; break;
} }

View File

@ -280,7 +280,7 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
return false; return false;
} }
static void getMouseEventInfo(UINT message, POINTER_BUTTON_CHANGE_TYPE changeType, QPoint globalPos, QEvent::Type *eventType, Qt::MouseButton *mouseButton) static void getMouseEventInfo(UINT message, POINTER_BUTTON_CHANGE_TYPE changeType, QEvent::Type *eventType, Qt::MouseButton *mouseButton)
{ {
static const QHash<POINTER_BUTTON_CHANGE_TYPE, Qt::MouseButton> buttonMapping { static const QHash<POINTER_BUTTON_CHANGE_TYPE, Qt::MouseButton> buttonMapping {
{POINTER_CHANGE_FIRSTBUTTON_DOWN, Qt::LeftButton}, {POINTER_CHANGE_FIRSTBUTTON_DOWN, Qt::LeftButton},
@ -334,28 +334,6 @@ static void getMouseEventInfo(UINT message, POINTER_BUTTON_CHANGE_TYPE changeTyp
} }
*mouseButton = buttonMapping.value(changeType, Qt::NoButton); *mouseButton = buttonMapping.value(changeType, Qt::NoButton);
// Pointer messages lack a double click indicator. Check if this is the case here.
if (*eventType == QEvent::MouseButtonPress ||
*eventType == QEvent::NonClientAreaMouseButtonPress) {
static LONG lastTime = 0;
static Qt::MouseButton lastButton = Qt::NoButton;
static QEvent::Type lastEvent = QEvent::None;
static QPoint lastPos;
LONG messageTime = GetMessageTime();
if (*mouseButton == lastButton
&& *eventType == lastEvent
&& messageTime - lastTime < (LONG)GetDoubleClickTime()
&& qAbs(globalPos.x() - lastPos.x()) < GetSystemMetrics(SM_CXDOUBLECLK)
&& qAbs(globalPos.y() - lastPos.y()) < GetSystemMetrics(SM_CYDOUBLECLK)) {
*eventType = nonClient ? QEvent::NonClientAreaMouseButtonDblClick :
QEvent::MouseButtonDblClick;
}
lastTime = messageTime;
lastButton = *mouseButton;
lastEvent = *eventType;
lastPos = globalPos;
}
} }
static QWindow *getWindowUnderPointer(QWindow *window, QPoint globalPos) static QWindow *getWindowUnderPointer(QWindow *window, QPoint globalPos)
@ -467,7 +445,7 @@ bool QWindowsPointerHandler::translateMouseTouchPadEvent(QWindow *window, HWND h
QEvent::Type eventType; QEvent::Type eventType;
Qt::MouseButton button; Qt::MouseButton button;
getMouseEventInfo(msg.message, pointerInfo->ButtonChangeType, globalPos, &eventType, &button); getMouseEventInfo(msg.message, pointerInfo->ButtonChangeType, &eventType, &button);
if (et & QtWindows::NonClientEventFlag) { if (et & QtWindows::NonClientEventFlag) {
QWindowSystemInterface::handleFrameStrutMouseEvent(window, localPos, globalPos, mouseButtons, button, eventType, QWindowSystemInterface::handleFrameStrutMouseEvent(window, localPos, globalPos, mouseButtons, button, eventType,