From 5d0935d45fa92296406175f065992669bf2ead1d Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 19 Apr 2022 12:11:07 +0200 Subject: [PATCH] xcb: create fake screen when XRandR 1.2 and later unavailable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep the old behavior from 6.0 to 6.2. Fixes: QTBUG-102637 Pick-to: 6.3 Change-Id: I2e596c7d5161a3dc7a8493358e272a481aee5308 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/xcb/qxcbconnection.h | 1 + .../platforms/xcb/qxcbconnection_screens.cpp | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 6ce71845703..2d55524f6ff 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -226,6 +226,7 @@ private: xcb_randr_get_output_info_reply_t *outputInfo); void destroyScreen(QXcbScreen *screen); void initializeScreens(bool initialized); + void initializeScreensWithoutXRandR(xcb_screen_iterator_t *it, int screenNumber, QXcbScreen **primaryScreen); void initializeScreensFromOutput(xcb_screen_iterator_t *it, int screenNumber, QXcbScreen **primaryScreen); void updateScreen_monitor(QXcbScreen *screen, xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp_t timestamp = XCB_NONE); diff --git a/src/plugins/platforms/xcb/qxcbconnection_screens.cpp b/src/plugins/platforms/xcb/qxcbconnection_screens.cpp index 149824bc929..aa0f2fef658 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_screens.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_screens.cpp @@ -317,6 +317,10 @@ void QXcbConnection::initializeScreens(bool initialized) initializeScreensFromMonitor(&it, xcbScreenNumber, &primaryScreen, initialized); else if (isAtLeastXRandR12()) initializeScreensFromOutput(&it, xcbScreenNumber, &primaryScreen); + else { + qWarning("There is no XRandR 1.2 and later version available. There will be only fake screen(s) to use."); + initializeScreensWithoutXRandR(&it, xcbScreenNumber, &primaryScreen); + } xcb_screen_next(&it); ++xcbScreenNumber; @@ -349,6 +353,26 @@ void QXcbConnection::initializeScreens(bool initialized) } } +void QXcbConnection::initializeScreensWithoutXRandR(xcb_screen_iterator_t *it, int xcbScreenNumber, QXcbScreen **primaryScreen) +{ + // XRandR extension is missing, then create a fake/legacy screen. + xcb_screen_t *xcbScreen = it->data; + QXcbVirtualDesktop *virtualDesktop = new QXcbVirtualDesktop(this, xcbScreen, xcbScreenNumber); + m_virtualDesktops.append(virtualDesktop); + QList siblings; + + QXcbScreen *screen = new QXcbScreen(this, virtualDesktop, XCB_NONE, nullptr); + qCDebug(lcQpaScreen) << "created fake screen" << screen; + m_screens << screen; + + if (primaryScreenNumber() == xcbScreenNumber) { + *primaryScreen = screen; + (*primaryScreen)->setPrimary(true); + } + siblings << screen; + virtualDesktop->setScreens(std::move(siblings)); +} + void QXcbConnection::initializeScreensFromOutput(xcb_screen_iterator_t *it, int xcbScreenNumber, QXcbScreen **primaryScreen) { // Each "screen" in xcb terminology is a virtual desktop,