From 74c8f847cafa4c47b89688b3808a66ba396aeeb7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 22 Jun 2020 16:03:31 +0200 Subject: Disable ALL outputs if setting resolution fails NVIDIA cards don't allow setting any resolution on disconnected screens. Simply disable all outputs in that case and set the screen size manually. --- src/loginrpc.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/loginrpc.cpp b/src/loginrpc.cpp index 6ad70ec..bbb1e1d 100644 --- a/src/loginrpc.cpp +++ b/src/loginrpc.cpp @@ -72,14 +72,15 @@ void LoginRpc::handleCommandV1(const QString &command) p.start("xrandr"); p.waitForFinished(2000); QString out = QString::fromLocal8Bit(p.readAll()); - QRegularExpression re("^(\\S+)\\s.*?(\\w+connected)", QRegularExpression::MultilineOption); + QRegularExpression re("^(\\S+)\\s.*?(\\w*connected)", QRegularExpression::MultilineOption); QRegularExpressionMatchIterator it = re.globalMatch(out); QString disconnectedOut; QString virtOut; - QStringList outputs; + QStringList disabledOutputs, allOutputs; while (it.hasNext()) { QRegularExpressionMatch m = it.next(); QString output = m.captured(1); + allOutputs << output; if (virtOut.isEmpty() && (output == QLatin1String("VIRTUAL1") || output == QLatin1String("VIRTUAL-1") || output == QLatin1String("Virtual1") || output == QLatin1String("Virtual-1") || output == QLatin1String("default"))) { @@ -87,7 +88,7 @@ void LoginRpc::handleCommandV1(const QString &command) } else if (disconnectedOut.isEmpty() && m.captured(2) == "disconnected") { disconnectedOut = output; } else { - outputs << output; + disabledOutputs << output; } } if (virtOut.isEmpty() && !disconnectedOut.isEmpty()) { @@ -95,16 +96,16 @@ void LoginRpc::handleCommandV1(const QString &command) disconnectedOut.clear(); } if (!disconnectedOut.isEmpty()) { - outputs << disconnectedOut; + disabledOutputs << disconnectedOut; } - if (virtOut.isEmpty() && !outputs.isEmpty()) { - virtOut = outputs.takeFirst(); + if (virtOut.isEmpty() && !disabledOutputs.isEmpty()) { + virtOut = disabledOutputs.takeFirst(); } - qDebug() << "Virtual output:" << virtOut << "unwanted additional outputs:" << outputs << "(First disconnected:" << disconnectedOut << ")"; + qDebug() << "Virtual output:" << virtOut << "unwanted additional outputs:" << disabledOutputs << "(First disconnected:" << disconnectedOut << ")"; p.kill(); if (!virtOut.isEmpty()) { setMode << "--output" << virtOut << "--mode" << name; - for (auto output : outputs) { + for (auto output : disabledOutputs) { setMode << "--output" << output << "--off"; } qDebug() << "Setting mode" << newmode; @@ -120,7 +121,20 @@ void LoginRpc::handleCommandV1(const QString &command) // Set all outputs p.start("xrandr", setMode); p.waitForFinished(2000); + int ret = p.exitCode(); p.kill(); + if (ret != 0) { + // Play it safe and disable all the outputs + qDebug() << "Command failed, trying to disable all outputs"; + setMode.clear(); + setMode << "--verbose" << "--fb" << name; + for (auto s : allOutputs) { + setMode << "--output" << s << "--off"; + } + p.start("xrandr", setMode); + p.waitForFinished(2000); + p.kill(); + } } } } -- cgit v1.2.3-55-g7522