summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindow.cpp
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2020-05-20 14:27:16 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2020-10-20 07:26:38 +0200
commit0ab89881c5aecc31e44fd83b1a63bd4de52ebe4a (patch)
tree7695c6a3f3eda3b48bc8dc0a55c184b64cbd7515 /src/gui/kernel/qwindow.cpp
parente8fabb29462e6ee268bde5267e3d7bca23addbb2 (diff)
high-dpi: Re-implement mapToGlobal and mapFromGlobal
(This code is required to handle corner cases such as a QWindow covering multiple screens, where the normal code path does not give correct results.) Move the map[to|from]Global implementation from qhighdpiscaling.cpp, and implement it in terms of [to|from]NativeGlobalPosition. These functions implement the required screenAt()-type searching. The implementation strategy for both mapping functions is to first map to the native coordinate system, perform the globalPos addition or subtraction, and then map the result back to device independent coordinates. Task-number: QTBUG-81695 Change-Id: I44e9e68651634650964e839b1e564b50f434553f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r--src/gui/kernel/qwindow.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 131f55908b..b0c07cb632 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -2684,10 +2684,20 @@ QPointF QWindow::mapToGlobal(const QPointF &pos) const
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos, this)), this);
}
- if (QHighDpiScaling::isActive())
- return QHighDpiScaling::mapPositionToGlobal(pos, d->globalPosition(), this);
+ if (!QHighDpiScaling::isActive())
+ return pos + d->globalPosition();
- return pos + QPointF(d->globalPosition());
+ // The normal pos + windowGlobalPos calculation may give a point which is outside
+ // screen geometry for windows which span multiple screens, due to the way QHighDpiScaling
+ // creates gaps between screens in the the device indendent cooordinate system.
+ //
+ // 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 nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
+ QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos, this);
+ return deviceIndependentGlobalPos;
}
/*!
@@ -2716,10 +2726,16 @@ QPointF QWindow::mapFromGlobal(const QPointF &pos) const
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeLocalPosition(pos, this)), this);
}
- if (QHighDpiScaling::isActive())
- return QHighDpiScaling::mapPositionFromGlobal(pos, d->globalPosition(), this);
+ if (!QHighDpiScaling::isActive())
+ return pos - d->globalPosition();
- return pos - QPointF(d->globalPosition());
+ // Calculate local position in the native coordinate system. (See comment for the
+ // correspinding mapToGlobal() code above).
+ QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos, this);
+ QPointF nativeWindowGlobalPos = QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this);
+ QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
+ QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos, this);
+ return deviceIndependentLocalPos;
}
/*!