[plasma/krdp] /: examples/streamer: Sync handling of monitor selection

Oliver Beard <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 6050d5f8cfbcc800a07183e1e708fb6294609dc3 by Oliver Beard, on behalf of David Edmundson.
Committed on 03/08/2026 at 20:07.
Pushed by olib into branch 'master'.

examples/streamer: Sync handling of monitor selection

Monitor selection was moved to a std::optional by default unset.
The streamer example was not updated to reflect this.

M  +4    -2    examples/streamer/main.cpp
M  +1    -1    src/PortalSession.cpp

https://invent.kde.org/plasma/krdp/-/commit/6050d5f8cfbcc800a07183e1e708fb6294609dc3

diff --git a/examples/streamer/main.cpp b/examples/streamer/main.cpp
index 451b4c6..bd113cc 100644
--- a/examples/streamer/main.cpp
+++ b/examples/streamer/main.cpp
@@ -25,14 +25,16 @@ int main(int argc, char **argv)
     parser.addHelpOption();
     parser.addOptions({
         {u"quit-after"_s, u"Quit after running for this amount of seconds"_s, u"seconds"_s},
-        {u"monitor"_s, u"Index of the monitor to display."_s, u"monitor"_s, u"-1"_s},
+        {u"monitor"_s, u"Index of the monitor to display."_s, u"monitor"_s},
         {u"quality"_s, u"Encoding quality of the stream, from 0 (lowest) to 100 (highest)"_s, u"quality"_s},
     });
     parser.process(application);
 
     KRdp::PortalSession session;
     PipeWireEncodedStream encodedStream;
-    session.setActiveStream(parser.value(u"monitor"_s).toInt());
+    if (parser.isSet(u"monitor"_s)) {
+        session.setActiveStream(parser.value(u"monitor"_s).toInt());
+    }
     if (parser.isSet(u"quality"_s)) {
         encodedStream.setQuality(parser.value(u"quality"_s).toUShort());
     }
diff --git a/src/PortalSession.cpp b/src/PortalSession.cpp
index 54f3f87..eafd045 100644
--- a/src/PortalSession.cpp
+++ b/src/PortalSession.cpp
@@ -332,7 +332,7 @@ void KRdp::PortalSession::onSessionStarted(uint code, const QVariantMap &result)
             qCDebug(KRDP) << "Started Freedesktop Portal session";
 
             auto streamIndex = activeStream().value_or(0);
-            if (streamIndex >= streams.size()) {
+            if (streamIndex < 0 || streamIndex >= streams.size()) {
                 qCWarning(KRDP) << "Requested monitor index out of range, using first monitor";
                 setActiveStream(0);
                 streamIndex = 0;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.