From 67fa2585ac48e64972d1c0a20b3add5c3ef72e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Thu, 9 Nov 2023 12:21:38 +0100 Subject: [PATCH] highdpi: fix map to/from global for "off-primary-screen" windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By "off-primary-screen" here I mean windows which are visible on more than one screen, e.g. a secondary screen in addition to the primary screen. In this case the call to QHighDpi::toNativeGlobalPosition(pos, this) problematic, since it uses the scale factor for the primary screen, while pos might be on the secondary screen. One way to fix this is to look up the correct scale factor based on pos. Another way is to realize we don't have to use scaling to get the native window position, and get it from platformWindow geometry. This patch implements this fix. Fixes: QTBUG-106695 Change-Id: I03ffc261e199f65e54b06b964d067b6a9e0dd021 Reviewed-by: Qt CI Bot Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index b514795da7..13bcc56f95 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2850,7 +2850,7 @@ QPointF QWindow::mapToGlobal(const QPointF &pos) const // Map the position (and the window's global position) to native coordinates, perform // the addition, and then map back to device independent coordinates. QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos, this); - QPointF nativeWindowGlobalPos = QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this); + QPointF nativeWindowGlobalPos = d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF(); QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos; QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos, this); return deviceIndependentGlobalPos; @@ -2888,7 +2888,7 @@ QPointF QWindow::mapFromGlobal(const QPointF &pos) const // Calculate local position in the native coordinate system. (See comment for the // corresponding mapToGlobal() code above). QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos, this); - QPointF nativeWindowGlobalPos = QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this); + QPointF nativeWindowGlobalPos = d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF(); QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos; QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos, this); return deviceIndependentLocalPos;