diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 8d6bb62594..2f759158ee 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -555,9 +555,8 @@ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor) else QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor); - // hack to force re-evaluation of screen geometry if (screen->handle()) - screen->d_func()->setPlatformScreen(screen->handle()); // updates geometries based on scale factor + screen->d_func()->updateLogicalDpi(); } QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen) diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index ca828171ff..1d8e103606 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -135,7 +135,7 @@ protected: QScopedPointer d_ptr; private: - friend class QScreenPrivate; + friend QScreen; }; // Qt doesn't currently support running with no platform screen diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index fd0e2ba2f7..ac33185900 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -41,7 +41,26 @@ QScreen::QScreen(QPlatformScreen *screen) : QObject(*new QScreenPrivate(), nullptr) { Q_D(QScreen); - d->setPlatformScreen(screen); + d->platformScreen = screen; + d->platformScreen->d_func()->screen = this; + d->orientation = d->platformScreen->orientation(); + + d->logicalDpi = QPlatformScreen::overrideDpi(d->platformScreen->logicalDpi()); + + d->refreshRate = d->platformScreen->refreshRate(); + // safeguard ourselves against buggy platform behavior... + if (d->refreshRate < 1.0) + d->refreshRate = 60.0; + + d->updateHighDpi(); + d->updatePrimaryOrientation(); // derived from the geometry +} + +void QScreenPrivate::updateLogicalDpi() +{ + Q_Q(QScreen); + logicalDpi = QPlatformScreen::overrideDpi(q->handle()->logicalDpi()); + updateGeometriesWithSignals(); // updates geometries based on scale factor } void QScreenPrivate::updateGeometriesWithSignals() @@ -71,25 +90,6 @@ void QScreenPrivate::emitGeometryChangeSignals(bool geometryChanged, bool availa emit q->physicalDotsPerInchChanged(q->physicalDotsPerInch()); } -void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen) -{ - Q_Q(QScreen); - platformScreen = screen; - platformScreen->d_func()->screen = q; - orientation = platformScreen->orientation(); - - logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi()); - - refreshRate = platformScreen->refreshRate(); - // safeguard ourselves against buggy platform behavior... - if (refreshRate < 1.0) - refreshRate = 60.0; - - updateHighDpi(); - updatePrimaryOrientation(); // derived from the geometry -} - - /*! Destroys the screen. */ diff --git a/src/gui/kernel/qscreen_p.h b/src/gui/kernel/qscreen_p.h index 1ba0c7c442..9d7ab504b2 100644 --- a/src/gui/kernel/qscreen_p.h +++ b/src/gui/kernel/qscreen_p.h @@ -28,12 +28,12 @@ class QScreenPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QScreen) public: - void setPlatformScreen(QPlatformScreen *screen); void updateHighDpi() { geometry = platformScreen->deviceIndependentGeometry(); availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft()); } + void updateLogicalDpi(); void updatePrimaryOrientation(); void updateGeometriesWithSignals();