xcb: Correctly update primary screen status with RandR 1.5

This amends d8f37d94e537aaab4fa960b80aacabe79bcc14c4 .

Fixes: QTBUG-99605
Pick-to: 6.3
Done-with: Liang Qi <liang.qi@qt.io>
Change-Id: Ia4cf67d6ebeed36596c0342302aa0b4af01769bc
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Zhang Hao 2022-01-10 14:59:22 +01:00 committed by Liang Qi
parent 8f7bebb611
commit 38a66aa53a
3 changed files with 37 additions and 11 deletions

View File

@ -191,7 +191,7 @@ void QXcbConnection::updateScreens(const xcb_randr_notify_event_t *event)
} }
} }
qCDebug(lcQpaScreen) << "primary output is" << qAsConst(m_screens).first()->name(); qCDebug(lcQpaScreen) << "updateScreens: primary output is" << qAsConst(m_screens).first()->name();
} }
} }
@ -379,7 +379,7 @@ void QXcbConnection::initializeScreens(bool initialized)
} }
if (!m_screens.isEmpty()) if (!m_screens.isEmpty())
qCDebug(lcQpaScreen) << "primary output is" << qAsConst(m_screens).first()->name(); qCDebug(lcQpaScreen) << "initializeScreens: primary output is" << qAsConst(m_screens).first()->name();
} }
} }
@ -534,11 +534,6 @@ void QXcbConnection::initializeScreensFromMonitor(xcb_screen_iterator_t *it, int
siblings << screen; siblings << screen;
if (primaryScreenNumber() == xcbScreenNumber) {
primaryScreen = screen;
primaryScreen->setPrimary(true);
}
xcb_randr_monitor_info_next(&monitor_iter); xcb_randr_monitor_info_next(&monitor_iter);
} }

View File

@ -705,9 +705,7 @@ void QXcbScreen::setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp
QByteArray ba = connection()->atomName(monitorInfo->name); QByteArray ba = connection()->atomName(monitorInfo->name);
m_outputName = getName(monitorInfo); m_outputName = getName(monitorInfo);
m_primary = monitorInfo->primary;
if (monitorInfo->primary)
m_primary = true;
m_cursor = new QXcbCursor(connection(), this); m_cursor = new QXcbCursor(connection(), this);
} }

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the test suite of the Qt Toolkit. ** This file is part of the test suite of the Qt Toolkit.
@ -42,6 +42,7 @@ private slots:
void xrandr_15_merge_and_unmerge(); void xrandr_15_merge_and_unmerge();
void xrandr_15_scale(); void xrandr_15_scale();
void xrandr_15_off_and_on(); void xrandr_15_off_and_on();
void xrandr_15_primary();
private: private:
void xrandr_process(const QStringList &arguments = {}); void xrandr_process(const QStringList &arguments = {});
@ -199,6 +200,38 @@ void tst_QScreen_Xrandr::xrandr_15_off_and_on()
} }
} }
void tst_QScreen_Xrandr::xrandr_15_primary()
{
QList<QScreen *> screens = QGuiApplication::screens();
int ss = screens.size();
if (ss < 2)
QSKIP("This test requires at least two screens.");
QStringList names;
for (QScreen *s : screens)
names << s->name();
qDebug() << "All screens: " << names;
QScreen *ps = qGuiApp->primaryScreen();
qDebug() << "Current primary screen: " << ps;
QStringList args;
for (QString name : names) {
qDebug() << "Trying to set primary screen:" << name;
args.clear();
args << "--output" << name << "--primary";
xrandr_process(args);
QTest::qWait(500);
QScreen *ps = qGuiApp->primaryScreen();
qDebug() << "Current primary screen: " << ps;
if (ps) {
qDebug() << "primary screen name: " << ps->name();
QVERIFY(ps->name() == name);
}
}
}
void tst_QScreen_Xrandr::xrandr_process(const QStringList &args) void tst_QScreen_Xrandr::xrandr_process(const QStringList &args)
{ {
QString prog = "xrandr"; QString prog = "xrandr";