From 1a4c4b6cbe887886382ce389bf14b97010b88d9e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Sep 2022 16:39:06 +0200 Subject: Try to select an output with an unused index --- src/loginrpc.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/loginrpc.cpp b/src/loginrpc.cpp index 1d36103..86bfe07 100644 --- a/src/loginrpc.cpp +++ b/src/loginrpc.cpp @@ -130,9 +130,33 @@ 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) { + if (ret != 0 && !disconnectedOutputs.isEmpty()) { qDebug() << "Ret:" << ret << "- Trying to enable one disconnected output"; - QString dis = disconnectedOutputs.first(); + QRegularExpression re("\\d+$"); + QString dis; + int used[10] = {}; + for (QString c : connectedOutputs) { + auto m = re.match(c); + if (m.hasMatch()) { + int i = m.captured().toInt(); + if (i >= 0 && i < 10) { + used[i]++; + } + } + } + for (QString c : disconnectedOutputs) { + auto m = re.match(c); + if (m.hasMatch()) { + int i = m.captured().toInt(); + if (i >= 0 && i < 10 && used[i] == 0) { + dis = c; + break; + } + } + } + if (dis.isEmpty()) { + dis = disconnectedOutputs.first(); + } setMode.clear(); setMode << "--verbose" << "--output" << dis << "--mode" << name; for (auto s : allOutputs) { -- cgit v1.2.3-55-g7522