diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-03-12 14:21:36 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-03-15 11:49:52 +0100 |
commit | 657284acbc1869f5f93b2cc6e9b7530e2e145435 (patch) | |
tree | 3adcff2ce6f425c7c104784c4e963e95fe372033 | |
parent | 4d1f13f3549a73f5ca4e64dac9137e83138080fa (diff) |
Don’t store screen scale factors in GLOBAL_STATIC
Use a normal static variable, like the other high-dpi
variables.
Clear the stored factors in initHighDpiScaling(). This
makes auto-testing possible where the application object
is recreated for each test case and should start with
a clean slate.
Change-Id: I1831c856b5d7a2c522e62c7ed0657da771c3144f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 13 | ||||
-rw-r--r-- | src/gui/kernel/qhighdpiscaling_p.h | 1 |
2 files changed, 6 insertions, 8 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 4fa8b9378f..3a70e5acf7 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -64,11 +64,6 @@ static const char scaleFactorRoundingPolicyEnvVar[] = "QT_SCALE_FACTOR_ROUNDING_ static const char dpiAdjustmentPolicyEnvVar[] = "QT_DPI_ADJUSTMENT_POLICY"; static const char usePhysicalDpiEnvVar[] = "QT_USE_PHYSICAL_DPI"; -// Per-screen scale factors for named screens set with QT_SCREEN_SCALE_FACTORS -// are stored here. Use a global hash to keep the factor across screen -// disconnect/connect cycles where the screen object may be deleted. -typedef QHash<QString, qreal> QScreenScaleFactorHash; -Q_GLOBAL_STATIC(QScreenScaleFactorHash, qNamedScreenScaleFactors); static std::optional<QString> qEnvironmentVariableOptionalString(const char *name) { if (!qEnvironmentVariableIsSet(name)) @@ -287,6 +282,7 @@ bool QHighDpiScaling::m_screenFactorSet = false; // QHighDpiScaling::setScreenFa bool QHighDpiScaling::m_usePhysicalDpi = false; QHighDpiScaling::DpiAdjustmentPolicy QHighDpiScaling::m_dpiAdjustmentPolicy = QHighDpiScaling::DpiAdjustmentPolicy::Unset; QString QHighDpiScaling::m_screenFactorsSpec; +QHash<QString, qreal> QHighDpiScaling::m_namedScreenScaleFactors; // Per-screen scale factors (screen name -> factor) qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen) { @@ -479,6 +475,7 @@ void QHighDpiScaling::initHighDpiScaling() // supports using screen names, which means that screen DPI cannot // be resolved at this point. QHighDpiScaling::m_screenFactorsSpec = envScreenFactors.value_or(QString()); + m_namedScreenScaleFactors.clear(); m_usePhysicalDpi = envUsePhysicalDpi.value_or(0) > 0; @@ -600,7 +597,7 @@ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor) if (name.isEmpty()) screen->setProperty(scaleFactorProperty, QVariant(factor)); else - qNamedScreenScaleFactors()->insert(name, factor); + QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor); // hack to force re-evaluation of screen geometry if (screen->handle()) @@ -647,8 +644,8 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) } if (!screenPropertyUsed) { - auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name()); - if ((screenPropertyUsed = byNameIt != qNamedScreenScaleFactors()->cend())) + auto byNameIt = QHighDpiScaling::m_namedScreenScaleFactors.constFind(screen->name()); + if ((screenPropertyUsed = byNameIt != QHighDpiScaling::m_namedScreenScaleFactors.cend())) factor = *byNameIt; } } diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index e3522d41c1..e85a9b4bd6 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -141,6 +141,7 @@ private: static bool m_usePhysicalDpi; static QString m_screenFactorsSpec; static DpiAdjustmentPolicy m_dpiAdjustmentPolicy; + static QHash<QString, qreal> m_namedScreenScaleFactors; }; namespace QHighDpi { |