From 18088d4706bdd2fefafe7dbb44dc467126f2c795 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 3 Sep 2019 13:43:58 +0200 Subject: QtGui: Refactor parsing of the High DPI scaling env variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use qEnvironmentVariable() where applicable and refactor the parsing of QT_SCREEN_SCALE_FACTORS to use QStringRef. Task-number: QTBUG-53022 Change-Id: I8956c6cecd7b634679eb5e66d2a87cccaf9e7936 Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/gui/kernel/qhighdpiscaling.cpp') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index c031885d5d..ec4feeba8b 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -86,7 +86,7 @@ static inline qreal initialGlobalScaleFactor() qreal result = 1; if (qEnvironmentVariableIsSet(scaleFactorEnvVar)) { bool ok; - const qreal f = qgetenv(scaleFactorEnvVar).toDouble(&ok); + const qreal f = qEnvironmentVariable(scaleFactorEnvVar).toDouble(&ok); if (ok && f > 0) { qCDebug(lcScaling) << "Apply " << scaleFactorEnvVar << f; result = f; @@ -284,7 +284,8 @@ static inline bool usePixelDensity() return QCoreApplication::testAttribute(Qt::AA_EnableHighDpiScaling) || (screenEnvValueOk && screenEnvValue > 0) || (enableEnvValueOk && enableEnvValue > 0) - || (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar) && qgetenv(legacyDevicePixelEnvVar).toLower() == "auto"); + || (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar) + && qEnvironmentVariable(legacyDevicePixelEnvVar).compare(QLatin1String("auto"), Qt::CaseInsensitive) == 0); } qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen) @@ -506,20 +507,20 @@ void QHighDpiScaling::updateHighDpiScaling() } if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) { int i = 0; - const auto specs = qgetenv(screenFactorsEnvVar).split(';'); - for (const QByteArray &spec : specs) { - int equalsPos = spec.lastIndexOf('='); + const QString spec = qEnvironmentVariable(screenFactorsEnvVar); + const auto specs = spec.splitRef(QLatin1Char(';')); + for (const QStringRef &spec : specs) { + int equalsPos = spec.lastIndexOf(QLatin1Char('=')); qreal factor = 0; if (equalsPos > 0) { // support "name=factor" - QByteArray name = spec.mid(0, equalsPos); - QByteArray f = spec.mid(equalsPos + 1); bool ok; - factor = f.toDouble(&ok); + const auto name = spec.left(equalsPos); + factor = spec.mid(equalsPos + 1).toDouble(&ok); if (ok && factor > 0 ) { const auto screens = QGuiApplication::screens(); for (QScreen *s : screens) { - if (s->name() == QString::fromLocal8Bit(name)) { + if (s->name() == name) { setScreenFactor(s, factor); break; } -- cgit v1.2.3 From e018d11600bffc6e54cddd3857822516f3f501a0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 7 Sep 2019 22:32:35 +0200 Subject: Dpi settings: QT_SCREEN_SCALE_FACTORS enables scaling again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 900f2cb6f7070 removed this from the condition, which breaks the (common) case of having QT_AUTO_SCREEN_SCALE_FACTOR=0 and QT_SCREEN_SCALE_FACTORS set. This used to obey the screen scale factors, so it should still do so (despite the deprecation warning). This is what the Plasma `kcmshell5 kscreen` module actually sets (via startkde). Change-Id: I5f4efed11b937498049ebf1b107954721cf54147 Reviewed-by: Friedemann Kleint Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/kernel/qhighdpiscaling.cpp') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index ec4feeba8b..dcbae4f5c0 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -538,7 +538,7 @@ void QHighDpiScaling::updateHighDpiScaling() ++i; } } - m_active = m_globalScalingActive || m_usePixelDensity; + m_active = m_globalScalingActive || m_screenFactorSet || m_usePixelDensity; } /* -- cgit v1.2.3 From 00d0a530358d40d577578cb1bcb75a978549bd8d Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 7 Sep 2019 23:14:19 +0200 Subject: QDpi: divide the forced DPI by the scaling factor, as Qt 5.13 did MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When setting a DPI in xrdb, it should have the same effect on apps that enable scaling and apps that don't (including Qt4 and GTK applications). That's what happened in Qt 5.13, while the recent changes removed that division, and as a result the fonts were huge in Qt5 apps compared to Qt4/GTK/kwin/plasmashell/krunner (which don't scale, but do honor the font DPI). Change-Id: Icd7be2d15a9b50982ae624e41bd9e546f315d58b Reviewed-by: Friedemann Kleint Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel/qhighdpiscaling.cpp') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index dcbae4f5c0..ee54fd4fa1 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -680,8 +680,11 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen) if (!screen || !screen->handle()) return QDpi(96, 96); - if (!m_usePixelDensity) - return QPlatformScreen::overrideDpi(screen->handle()->logicalDpi()); + if (!m_usePixelDensity) { + const qreal screenScaleFactor = screenSubfactor(screen->handle()); + const QDpi dpi = QPlatformScreen::overrideDpi(screen->handle()->logicalDpi()); + return QDpi{ dpi.first / screenScaleFactor, dpi.second / screenScaleFactor }; + } const qreal scaleFactor = rawScaleFactor(screen->handle()); const qreal roundedScaleFactor = roundScaleFactor(scaleFactor); -- cgit v1.2.3 From a96c4b3aab4592155f7647399f6f2eda98d3908a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 11 Sep 2019 14:42:30 +0200 Subject: QHighDPI: Fix wrong conversion for native child windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not try to find a screen for native child coordinates. Fixes: QTBUG-78158 Change-Id: I78ba814929f4db3dfd7dd43c09f7c7642222f4fb Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel/qhighdpiscaling.cpp') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 64f1397771..8189eebedd 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -476,8 +476,10 @@ QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QWindow *w { if (!m_active) return { qreal(1), QPoint() }; + QScreen *screen = window ? window->screen() : QGuiApplication::primaryScreen(); - return scaleAndOrigin(screen, nativePosition); + const bool searchScreen = !window || window->isTopLevel(); + return scaleAndOrigin(screen, searchScreen ? nativePosition : nullptr); } #endif //QT_NO_HIGHDPISCALING -- cgit v1.2.3