diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index d967b03fee..f566677ff4 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1852,7 +1852,7 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv only see a press in a new location without any intervening moves. This could confuse code that is written for a real mouse. The same is true for mouse release events that change position, see tst_QWidget::touchEventSynthesizedMouseEvent() - auto test. + and tst_QWindow::generatedMouseMove() auto tests. */ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e) { @@ -1874,7 +1874,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo if (!mouseMove && positionChanged) { QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp, - e->localPos, e->globalPos, e->buttons & ~button, e->modifiers, Qt::NoButton, + e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton, e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove, e->source, e->nonClientArea); if (e->synthetic()) @@ -1977,14 +1977,14 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen); const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen); QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint, - button, mouse_buttons, e->modifiers, e->source); + button, e->buttons, e->modifiers, e->source); ev.setTimestamp(e->timestamp); cursor->pointerEvent(ev); } } #endif - QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, mouse_buttons, e->modifiers, e->source); + QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source); ev.setTimestamp(e->timestamp); if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) { @@ -2018,7 +2018,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo point.state = Qt::TouchPointPressed; } else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) { point.state = Qt::TouchPointReleased; - } else if (type == QEvent::MouseMove && (mouse_buttons & Qt::LeftButton)) { + } else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) { point.state = Qt::TouchPointMoved; } else { return; @@ -2039,7 +2039,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo if (!e->window.isNull() || e->nullWindow()) { // QTBUG-36364, check if window closed in response to press const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick; QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint, - button, mouse_buttons, e->modifiers, e->source); + button, e->buttons, e->modifiers, e->source); dblClickEvent.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent); } diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index a365d21d36..f2754de929 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -106,6 +106,7 @@ private slots: void flags(); void cleanup(); void testBlockingWindowShownAfterModalDialog(); + void generatedMouseMove(); private: QPoint m_availableTopLeft; @@ -918,6 +919,7 @@ public: } } void mouseMoveEvent(QMouseEvent *event) { + buttonStateInGeneratedMove = event->buttons(); if (ignoreMouse) { event->ignore(); } else { @@ -999,6 +1001,7 @@ public: bool ignoreMouse, ignoreTouch; bool spinLoopWhenPressed; + Qt::MouseButtons buttonStateInGeneratedMove; }; void tst_QWindow::testInputEvents() @@ -2316,6 +2319,56 @@ void tst_QWindow::testBlockingWindowShownAfterModalDialog() QVERIFY(normalWindowAfter.gotBlocked); } +void tst_QWindow::generatedMouseMove() +{ + InputTestWindow w; + w.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); + w.show(); + QVERIFY(QTest::qWaitForWindowActive(&w)); + QPoint point(10, 10); + QPoint step(2, 2); + + QVERIFY(w.mouseMovedCount == 0); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::NoButton, QEvent::MouseMove); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 1); + // Press that does not change position should not generate mouse move + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton | Qt::RightButton, Qt::RightButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 1); + + // Test moves generated for mouse release + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::RightButton, Qt::LeftButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 2); + QVERIFY(w.buttonStateInGeneratedMove == (Qt::LeftButton | Qt::RightButton)); + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::RightButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 3); + QVERIFY(w.buttonStateInGeneratedMove == Qt::RightButton); + + // Test moves generated for mouse press + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 4); + QVERIFY(w.buttonStateInGeneratedMove == Qt::NoButton); + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton | Qt::RightButton, Qt::RightButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 5); + QVERIFY(w.buttonStateInGeneratedMove == Qt::LeftButton); + + // Release that does not change position should not generate mouse move + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::RightButton, QEvent::MouseButtonRelease); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::LeftButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 5); +} + #include QTEST_MAIN(tst_QWindow)