From 8be8f771637946812ff78decf6e19364cae6f6d2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 9 Mar 2020 15:41:35 +0100 Subject: Use actually applied resolution when calculating screen offsets --- src/xprivate.cpp | 5 +++-- src/xprivate.h | 2 +- src/xx.cpp | 21 ++++++++++++++++----- src/xx.h | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/xprivate.cpp b/src/xprivate.cpp index c8a45b2..7cb0949 100644 --- a/src/xprivate.cpp +++ b/src/xprivate.cpp @@ -638,13 +638,13 @@ QList XPrivate::getTotalSize(const QList &projectors, const return modes; } -void XPrivate::setOutputResolution(QStringList &args, OutputInfo *oi, int x, int y, const QSize &size) +XRRModeInfo* XPrivate::setOutputResolution(QStringList &args, OutputInfo *oi, int x, int y, const QSize &size) { QList modes = getOutputModeForResolution(oi->output, size); if (modes.isEmpty()) { qDebug() << "Cannot set" << oi->outputName << "to" << size << " since it's not supported"; if (oi->output->nmode == 0) - return; + return nullptr; qDebug() << "falling back to its default mode"; modes.append(oi->output->modes[0]); } @@ -656,4 +656,5 @@ void XPrivate::setOutputResolution(QStringList &args, OutputInfo *oi, int x, int if (x == 0 && y == 0 && !args.contains(QLatin1String("--primary"))) { args.append("--primary"); } + return best; } diff --git a/src/xprivate.h b/src/xprivate.h index d0f2d53..0152fb1 100644 --- a/src/xprivate.h +++ b/src/xprivate.h @@ -53,7 +53,7 @@ public: QList getOutputModeForResolution(const XRROutputInfo *output, unsigned int width, unsigned int height) const; QList getOutputModeForResolution(const XRROutputInfo *output, const QSize &resolution) const; RRCrtc getFreeCrtc(const XRROutputInfo* output) const; - void setOutputResolution(QStringList &args, OutputInfo *oi, int x, int y, const QSize &size); + XRRModeInfo* setOutputResolution(QStringList &args, OutputInfo *oi, int x, int y, const QSize &size); QList getTotalSize(const QList &projectors, const QList &screens) const; void copyModesToAll(RROutput id, int num); diff --git a/src/xx.cpp b/src/xx.cpp index 6e6286e..b8b1eab 100644 --- a/src/xx.cpp +++ b/src/xx.cpp @@ -402,13 +402,20 @@ ConfigBackup ScreenSetup::setDefaultMode(ScreenMode &mode) int offset = 0; for (int i = 0; i < outputSizes.size(); ++i) { const QSize &size = outputSizes.at(i); + unsigned int w = 0; if (i < projectors.size()) { - a->setOutputResolution(cmd, projectors.at(i), offset, 0, size); + auto *mode = a->setOutputResolution(cmd, projectors.at(i), offset, 0, size); + if (mode != nullptr && mode->width > w) { + w = mode->width; + } } if (i < screens.size()) { - a->setOutputResolution(cmd, screens.at(i), offset, 0, size); + auto *mode = a->setOutputResolution(cmd, screens.at(i), offset, 0, size); + if (mode != nullptr && mode->width > w) { + w = mode->width; + } } - offset += size.width(); + offset += w; } retval._ok = runXrandr(cmd); updateScreenResources(); // Re-Read @@ -555,14 +562,18 @@ ConfigBackup ScreenSetup::setCustom(const QList>> &l if (e.second.isEmpty()) continue; const QSize &res = e.first; + unsigned int w = 0; for (auto outputName : e.second) { for (auto oi : a->_outputMap) { if (oi->outputName != outputName) continue; - a->setOutputResolution(cmd, oi, x, 0, res); + auto *mode = a->setOutputResolution(cmd, oi, x, 0, res); + if (mode != nullptr && mode->width > w) { + w = mode->width; + } } } - x += res.width(); + x += w; } retval._ok = runXrandr(cmd); return retval; diff --git a/src/xx.h b/src/xx.h index c3e80e7..cf5a37a 100644 --- a/src/xx.h +++ b/src/xx.h @@ -69,7 +69,7 @@ public: ScreenMode getCurrentMode(); bool hasScreenWithoutEdid(); ConfigBackup setResolutionsFromString(const QString &resolutions, const QString &mapping); - ConfigBackup setDefaultMode(ScreenMode &mode); + ConfigBackup setDefaultMode(ScreenMode &mode); bool createMode(unsigned int resX, unsigned int resY, float refresh, QString name); ConfigBackup setCenteredClone(); ConfigBackup setClone(const QSize &resolution); @@ -79,7 +79,7 @@ public: int queryCurrentOutputCount() const; QMap getScreenPositions() const; const ResolutionVector &getVirtualResolutions() const; - bool runXrandr(QStringList &cmd); + bool runXrandr(QStringList &cmd); // Singleton inline static ScreenSetup* inst() { -- cgit v1.2.3-55-g7522