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>
This commit is contained in:
Liang Qi 2022-05-31 12:27:49 +02:00 committed by Qt Cherry-pick Bot
parent dd7fcd633a
commit d4a0781cd6
2 changed files with 17 additions and 4 deletions

View File

@ -679,10 +679,11 @@ void QXcbScreen::setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp
m_sizeMillimeters = virtualDesktop()->physicalSize(); m_sizeMillimeters = virtualDesktop()->physicalSize();
m_outputName = getName(monitorInfo); 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); m_cursor = new QXcbCursor(connection(), this);
@ -701,6 +702,17 @@ QString QXcbScreen::defaultName()
return name; 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() QXcbScreen::~QXcbScreen()
{ {
delete m_cursor; delete m_cursor;

View File

@ -161,6 +161,7 @@ public:
void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; } void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; }
void setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp_t timestamp = XCB_NONE); void setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp_t timestamp = XCB_NONE);
QString defaultName(); QString defaultName();
bool isPrimaryInXScreen();
void windowShown(QXcbWindow *window); void windowShown(QXcbWindow *window);
QString windowManagerName() const { return m_virtualDesktop->windowManagerName(); } QString windowManagerName() const { return m_virtualDesktop->windowManagerName(); }