Revert "Drop call to setPlatformScreen in QHighDpiScaling::setScreenFactor"

This reverts commit 7b2ae3faab.

Reason for revert: this breaks multi-monitor XCB with HighDPI.

Fixes: QTBUG-105079
Pick-to: 6.4
Change-Id: I386c9480c33d1f67b3478332c8e03fe3eeeeee39
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Fushan Wen <qydwhotmail@gmail.com>
This commit is contained in:
Thiago Macieira 2022-07-19 17:57:08 +00:00
parent 5a5bc86028
commit 392566cf61
4 changed files with 24 additions and 23 deletions

View File

@ -555,8 +555,9 @@ 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()->updateLogicalDpi();
screen->d_func()->setPlatformScreen(screen->handle()); // updates geometries based on scale factor
}
QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen)

View File

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

View File

@ -41,26 +41,7 @@ QScreen::QScreen(QPlatformScreen *screen)
: QObject(*new QScreenPrivate(), nullptr)
{
Q_D(QScreen);
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
d->setPlatformScreen(screen);
}
void QScreenPrivate::updateGeometriesWithSignals()
@ -90,6 +71,25 @@ 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.
*/

View File

@ -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();