From 9d52174d6b86d5f45da51b5b4400303ddbba8e20 Mon Sep 17 00:00:00 2001 From: loki Date: Wed, 9 Jun 2021 11:49:31 +0200 Subject: [PATCH] fix selecting incorrect monitor on linux --- sunshine/platform/linux/display.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sunshine/platform/linux/display.cpp b/sunshine/platform/linux/display.cpp index a6f3df9c..1084cccb 100644 --- a/sunshine/platform/linux/display.cpp +++ b/sunshine/platform/linux/display.cpp @@ -176,20 +176,26 @@ struct x11_attr_t : public display_t { screen_res_t screenr { XRRGetScreenResources(xdisplay.get(), xwindow) }; int output = screenr->noutput; - if(streamedMonitor >= output) { - BOOST_LOG(error) << "Could not stream display number ["sv << streamedMonitor << "], there are only ["sv << output << "] displays."sv; + output_info_t result; + int monitor = 0; + for(int x = 0; x < output; ++x) { + output_info_t out_info { XRRGetOutputInfo(xdisplay.get(), screenr.get(), screenr->outputs[x]) }; + if(out_info && out_info->connection == RR_Connected) { + if(monitor++ == streamedMonitor) { + result = std::move(out_info); + break; + } + } + } + + if(!result) { + BOOST_LOG(error) << "Could not stream display number ["sv << streamedMonitor << "], there are only ["sv << monitor << "] displays."sv; return -1; } - output_info_t out_info { XRRGetOutputInfo(xdisplay.get(), screenr.get(), screenr->outputs[streamedMonitor]) }; - if(!out_info || out_info->connection != RR_Connected) { - BOOST_LOG(error) << "Could not stream selected display because it doesn't seem to be connected"sv; - return -1; - } - - crtc_info_t crt_info { XRRGetCrtcInfo(xdisplay.get(), screenr.get(), out_info->crtc) }; + crtc_info_t crt_info { XRRGetCrtcInfo(xdisplay.get(), screenr.get(), result->crtc) }; BOOST_LOG(info) - << "Streaming display: "sv << out_info->name << " with res "sv << crt_info->width << 'x' << crt_info->height << " offset by "sv << crt_info->x << 'x' << crt_info->y; + << "Streaming display: "sv << result->name << " with res "sv << crt_info->width << 'x' << crt_info->height << " offset by "sv << crt_info->x << 'x' << crt_info->y; width = crt_info->width; height = crt_info->height;