summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2022-05-31 12:27:49 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-21 02:06:10 +0000
commitd4a0781cd65c1f3c8ac410a80a9331cf4bd47868 (patch)
treebe37ba900608642e11b6acf0d134591a08266a2f /src/plugins
parentdd7fcd633a5dc09591cecb73cef5e99e7e22db73 (diff)
xcb: set primary screen more correctly
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 <wujiang@kylinos.cn> Change-Id: I6af443ff69d347a6d86efc9c8ea7a5d18f4c3e24 Reviewed-by: JiDe Zhang <zhangjide@uniontech.com> Reviewed-by: Jiang Wu <wujiang@kylinos.cn> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit a79e2aafd63071da42212f6d30e64aef878154ab) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.cpp20
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.h1
2 files changed, 17 insertions, 4 deletions
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
index 9179b1ca99..4cdd9250e3 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;
+ }
m_cursor = new QXcbCursor(connection(), this);
@@ -701,6 +702,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()
{
delete m_cursor;
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
index 12c13ef80e..d5191e3195 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
@@ -161,6 +161,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(); }