From a79e2aafd63071da42212f6d30e64aef878154ab Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 31 May 2022 12:27:49 +0200 Subject: [PATCH] xcb: set primary screen more correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example, when having virtual monitor which includes two real monitors, the primary information in xcb_randr_monitor_info_t is normally false, because user can only set it for output. Kudos to Jiang Wu for his first patch and details of the issue. Done-with: Jiang Wu Pick-to: 6.4 6.3 Change-Id: I6af443ff69d347a6d86efc9c8ea7a5d18f4c3e24 Reviewed-by: JiDe Zhang Reviewed-by: Jiang Wu Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/xcb/qxcbscreen.cpp | 20 ++++++++++++++++---- src/plugins/platforms/xcb/qxcbscreen.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 6c30d39234..2a538c9b6e 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -679,10 +679,11 @@ void QXcbScreen::setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp m_sizeMillimeters = virtualDesktop()->physicalSize(); m_outputName = getName(monitorInfo); - if (connection()->primaryScreenNumber() == virtualDesktop()->number() && monitorInfo->primary) - m_primary = true; - else - m_primary = false; + m_primary = false; + if (connection()->primaryScreenNumber() == virtualDesktop()->number()) { + if (monitorInfo->primary || isPrimaryInXScreen()) + m_primary = true; + } updateColorSpaceAndEdid(); } @@ -699,6 +700,17 @@ QString QXcbScreen::defaultName() return name; } +bool QXcbScreen::isPrimaryInXScreen() +{ + auto primary = Q_XCB_REPLY(xcb_randr_get_output_primary, connection()->xcb_connection(), root()); + if (!primary) + qWarning("failed to get the primary output of the screen"); + + const bool isPrimary = primary ? (m_monitor ? m_outputs.contains(primary->output) : m_output == primary->output) : false; + + return isPrimary; +} + QXcbScreen::~QXcbScreen() { } diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index 5a844f944a..49165d3ba4 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -163,6 +163,7 @@ public: void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; } void setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp_t timestamp = XCB_NONE); QString defaultName(); + bool isPrimaryInXScreen(); void windowShown(QXcbWindow *window); QString windowManagerName() const { return m_virtualDesktop->windowManagerName(); }