diff options
Diffstat (limited to 'src/xprivate.cpp')
-rw-r--r-- | src/xprivate.cpp | 67 |
1 files changed, 14 insertions, 53 deletions
diff --git a/src/xprivate.cpp b/src/xprivate.cpp index b8f10b6..370c6f5 100644 --- a/src/xprivate.cpp +++ b/src/xprivate.cpp @@ -7,13 +7,6 @@ static Display* __display; static XErrorHandler old_handler; -static double toVertRefresh(const XRRModeInfo *mode) -{ - if (mode->hTotal > 0 && mode->vTotal > 0) - return (double(mode->dotClock) / (double(mode->hTotal) * double(mode->vTotal))); - return 0; -} - /** * Check list of known model names that falsely report a screen size or similar */ @@ -173,6 +166,7 @@ void XPrivate::updateScreenResources() qDebug() << "updateScreenResources: Outputs"; QHash<RROutput, QString> tempMap; QMap<Projector, int> typeCount; + _allOutputs.clear(); for (int i = 0; i < _screenResources->noutput; ++i) { XRROutputInfo* info = XRRGetOutputInfo( _display, @@ -183,6 +177,7 @@ void XPrivate::updateScreenResources() continue; } const QString outputName = QString::fromLocal8Bit(info->name, info->nameLen); + _allOutputs.append(outputName); tempMap.insert(_screenResources->outputs[i], outputName); if (info->connection == RR_Disconnected) { qDebug() << "Ignoring disconnected output" << outputName; @@ -446,26 +441,6 @@ void XPrivate::addMissingModesFromDtd(XRRScreenResources *res, RROutput outputId } } -void XPrivate::setScreenSize(const QSize &size) -{ - XRRSetScreenSize(_display, DefaultRootWindow(_display), - size.width(), size.height(), - int(25.4 * size.width() / 96.0), // standard dpi that X uses - int(25.4 * size.height() / 96.0)); // standard dpi that X uses -} - -void XPrivate::disconnectAllCrtcs() -{ - // Disconnect everything - for (auto crtc : _crtcMap.keys()) { - Status s = XRRSetCrtcConfig(_display, _screenResources, crtc, CurrentTime, - 0, 0, None, RR_Rotate_0, nullptr, 0); - if (s != RRSetConfigSuccess) { - qDebug() << "Disconnecting CRTC" << crtc << "failed"; - } - } -} - /** * Copy first "num" modes from output to all other outputs if they * dont have a suitable mode yet. @@ -514,6 +489,8 @@ QList<RRMode> XPrivate::getOutputModeForResolution(const XRROutputInfo *output, } // Sort others descending by dotClock qSort(others.begin(), others.end(), [](const XRRModeInfo *a, const XRRModeInfo *b) { + if ((a->modeFlags & RR_DoubleScan) != (b->modeFlags & RR_DoubleScan)) + return (a->modeFlags & RR_DoubleScan) == 0; // Prefer non-interlaced resolutions return toVertRefresh(a) > toVertRefresh(b); }); QList<RRMode> ret; @@ -661,38 +638,22 @@ QList<QSize> XPrivate::getTotalSize(const QList<OutputInfo*> &projectors, const return modes; } -bool XPrivate::setOutputResolution(OutputInfo *oi, int x, int y, const QSize &size, bool dryRun) +void XPrivate::setOutputResolution(QStringList &args, OutputInfo *oi, int x, int y, const QSize &size) { QList<RRMode> modes = getOutputModeForResolution(oi->output, size); - Status s = RRSetConfigSuccess; if (modes.isEmpty()) { 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"; + return; + qDebug() << "falling back to its default mode"; modes.append(oi->output->modes[0]); } - if (!dryRun) { - for (RRMode mode : modes) { - qDebug() << "Trying" << toVertRefresh(_modeMap[mode]) << "Hz"; - s = XRRSetCrtcConfig(_display, - _screenResources, - oi->output->crtc, - CurrentTime, - x, y, mode, - RR_Rotate_0, - &oi->id, 1); - if (s == RRSetConfigSuccess) { - if (x == 0 && y == 0) { - XRRSetOutputPrimary(_display, DefaultRootWindow(_display), oi->id); - } - break; - } - } - } - qDebug() << (s != RRSetConfigSuccess ? "Failed to" : "") << "Set" << oi->outputName << "to" << size << "-- offset" << x << "/" << y; - if (s == RRSetConfigSuccess) { - return true; + // modes list is known to be sorted by preferred resolution/rate, then sorted by highest to lowest rate + // so we just pick the first one for now, as the GUI doesn't offer picking the rate + XRRModeInfo *best = _modeMap[modes.first()]; + args << "--output" << oi->outputName << "--mode" << best->name << "--rate" << QString::number(toVertRefresh(best), 'f', 2); + args << "--x" << QString::number(x) << "--y" << QString::number(y); + if (x == 0 && y == 0 && !args.contains(QLatin1String("--primary"))) { + args.append("--primary"); } - return false; } |