summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2022-09-08 12:39:02 +0200
committerSimon Rettberg2022-09-08 12:39:02 +0200
commit052b5e034055862287a73bdc9e45ded5a7eb8c12 (patch)
tree18952cd59c492c212a5ff258e2e3e799dde10606
parentWarn if X11 is not accelerated/running on llvmpipe (diff)
downloadslxgreeter-052b5e034055862287a73bdc9e45ded5a7eb8c12.tar.gz
slxgreeter-052b5e034055862287a73bdc9e45ded5a7eb8c12.tar.xz
slxgreeter-052b5e034055862287a73bdc9e45ded5a7eb8c12.zip
If no virtual output is found, prefer a disconnected one, then connected
-rw-r--r--src/loginrpc.cpp65
1 files changed, 53 insertions, 12 deletions
diff --git a/src/loginrpc.cpp b/src/loginrpc.cpp
index df28600..1d36103 100644
--- a/src/loginrpc.cpp
+++ b/src/loginrpc.cpp
@@ -59,23 +59,29 @@ void LoginRpc::handleCommandV1(const QString &command)
if (y < 720) y = 720;
if (x > 1920) x = 1920;
if (y > 1080) y = 1080;
- QString name = QString("%1x%2").arg(x).arg(y);
- mode *mode = vert_refresh(x, y, 60, 0, 0, 0);
+ QString name = QString("%1x%2_30").arg(x).arg(y);
+ mode *mode = vert_refresh(x, y, 30, 0, 0, 0);
QProcess p;
+ p.setProcessChannelMode(QProcess::MergedChannels);
+ qDebug() << "Creating new mode via xrandr";
QStringList newmode = QStringList() << "--verbose" << "--newmode" << name << QString::asprintf("%.2f", mode->pclk)
<< 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";
+ // Create mode
+ p.start("xrandr", newmode);
+ p.waitForFinished(2000);
+ //bool lowResFallback = p.exitCode() != 0;
+ p.kill();
// Get all outputs
QStringList setMode("--verbose");
- p.setProcessChannelMode(QProcess::MergedChannels);
p.start("xrandr", QStringList());
p.waitForFinished(2000);
QString out = QString::fromLocal8Bit(p.readAll());
QRegularExpression re("^(\\S+)\\s.*?(\\w*connected)", QRegularExpression::MultilineOption);
QRegularExpressionMatchIterator it = re.globalMatch(out);
QString virtOut, evdiOut;
- QStringList allOutputs;
+ QStringList allOutputs, disconnectedOutputs, connectedOutputs;
while (it.hasNext()) {
QRegularExpressionMatch m = it.next();
QString output = m.captured(1);
@@ -88,6 +94,11 @@ void LoginRpc::handleCommandV1(const QString &command)
} else {
allOutputs << output;
}
+ if (m.captured(2) == QStringLiteral("disconnected")) {
+ disconnectedOutputs << output;
+ } else {
+ connectedOutputs << output;
+ }
}
if (virtOut.isEmpty()) {
virtOut = evdiOut;
@@ -102,12 +113,8 @@ void LoginRpc::handleCommandV1(const QString &command)
for (auto output : allOutputs) {
setMode << "--output" << output << "--off";
}
- qDebug() << "Setting mode" << newmode;
+ qDebug() << "Setting mode" << setMode;
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);
@@ -122,16 +129,50 @@ void LoginRpc::handleCommandV1(const QString &command)
}
}
// 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
if (ret != 0) {
- // Play it safe and disable all the outputs
- qDebug() << "Ret:" << ret << "- Trying to disable all outputs";
+ qDebug() << "Ret:" << ret << "- Trying to enable one disconnected output";
+ QString dis = disconnectedOutputs.first();
setMode.clear();
- setMode << "--verbose" << "--fb" << name; // Explicit framebuffer size
+ setMode << "--verbose" << "--output" << dis << "--mode" << name;
for (auto s : allOutputs) {
+ if (s == dis)
+ continue; // Not the one we need
setMode << "--output" << s << "--off";
}
+ qDebug() << "Setting mode" << setMode;
+ p.setProcessChannelMode(QProcess::ForwardedChannels);
+ // Add to output
+ p.start("xrandr", QStringList() << "--verbose" << "--addmode" << dis << name);
+ p.waitForFinished(2000);
+ p.kill();
+ // Set
p.start("xrandr", setMode);
p.waitForFinished(2000);
+ ret = p.exitCode();
+ p.kill();
+ }
+ // Now as fallback, try enabling just one connected output
+ if (ret != 0) {
+ qDebug() << "Ret:" << ret << "- Trying to enable one connected output";
+ QString conn = connectedOutputs.first();
+ setMode.clear();
+ setMode << "--verbose" << "--output" << conn << "--mode" << name;
+ for (auto s : allOutputs) {
+ if (s == conn)
+ continue; // Not the one we need
+ setMode << "--output" << s << "--off";
+ }
+ qDebug() << "Setting mode" << setMode;
+ p.setProcessChannelMode(QProcess::ForwardedChannels);
+ // Add to output
+ p.start("xrandr", QStringList() << "--verbose" << "--addmode" << conn << name);
+ p.waitForFinished(2000);
+ p.kill();
+ // Set
+ p.start("xrandr", setMode);
+ p.waitForFinished(2000);
+ ret = p.exitCode();
p.kill();
}
}