From 7809e77f2e6163de892afb99cb3a4a8f259f4709 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 23 Jun 2015 17:05:32 +0200 Subject: Add environment variable to set per-screen scaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0fce05998ba6092c4dd1d64790c56c0668383477 Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/gui/kernel/qhighdpiscaling.cpp') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 8dd6c6687d..e574a79370 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -54,6 +54,7 @@ Q_LOGGING_CATEGORY(lcScaling, "qt.scaling"); static const char legacyDevicePixelEnvVar[] = "QT_DEVICE_PIXEL_RATIO"; static const char scaleFactorEnvVar[] = "QT_SCALE_FACTOR"; static const char autoScreenEnvVar[] = "QT_AUTO_SCREEN_SCALE_FACTOR"; +static const char screenFactorsEnvVar[] = "QT_SCREEN_SCALE_FACTORS"; static inline qreal initialScaleFactor() { @@ -113,6 +114,11 @@ static inline qreal initialScaleFactor() Setting this to a true-ish value will make QHighDpiScaling call QPlatformScreen::pixelDensity() - QHighDpiScaling::setScreenFactor(screen, factor); + - QT_SCREEN_SCALE_FACTORS (environment variable) + Set this to a semicolon-separated list of scale factors + (matching the order of QGuiApplications::screens()), + or to a list of name=value pairs (where name matches + QScreen::name()). All scale factors are of type qreal. @@ -159,6 +165,38 @@ void QHighDpiScaling::updateHighDpiScaling() } } } + if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) { + int i = 0; + Q_FOREACH (QByteArray spec, qgetenv(screenFactorsEnvVar).split(';')) { + QScreen *screen = 0; + int equalsPos = spec.lastIndexOf('='); + double 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); + if (ok) { + Q_FOREACH (QScreen *s, QGuiApplication::screens()) { + if (s->name() == QString::fromLocal8Bit(name)) { + screen = s; + break; + } + } + } + } else { + // listing screens in order + bool ok; + factor = spec.toDouble(&ok); + if (ok && i < QGuiApplication::screens().count()) + screen = QGuiApplication::screens().at(i); + } + if (screen) + setScreenFactor(screen, factor); + ++i; + } + } m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive; QPlatformScreen *primaryScreen = QGuiApplication::primaryScreen()->handle(); -- cgit v1.2.3