summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/loginrpc.cpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/loginrpc.cpp b/src/loginrpc.cpp
index 3d6092b..353d824 100644
--- a/src/loginrpc.cpp
+++ b/src/loginrpc.cpp
@@ -8,6 +8,8 @@
#include <QProcess>
#include <QRegularExpression>
+static int doFbOnly(int x, int y, const QStringList &allOutputs);
+
static int setMode(const QString &virtOut, const QString &name, const QStringList &allOutputs);
static int sizeDiff(const QSize &a, const QSize &b)
@@ -184,6 +186,12 @@ void LoginRpc::handleCommandV1(const QString &command)
ret = setMode(bestConMode.output, bestConMode.modeName, allOutputs);
bestConMode.modeName.clear();
}
+ } else {
+ if (ret != 0) {
+ // Do the --fb thing - we had that before and there was a problem, but I don't remember what it
+ // was, and initial testing seems fine!? Not taking notes FTW!
+ ret = doFbOnly(x, y, allOutputs);
+ }
}
// Either -1 if we didn't have a virtual one, or != 0 if xrandr setting failed
// Now as fallback, try enabling a disconnected output only
@@ -192,7 +200,7 @@ void LoginRpc::handleCommandV1(const QString &command)
QRegularExpression re("\\d+$");
QString dis;
int used[10] = {};
- for (QString c : connectedOutputs) {
+ for (const auto & c : connectedOutputs) {
auto m = re.match(c);
if (m.hasMatch()) {
int i = m.captured().toInt();
@@ -201,7 +209,7 @@ void LoginRpc::handleCommandV1(const QString &command)
}
}
}
- for (QString c : disconnectedOutputs) {
+ for (const auto & c : disconnectedOutputs) {
auto m = re.match(c);
if (m.hasMatch()) {
int i = m.captured().toInt();
@@ -220,6 +228,9 @@ void LoginRpc::handleCommandV1(const QString &command)
p.kill();
ret = setMode(dis, name, allOutputs);
}
+ if (lowResFallback && ret != 0) {
+ ret = doFbOnly(x, y, allOutputs);
+ }
// Try this stuff again in case --newmode succeeded but --addmode now didn't (NVIDIA)
if (ret != 0 && !bestDisconMode.modeName.isEmpty()) {
qDebug() << "Ret" << ret << "- Trying to enable best disconnected screen (2)";
@@ -247,12 +258,46 @@ void LoginRpc::handleCommandV1(const QString &command)
emit loginRequest(lines[0], lines[1], lines[2]);
}
+static int doFbOnly(int x, int y, const QStringList &allOutputs)
+{
+ QStringList setMode(QStringLiteral("--verbose"));
+ QProcess p;
+ p.setProcessChannelMode(QProcess::ForwardedChannels);
+ for (const auto &output : allOutputs) {
+ setMode << "--output" << output << "--off";
+ }
+ setMode << "--fb" << QString("%1x%2").arg(x).arg(y);
+ // Set all outputs
+ qDebug() << setMode;
+ p.start("xrandr", setMode);
+ p.waitForFinished(2000);
+ int ret = p.exitCode();
+ p.kill();
+ if (ret != 0)
+ return ret;
+ p.setProcessChannelMode(QProcess::MergedChannels);
+ p.start("xrandr", QStringList("--current"));
+ p.waitForFinished(1000);
+ p.kill();
+ QString xrandrOutput = QString::fromLocal8Bit(p.readAll());
+ QRegularExpression re("current (\\d+) x (\\d+),", QRegularExpression::MultilineOption);
+ QRegularExpressionMatch m = re.match(xrandrOutput);
+ if (!m.hasMatch()) {
+ qDebug() << "Could not query current screen size after setting --fb";
+ } else {
+ if (m.captured(1).toInt() == x && m.captured(2).toInt() == y)
+ return 0;
+ qDebug() << "Screen size after --fb is not" << x << "x" << y << "but" << m.captured();
+ }
+ return -1;
+}
+
static int setMode(const QString &virtOut, const QString &name, const QStringList &allOutputs)
{
QStringList setMode(QStringLiteral("--verbose"));
QProcess p;
p.setProcessChannelMode(QProcess::ForwardedChannels);
- for (auto output : allOutputs) {
+ for (const auto & output : allOutputs) {
if (output == virtOut)
continue; // Skip self
setMode << "--output" << output << "--off";