From eef865cdc594c20b6f468d206475ddab48e2819a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 5 Jan 2022 23:10:33 +0100 Subject: [PATCH] Make QCursor::setPos() use the correct screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setPos() takes a screen argument, however this argument indicates which cursor should be moved only and is not usable as an argument to toNativePixels() since the position may be on a sibling screen. Add call to QScreen::virtualSiblingAt to get the target screen. Task-number: QTBUG-99009 Pick-to: 6.3 6.2 5.15 Change-Id: I8714ebc93a283c58bc67911315f787c484fb0dd8 Reviewed-by: Liang Qi Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qcursor.cpp | 3 ++- .../auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index 20511ef8e6f..876cf40bdff 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -251,7 +251,8 @@ void QCursor::setPos(QScreen *screen, int x, int y) { if (screen) { if (QPlatformCursor *cursor = screen->handle()->cursor()) { - const QPoint devicePos = QHighDpi::toNativePixels(QPoint(x, y), screen); + const QPoint pos(x, y); + const QPoint devicePos = QHighDpi::toNativePixels(pos, screen->virtualSiblingAt(pos)); // Need to check, since some X servers generate null mouse move // events, causing looping in applications which call setPos() on // every mouse move event. diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index b7329542308..cd721f249b6 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -76,6 +76,8 @@ private slots: void mouseEvents(); void mouseVelocity(); void mouseVelocity_data(); + void setCursor(); + void setCursor_data(); }; /// Offscreen platform plugin test setup @@ -805,5 +807,22 @@ void tst_QHighDpi::mouseVelocity() } } +void tst_QHighDpi::setCursor_data() +{ + standardScreenDpiTestData(); +} + +void tst_QHighDpi::setCursor() +{ + QFETCH(QList, dpiValues); + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + + for (QScreen *screen : app->screens()) { + QPoint center = screen->geometry().center(); + QCursor::setPos(center.x(), center.y()); + QCOMPARE(QCursor::pos(), center); + } +} + #include "tst_qhighdpi.moc" QTEST_APPLESS_MAIN(tst_QHighDpi);