diff options
Diffstat (limited to 'src/xprivate.cpp')
-rw-r--r-- | src/xprivate.cpp | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/xprivate.cpp b/src/xprivate.cpp index 2f4cd55..0233f5b 100644 --- a/src/xprivate.cpp +++ b/src/xprivate.cpp @@ -284,8 +284,11 @@ void XPrivate::disconnectAllCrtcs() { // Disconnect everything for (auto crtc : _crtcMap.keys()) { - XRRSetCrtcConfig(_display, _screenResources, crtc, CurrentTime, + Status s = XRRSetCrtcConfig(_display, _screenResources, crtc, CurrentTime, 0, 0, None, RR_Rotate_0, nullptr, 0); + if (s != RRSetConfigSuccess) { + qDebug() << "Disconnecting CRTC" << crtc << "failed"; + } } } @@ -396,7 +399,7 @@ next:; return None; } -XRRModeInfo* XPrivate::getPreferredMode(OutputInfo *oi) const +XRRModeInfo* XPrivate::getPreferredMode(OutputInfo *oi, XRRModeInfo *fallback) const { if (oi->output->nmode == 0) { qDebug() << "getPreferredMode: Output" << oi->outputName << "has no modes!?"; @@ -406,7 +409,13 @@ XRRModeInfo* XPrivate::getPreferredMode(OutputInfo *oi) const if (oi->output->npreferred > 0) { mode = oi->output->modes[0]; } else { - mode = getOutputModeForResolution(oi->output, 1920, 1080); + mode = None; + if (fallback != nullptr) { + mode = getOutputModeForResolution(oi->output, fallback->width, fallback->height); + } + if (mode == None) { + mode = getOutputModeForResolution(oi->output, 1920, 1080); + } if (mode == None) { mode = getOutputModeForResolution(oi->output, 1280, 720); } @@ -428,12 +437,12 @@ QList<QSize> XPrivate::getTotalSize(const QList<OutputInfo*> &projectors, const QList<QSize> modes; for (int i = 0; i < max; ++i) { XRRModeInfo *mode = nullptr; - if (i < projectors.size()) { - mode = getPreferredMode(projectors.at(i)); - } - if (mode == nullptr && i < screens.size()) { + if (i < screens.size()) { mode = getPreferredMode(screens.at(i)); } + if (i < projectors.size()) { + mode = getPreferredMode(projectors.at(i), mode); + } if (mode != nullptr) { modes.append(QSize(int(mode->width), int(mode->height))); } @@ -443,23 +452,27 @@ QList<QSize> XPrivate::getTotalSize(const QList<OutputInfo*> &projectors, const bool XPrivate::setOutputResolution(OutputInfo *oi, int x, int y, const QSize &size, bool dryRun) { - RRMode mode = getOutputModeForResolution(oi->output, size); - if (mode == None) { - qDebug() << "Cannot set" << oi->outputName << "to" << size << " since it's not supported"; - if (oi->output->nmode == 0) - return false; - qDebug() << "falling back to its default"; - mode = oi->output->modes[0]; - } - if (!dryRun) { - XRRSetCrtcConfig(_display, - _screenResources, - oi->output->crtc, - CurrentTime, - x, y, mode, - RR_Rotate_0, - &oi->id, 1); - } - qDebug() << "Set" << oi->outputName << "to" << _modeMap[mode]->width << "x" << _modeMap[mode]->height << "-- offset" << x << "/" << y; + RRMode mode = getOutputModeForResolution(oi->output, size); + Status s = RRSetConfigSuccess; + if (mode == None) { + qDebug() << "Cannot set" << oi->outputName << "to" << size << " since it's not supported"; + if (oi->output->nmode == 0) + return false; + qDebug() << "falling back to its default"; + mode = oi->output->modes[0]; + } + if (!dryRun) { + s = XRRSetCrtcConfig(_display, + _screenResources, + oi->output->crtc, + CurrentTime, + x, y, mode, + RR_Rotate_0, + &oi->id, 1); + } + qDebug() << (s != RRSetConfigSuccess ? "Failed to" : "") << "Set" << oi->outputName << "to" << _modeMap[mode]->width << "x" << _modeMap[mode]->height << "-- offset" << x << "/" << y; + if (s == RRSetConfigSuccess) { return true; + } + return false; } |