Remove indirection via QScreenPrivate::setPlatformScreen()

The QHighDpiScaling code should call the explicit updateGeometry
function instead to re-evaluate the platform screen geometry in
light of the change to the scale factor.

Change-Id: Idac975c117c431356f4fb812c245348c4722a8b5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Tor Arne Vestbø 2022-09-07 21:13:42 +02:00
parent c4debab927
commit 2187936978
4 changed files with 12 additions and 21 deletions

View File

@ -574,9 +574,7 @@ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor)
else else
QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor); QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor);
// hack to force re-evaluation of screen geometry screen->d_func()->updateGeometry();
if (screen->handle())
screen->d_func()->setPlatformScreen(screen->handle()); // updates geometries based on scale factor
} }
QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen) QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen)

View File

@ -132,7 +132,7 @@ protected:
QScopedPointer<QPlatformScreenPrivate> d_ptr; QScopedPointer<QPlatformScreenPrivate> d_ptr;
private: private:
friend class QScreenPrivate; friend class QScreen;
}; };
// Qt doesn't currently support running with no platform screen // Qt doesn't currently support running with no platform screen

View File

@ -37,29 +37,23 @@ QT_BEGIN_NAMESPACE
\inmodule QtGui \inmodule QtGui
*/ */
QScreen::QScreen(QPlatformScreen *screen) QScreen::QScreen(QPlatformScreen *platformScreen)
: QObject(*new QScreenPrivate(), nullptr) : QObject(*new QScreenPrivate(), nullptr)
{ {
Q_D(QScreen); Q_D(QScreen);
d->setPlatformScreen(screen);
}
void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen) d->platformScreen = platformScreen;
{ platformScreen->d_func()->screen = this;
Q_Q(QScreen);
platformScreen = screen;
platformScreen->d_func()->screen = q;
orientation = platformScreen->orientation();
logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi()); d->orientation = platformScreen->orientation();
d->logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
refreshRate = platformScreen->refreshRate(); d->refreshRate = platformScreen->refreshRate();
// safeguard ourselves against buggy platform behavior... // safeguard ourselves against buggy platform behavior...
if (refreshRate < 1.0) if (d->refreshRate < 1.0)
refreshRate = 60.0; d->refreshRate = 60.0;
updateGeometry(); d->updateGeometry();
updatePrimaryOrientation(); // derived from the geometry d->updatePrimaryOrientation(); // derived from the geometry
} }
void QScreenPrivate::updateGeometry() void QScreenPrivate::updateGeometry()

View File

@ -40,7 +40,6 @@ class QScreenPrivate : public QObjectPrivate, public QScreenData
{ {
Q_DECLARE_PUBLIC(QScreen) Q_DECLARE_PUBLIC(QScreen)
public: public:
void setPlatformScreen(QPlatformScreen *screen);
void updateGeometry(); void updateGeometry();
void updatePrimaryOrientation(); void updatePrimaryOrientation();