diff options
-rw-r--r-- | src/xprivate.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/xprivate.cpp b/src/xprivate.cpp index 70c1a3f..950c6ce 100644 --- a/src/xprivate.cpp +++ b/src/xprivate.cpp @@ -149,7 +149,7 @@ void XPrivate::updateScreenResources() continue; } bool disconnected = false; - if (info->crtc == None) { + if (info->crtc == None && info->connection == RR_Connected) { disconnected = true; qDebug() << "Connected output" << outputName << "has no CRTC -- trying to find free one"; info->crtc = getFreeCrtc(info); @@ -375,9 +375,36 @@ XRRModeInfo* XPrivate::getPreferredMode(OutputInfo *oi, XRRModeInfo *fallback) c return nullptr; // WTF!? } RRMode mode; + // H4xx0r - Ultrawide screens seem to incorrectly report a 16:9 resultion as their preferred one + // I can only guess this is a safety measure for old/bad OS or gfx cards + // So, determine the aspect ratio by looking at the physical size and if it's ultrawide, look for a + // more fitting resolution in the list of supported ones + if (oi->output->mm_height > 0) { + float ar = float(oi->output->mm_width) / float(oi->output->mm_height); + if (ar >= 1.999f) { // Consider 18:9+ as ultrawide + XRRModeInfo *best = nullptr; + for (int i = 0; i < oi->output->nmode; ++i) { + if (!_modeMap.contains(oi->output->modes[i])) + continue; + auto mode = _modeMap[oi->output->modes[i]]; + if (mode->height == 0) + continue; + float resAr = float(mode->width) / float(mode->height); + if (qAbs(resAr - ar) > 0.02f) // Check if aspect ratios are same + continue; + if (best == nullptr || mode->width > best->width) { + best = mode; // If multiple resolutions match, use the largest one + } + } + if (best != nullptr) + return best; // Ultrawide it is! + } + } + // "Normal" way of determining optimal resolution if (oi->output->npreferred > 0) { mode = oi->output->modes[0]; } else { + // No preferred one, try some more or less clever fallback mode = None; if (fallback != nullptr) { mode = getOutputModeForResolution(oi->output, fallback->width, fallback->height); |