summaryrefslogtreecommitdiffstats
path: root/src/xx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xx.cpp')
-rw-r--r--src/xx.cpp66
1 files changed, 15 insertions, 51 deletions
diff --git a/src/xx.cpp b/src/xx.cpp
index 85f843f..6080316 100644
--- a/src/xx.cpp
+++ b/src/xx.cpp
@@ -250,52 +250,6 @@ QMap<QString, ScreenInfo> ScreenSetup::getScreenPositions() const
return ret;
}
-/**
- * Create common modes and add them to all outputs.
- * Make sure every output has some variant of the most commonly
- * used modes.
- */
-void ScreenSetup::initModes()
-{
- // First copy typical resolutions to all outputs
-#define RES(x,y) (((y) << 16) | (x))
- QSet<quint32> wanted;
- wanted << RES(1280, 720) << RES(1280, 800) << RES(1920, 1080);
- for (XRRModeInfo *mode : a->_modeMap) {
- if (toVertRefresh(mode) < 55 || toVertRefresh(mode) > 65)
- continue; // Play it safe and consider only those for copying that are 60Hz
- if (!wanted.remove(RES(mode->width, mode->height)))
- continue; // Is not a wanted resolution
- // Make sure all outputs got it
- for (OutputInfo *info : a->_outputMap) {
- if (!a->getOutputModeForResolution(info->output, mode->width, mode->height).isEmpty())
- continue;
- XRRAddOutputMode(a->_display, info->id, mode->id);
- qDebug() << "Adding mode" << mode->width << 'x' << mode->height << "to" << info->outputName;
- }
- }
-#undef RES
- // Create those that no output supported
- for (auto res : wanted) {
- unsigned int x = res & 0xffff;
- unsigned int y = res >> 16;
- qDebug() << "Creating missing wanted resolution of" << x << "x" << y;
- createMode(x, y, 60, QString::asprintf("%ux%u", x, y));
- }
- if (!wanted.isEmpty()) { // Modes were added, update for final loop below
- updateScreenResources();
- }
- // Finally copy all those the projector supports to other outputs
- for (auto key : a->_outputMap.keys()) {
- OutputInfo *oi = a->_outputMap[key];
- if (oi->outputType == Projector::Yes && oi->output->npreferred > 0) { // Only if has edid
- qDebug() << "Copying" << oi->output->nmode << "modes to all from" << oi->outputName;
- a->copyModesToAll(key, oi->output->nmode);
- }
- }
- updateScreenResources();
-}
-
static QSize getTotalSizeHorz(const QList<QSize> &list)
{
QSize ret(0, 0);
@@ -416,6 +370,8 @@ ConfigBackup ScreenSetup::setDefaultMode(ScreenMode &mode)
mode = ScreenMode::Advanced; // Dunno lol
return retval;
}
+ // We now have a list of projectors and screens.
+ // Make them cloning pairs.
for (;;) {
QSize screenSize = getTotalSizeHorz(outputSizes);
QStringList cmd;
@@ -428,13 +384,13 @@ ConfigBackup ScreenSetup::setDefaultMode(ScreenMode &mode)
const QSize &size = outputSizes.at(i);
unsigned int w = 0;
if (i < projectors.size()) {
- auto *mode = a->setOutputResolution(cmd, projectors.at(i), offset, 0, size);
+ auto *mode = a->setOutputResolution(cmd, projectors.at(i), offset, 0, size, size);
if (mode != nullptr && mode->width > w) {
w = mode->width;
}
}
if (i < screens.size()) {
- auto *mode = a->setOutputResolution(cmd, screens.at(i), offset, 0, size);
+ auto *mode = a->setOutputResolution(cmd, screens.at(i), offset, 0, size, size);
if (mode != nullptr && mode->width > w) {
w = mode->width;
}
@@ -584,7 +540,7 @@ ConfigBackup ScreenSetup::setClone(const QSize &resolution)
QStringList cmd;
ConfigBackup retval = createCrtcBackup();
for (auto oi : a->_outputMap) {
- a->setOutputResolution(cmd, oi, 0, 0, resolution);
+ a->setOutputResolution(cmd, oi, 0, 0, resolution, resolution);
}
retval._ok = runXrandr(cmd);
return retval;
@@ -658,10 +614,16 @@ static bool modeBiggerThan(const QSize &a, const QSize &b)
return a.width() == b.width() && a.height() > b.height();
}
-ResolutionVector ScreenSetup::getCommonModes() const
+ResolutionVector ScreenSetup::getCommonModes(bool projectorsOnly) const
{
QHash<QPair<quint32, quint32>, QSet<RROutput>> matches;
+ int expectedNum = 0;
+ // For all outputs
for (auto oi : a->_outputMap) {
+ if (projectorsOnly && oi->outputType == Projector::No)
+ continue;
+ expectedNum++;
+ // Validate all modes, add to match map's set
for (int i = 0; i < oi->output->nmode; ++i) {
if (!a->_modeMap.contains(oi->output->modes[i]))
continue;
@@ -672,7 +634,9 @@ ResolutionVector ScreenSetup::getCommonModes() const
}
ResolutionVector ret;
for (auto it = matches.begin(); it != matches.end(); ++it) {
- if (it.value().size() == a->_outputMap.size()) {
+ // If a resolution in the map contains all the outputs we expect, it
+ // means it's a common mode
+ if (it.value().size() == expectedNum) {
ret.append(QSize(int(it.key().first), int(it.key().second)));
}
}