QtGui: Refactor parsing of the High DPI scaling env variables
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 <morten.sorvig@qt.io>
This commit is contained in:
parent
dfeb2e16e0
commit
18088d4706
@ -86,7 +86,7 @@ static inline qreal initialGlobalScaleFactor()
|
|||||||
qreal result = 1;
|
qreal result = 1;
|
||||||
if (qEnvironmentVariableIsSet(scaleFactorEnvVar)) {
|
if (qEnvironmentVariableIsSet(scaleFactorEnvVar)) {
|
||||||
bool ok;
|
bool ok;
|
||||||
const qreal f = qgetenv(scaleFactorEnvVar).toDouble(&ok);
|
const qreal f = qEnvironmentVariable(scaleFactorEnvVar).toDouble(&ok);
|
||||||
if (ok && f > 0) {
|
if (ok && f > 0) {
|
||||||
qCDebug(lcScaling) << "Apply " << scaleFactorEnvVar << f;
|
qCDebug(lcScaling) << "Apply " << scaleFactorEnvVar << f;
|
||||||
result = f;
|
result = f;
|
||||||
@ -284,7 +284,8 @@ static inline bool usePixelDensity()
|
|||||||
return QCoreApplication::testAttribute(Qt::AA_EnableHighDpiScaling)
|
return QCoreApplication::testAttribute(Qt::AA_EnableHighDpiScaling)
|
||||||
|| (screenEnvValueOk && screenEnvValue > 0)
|
|| (screenEnvValueOk && screenEnvValue > 0)
|
||||||
|| (enableEnvValueOk && enableEnvValue > 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)
|
qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen)
|
||||||
@ -506,20 +507,20 @@ void QHighDpiScaling::updateHighDpiScaling()
|
|||||||
}
|
}
|
||||||
if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
|
if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
const auto specs = qgetenv(screenFactorsEnvVar).split(';');
|
const QString spec = qEnvironmentVariable(screenFactorsEnvVar);
|
||||||
for (const QByteArray &spec : specs) {
|
const auto specs = spec.splitRef(QLatin1Char(';'));
|
||||||
int equalsPos = spec.lastIndexOf('=');
|
for (const QStringRef &spec : specs) {
|
||||||
|
int equalsPos = spec.lastIndexOf(QLatin1Char('='));
|
||||||
qreal factor = 0;
|
qreal factor = 0;
|
||||||
if (equalsPos > 0) {
|
if (equalsPos > 0) {
|
||||||
// support "name=factor"
|
// support "name=factor"
|
||||||
QByteArray name = spec.mid(0, equalsPos);
|
|
||||||
QByteArray f = spec.mid(equalsPos + 1);
|
|
||||||
bool ok;
|
bool ok;
|
||||||
factor = f.toDouble(&ok);
|
const auto name = spec.left(equalsPos);
|
||||||
|
factor = spec.mid(equalsPos + 1).toDouble(&ok);
|
||||||
if (ok && factor > 0 ) {
|
if (ok && factor > 0 ) {
|
||||||
const auto screens = QGuiApplication::screens();
|
const auto screens = QGuiApplication::screens();
|
||||||
for (QScreen *s : screens) {
|
for (QScreen *s : screens) {
|
||||||
if (s->name() == QString::fromLocal8Bit(name)) {
|
if (s->name() == name) {
|
||||||
setScreenFactor(s, factor);
|
setScreenFactor(s, factor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user