diff options
author | Simon Rettberg | 2020-03-09 15:35:46 +0100 |
---|---|---|
committer | Simon Rettberg | 2020-03-09 15:35:46 +0100 |
commit | 28d79985e27a483126ce1b50ac64901db7b29e5e (patch) | |
tree | 6392eefdbb3888813b3c4c15fdb7e617ff71b468 | |
parent | Add -d to dump all screen geometry (diff) | |
download | beamergui-28d79985e27a483126ce1b50ac64901db7b29e5e.tar.gz beamergui-28d79985e27a483126ce1b50ac64901db7b29e5e.tar.xz beamergui-28d79985e27a483126ce1b50ac64901db7b29e5e.zip |
Add --resolutions and --mapping for manual setup
-rw-r--r-- | src/main.cpp | 19 | ||||
-rw-r--r-- | src/xx.cpp | 42 | ||||
-rw-r--r-- | src/xx.h | 9 |
3 files changed, 64 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index eac930b..76ea2cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ namespace { bool _testMode, _autoSetup, _showGui, _backgroundMode, _wakeup, _center, _dumpScreens; +QString _resList, _outputMapping; } namespace CommandLine @@ -69,8 +70,10 @@ int main(int argc, char *argv[]) if (CommandLine::center()) { ScreenSetup::inst()->setCenteredClone(); } else if (CommandLine::autoSetup()) { - ScreenMode mode; - ScreenSetup::inst()->setDefaultMode(mode); + ScreenMode mode; + ScreenSetup::inst()->setDefaultMode(mode); + } else if (!_resList.isEmpty()) { + ScreenSetup::inst()->setResolutionsFromString(_resList, _outputMapping); } else { ScreenSetup::inst()->getCurrentMode(); } @@ -122,6 +125,16 @@ static void parseCommandLine(const QCoreApplication &a) QCommandLineOption oDumpScreens(QStringList() << "d" << "dump", QCoreApplication::translate("main", "Dump all non-overlapping screens.")); parser.addOption(oDumpScreens); + // Pre-configured setup + QCommandLineOption oResList("resolutions", + QCoreApplication::translate("main", "Space separated list of resolutions to apply to outputs." + " Outputs will be assigned in alphabetical order, if no additional" + " output mapping is given."), "WxH [WxH ...]"); + parser.addOption(oResList); + QCommandLineOption oMapping("mapping", + QCoreApplication::translate("main", "Map resolutions (from --resolutions) to output names." + " The list of resolutions is zero-based.", "<index>=<output> [...]")); + parser.addOption(oMapping); // PARSE parser.process(a); _testMode = parser.isSet(oTest); @@ -131,6 +144,8 @@ static void parseCommandLine(const QCoreApplication &a) _wakeup = parser.isSet(oWakeup); _center = parser.isSet(oCenter); _dumpScreens = parser.isSet(oDumpScreens); + _resList = parser.value(oResList); + _outputMapping = parser.value(oMapping); } QTextStream& qStdOut() @@ -6,6 +6,7 @@ #include <QSocketNotifier> #include <QThread> #include <QProcess> +#include <QRegularExpression> /* * This clusterfuck exists because there are name clashes between X11/Xrandr headers @@ -325,6 +326,47 @@ bool ScreenSetup::hasScreenWithoutEdid() return false; } +ConfigBackup ScreenSetup::setResolutionsFromString(const QString &resolutions, const QString &mapping) +{ + auto resListStr = resolutions.split(QRegularExpression(QLatin1String("\\s+")), QString::SkipEmptyParts); + QList<QPair<QSize, QList<QString>>> config; + QRegularExpression re(QLatin1String("^(\\d+)x(\\d+)$")); + for (auto s : resListStr) { + auto m = re.match(s); + if (m.hasMatch()) { + config.append(qMakePair(QSize(m.captured(1).toInt(), m.captured(2).toInt()), QList<QString>())); + qDebug() << "Adding resolution" << s; + } + } + auto outputListStr = mapping.split(QRegularExpression(QLatin1String("\\s+")), QString::SkipEmptyParts); + if (outputListStr.isEmpty()) { + int i = 0; + for (auto *o : a->_outputMap) { + int index = i % config.size(); + auto x = config.at(index).second; + x.append(o->outputName); + config.replace(index, qMakePair(config.at(index).first, x)); + qDebug() << "Resolution" << config.at(index).first << "is now" << config.at(index).second; + ++i; + } + } else { + QRegularExpression re(QLatin1String("^(.+)=(\\d+)$")); + for (auto s : outputListStr) { + auto m = re.match(s); + if (m.hasMatch()) { + int index = m.captured(2).toInt(); + if (index >= 0 && index < config.size()) { + auto x = config.at(index).second; + x.append(m.captured(1)); + config.replace(index, qMakePair(config.at(index).first, x)); + } + } + } + } + qDebug() << config; + return setCustom(config); +} + ConfigBackup ScreenSetup::setDefaultMode(ScreenMode &mode) { ConfigBackup retval; @@ -68,11 +68,12 @@ public: void initModes(); ScreenMode getCurrentMode(); bool hasScreenWithoutEdid(); + ConfigBackup setResolutionsFromString(const QString &resolutions, const QString &mapping); ConfigBackup setDefaultMode(ScreenMode &mode); - bool createMode(unsigned int resX, unsigned int resY, float refresh, QString name); - ConfigBackup setCenteredClone(); - ConfigBackup setClone(const QSize &resolution); - ConfigBackup setCustom(const QList<QPair<QSize, QList<QString>>> &list); + bool createMode(unsigned int resX, unsigned int resY, float refresh, QString name); + ConfigBackup setCenteredClone(); + ConfigBackup setClone(const QSize &resolution); + ConfigBackup setCustom(const QList<QPair<QSize, QList<QString>>> &list); ResolutionVector getCommonModes() const; int getOutputCount() const; int queryCurrentOutputCount() const; |