diff --git a/modules/desktop_capture/linux/screen_capturer_x11.cc b/modules/desktop_capture/linux/screen_capturer_x11.cc index 33e332613f..ab1bd7fb7c 100644 --- a/modules/desktop_capture/linux/screen_capturer_x11.cc +++ b/modules/desktop_capture/linux/screen_capturer_x11.cc @@ -205,6 +205,16 @@ void ScreenCapturerX11::UpdateMonitors() { RTC_LOG(LS_INFO) << "XRandR monitor " << m.name << " rect updated."; selected_monitor_rect_ = DesktopRect::MakeXYWH(m.x, m.y, m.width, m.height); + const auto& pixel_buffer_rect = x_server_pixel_buffer_.window_rect(); + if (!pixel_buffer_rect.ContainsRect(selected_monitor_rect_)) { + // This is never expected to happen, but crop the rectangle anyway + // just in case the server returns inconsistent information. + // CaptureScreen() expects `selected_monitor_rect_` to lie within + // the pixel-buffer's rectangle. + RTC_LOG(LS_WARNING) + << "Cropping selected monitor rect to fit the pixel-buffer."; + selected_monitor_rect_.IntersectWith(pixel_buffer_rect); + } return; } } @@ -408,7 +418,12 @@ void ScreenCapturerX11::ScreenConfigurationChanged() { "configuration change."; } - if (!use_randr_) { + if (use_randr_) { + // Adding/removing RANDR monitors can generate a ConfigureNotify event + // without generating any RRScreenChangeNotify event. So it is important to + // update the monitors here even if the screen resolution hasn't changed. + UpdateMonitors(); + } else { selected_monitor_rect_ = DesktopRect::MakeSize(x_server_pixel_buffer_.window_size()); }