Commit 97e612c2 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Don't compute aspect ratio for empty screen geometries

Apparently some kinds of virtual screens have a geometry of 0x0, which causes a divide-by-zero when computing the aspect ratio

Since the aspect ratio is meaningless in that case just don't show it

BUG: 456235
parent de19cde6
Pipeline #217236 passed with stage
in 1 minute and 25 seconds
......@@ -564,27 +564,36 @@ QVariantList OutputModel::resolutionsStrings(const KScreen::OutputPtr &output) c
QVariantList ret;
const auto resolutionList = resolutions(output);
for (const QSize &size : resolutionList) {
int divisor = greatestCommonDivisor(size.width(), size.height());
if (size.height() / divisor == 5) { // Prefer "16:10" over "8:5"
divisor /= 2;
} else if (size.height() / divisor == 27) { // Prefer "21:9" over "64:27"
divisor *= 3;
} else if (size.height() / divisor == 18) { // Prefer "21:9" over "43:18"
divisor *= 2;
} else if (size.height() / divisor == 384) { // Prefer "16:9" over "683:384"
divisor *= 41;
}
if (size.isEmpty()) {
const QString text = i18nc("Width x height",
"%1x%2",
// Explicitly not have it add thousand-separators.
QString::number(size.width()),
QString::number(size.height()));
ret << text;
} else {
int divisor = greatestCommonDivisor(size.width(), size.height());
if (size.height() / divisor == 5) { // Prefer "16:10" over "8:5"
divisor /= 2;
} else if (size.height() / divisor == 27) { // Prefer "21:9" over "64:27"
divisor *= 3;
} else if (size.height() / divisor == 18) { // Prefer "21:9" over "43:18"
divisor *= 2;
} else if (size.height() / divisor == 384) { // Prefer "16:9" over "683:384"
divisor *= 41;
}
const QString text = i18nc("Width x height (aspect ratio)",
"%1x%2 (%3:%4)",
// Explicitly not have it add thousand-separators.
QString::number(size.width()),
QString::number(size.height()),
size.width() / divisor,
size.height() / divisor);
const QString text = i18nc("Width x height (aspect ratio)",
"%1x%2 (%3:%4)",
// Explicitly not have it add thousand-separators.
QString::number(size.width()),
QString::number(size.height()),
size.width() / divisor,
size.height() / divisor);
ret << text;
ret << text;
}
}
return ret;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment