highdpi: fix map to/from global for "off-primary-screen" windows
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 <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
773f9ab018
commit
67fa2585ac
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user