summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-06-22 15:03:27 +0200
committerSimon Rettberg2020-06-22 15:03:27 +0200
commit9fe8c10aaf55a8aeea924f8f69de432f98256f89 (patch)
tree85e5dee3b5dcda301c6d7e277202aec15a8089dd
parentDbug spam (diff)
downloadslxgreeter-9fe8c10aaf55a8aeea924f8f69de432f98256f89.tar.gz
slxgreeter-9fe8c10aaf55a8aeea924f8f69de432f98256f89.tar.xz
slxgreeter-9fe8c10aaf55a8aeea924f8f69de432f98256f89.zip
Make detection of virtual screen smarter; fall back to disconnected
We try to find a virtual output, set the desired resolution, and disable all real outputs. If we don't find a virtual one, we pick a disconnected output, set the resolution, and disable the remaining outputs. If we don't have a disconnected output, we just take the first one.
-rw-r--r--src/loginrpc.cpp64
1 files changed, 55 insertions, 9 deletions
diff --git a/src/loginrpc.cpp b/src/loginrpc.cpp
index 30534a0..6ad70ec 100644
--- a/src/loginrpc.cpp
+++ b/src/loginrpc.cpp
@@ -5,6 +5,7 @@
#include <QtNetwork/QTcpSocket>
#include <QDebug>
#include <QProcess>
+#include <QRegularExpression>
LoginRpc::LoginRpc(int port, QObject *parent)
: QObject(parent)
@@ -65,17 +66,62 @@ void LoginRpc::handleCommandV1(const QString &command)
<< QString::number(mode->hr) << QString::number(mode->hss) << QString::number(mode->hse) << QString::number(mode->hfl)
<< QString::number(mode->vr) << QString::number(mode->vss) << QString::number(mode->vse) << QString::number(mode->vfl)
<< "-hsync" << "+vsync";
- qDebug() << "Setting mode" << newmode;
- p.setProcessChannelMode(QProcess::ForwardedChannels);
- p.start("xrandr", newmode);
- p.waitForFinished(2000);
- p.kill();
- p.start("xrandr", QStringList() << "--verbose" << "--addmode" << "VIRTUAL1" << name);
- p.waitForFinished(2000);
- p.kill();
- p.start("xrandr", QStringList() << "--verbose" << "--output" << "VIRTUAL1" << "--mode" << name);
+ // Get all outputs
+ QStringList setMode("--verbose");
+ p.setProcessChannelMode(QProcess::MergedChannels);
+ p.start("xrandr");
p.waitForFinished(2000);
+ QString out = QString::fromLocal8Bit(p.readAll());
+ QRegularExpression re("^(\\S+)\\s.*?(\\w+connected)", QRegularExpression::MultilineOption);
+ QRegularExpressionMatchIterator it = re.globalMatch(out);
+ QString disconnectedOut;
+ QString virtOut;
+ QStringList outputs;
+ while (it.hasNext()) {
+ QRegularExpressionMatch m = it.next();
+ QString output = m.captured(1);
+ if (virtOut.isEmpty() && (output == QLatin1String("VIRTUAL1") || output == QLatin1String("VIRTUAL-1")
+ || output == QLatin1String("Virtual1") || output == QLatin1String("Virtual-1")
+ || output == QLatin1String("default"))) {
+ virtOut = output;
+ } else if (disconnectedOut.isEmpty() && m.captured(2) == "disconnected") {
+ disconnectedOut = output;
+ } else {
+ outputs << output;
+ }
+ }
+ if (virtOut.isEmpty() && !disconnectedOut.isEmpty()) {
+ virtOut = disconnectedOut;
+ disconnectedOut.clear();
+ }
+ if (!disconnectedOut.isEmpty()) {
+ outputs << disconnectedOut;
+ }
+ if (virtOut.isEmpty() && !outputs.isEmpty()) {
+ virtOut = outputs.takeFirst();
+ }
+ qDebug() << "Virtual output:" << virtOut << "unwanted additional outputs:" << outputs << "(First disconnected:" << disconnectedOut << ")";
p.kill();
+ if (!virtOut.isEmpty()) {
+ setMode << "--output" << virtOut << "--mode" << name;
+ for (auto output : outputs) {
+ setMode << "--output" << output << "--off";
+ }
+ qDebug() << "Setting mode" << newmode;
+ p.setProcessChannelMode(QProcess::ForwardedChannels);
+ // Create mode
+ p.start("xrandr", newmode);
+ p.waitForFinished(2000);
+ p.kill();
+ // Add to virtual output
+ p.start("xrandr", QStringList() << "--verbose" << "--addmode" << virtOut << name);
+ p.waitForFinished(2000);
+ p.kill();
+ // Set all outputs
+ p.start("xrandr", setMode);
+ p.waitForFinished(2000);
+ p.kill();
+ }
}
}
emit loginRequest(lines[0], lines[1], lines[2]);