autotests: Make mapping between KWin::Output and wl_output more robust

Use wl_output.name to find the wl_output for the given server side
output. This way the order in which wl_output globals are announced
won't matter.
This commit is contained in:
Vlad Zahorodnii 2022-09-05 15:29:56 +03:00
parent 64800e72ca
commit a295db01d9
4 changed files with 25 additions and 10 deletions

View file

@ -571,6 +571,7 @@ KWayland::Client::AppMenuManager *waylandAppMenuManager();
WaylandOutputManagementV2 *waylandOutputManagementV2(); WaylandOutputManagementV2 *waylandOutputManagementV2();
KWayland::Client::TextInputManager *waylandTextInputManager(); KWayland::Client::TextInputManager *waylandTextInputManager();
QVector<KWayland::Client::Output *> waylandOutputs(); QVector<KWayland::Client::Output *> waylandOutputs();
KWayland::Client::Output *waylandOutput(const QString &name);
QVector<WaylandOutputDeviceV2 *> waylandOutputDevicesV2(); QVector<WaylandOutputDeviceV2 *> waylandOutputDevicesV2();
bool waitForWaylandSurface(Window *window); bool waitForWaylandSurface(Window *window);

View file

@ -120,27 +120,31 @@ void ScreenChangesTest::testScreenAddRemove()
QSignalSpy o1ChangedSpy(o1.get(), &KWayland::Client::Output::changed); QSignalSpy o1ChangedSpy(o1.get(), &KWayland::Client::Output::changed);
QVERIFY(o1ChangedSpy.isValid()); QVERIFY(o1ChangedSpy.isValid());
QVERIFY(o1ChangedSpy.wait()); QVERIFY(o1ChangedSpy.wait());
QCOMPARE(o1->geometry(), geometries.at(0)); KWin::Output *serverOutput1 = kwinApp()->platform()->findOutput(o1->name()); // use wl_output.name to find the compositor side output
QCOMPARE(o1->globalPosition(), serverOutput1->geometry().topLeft());
QCOMPARE(o1->pixelSize(), serverOutput1->modeSize());
std::unique_ptr<KWayland::Client::Output> o2(registry.createOutput(outputAnnouncedSpy.last().first().value<quint32>(), outputAnnouncedSpy.last().last().value<quint32>())); std::unique_ptr<KWayland::Client::Output> o2(registry.createOutput(outputAnnouncedSpy.last().first().value<quint32>(), outputAnnouncedSpy.last().last().value<quint32>()));
QVERIFY(o2->isValid()); QVERIFY(o2->isValid());
QSignalSpy o2ChangedSpy(o2.get(), &KWayland::Client::Output::changed); QSignalSpy o2ChangedSpy(o2.get(), &KWayland::Client::Output::changed);
QVERIFY(o2ChangedSpy.isValid()); QVERIFY(o2ChangedSpy.isValid());
QVERIFY(o2ChangedSpy.wait()); QVERIFY(o2ChangedSpy.wait());
QCOMPARE(o2->geometry(), geometries.at(1)); KWin::Output *serverOutput2 = kwinApp()->platform()->findOutput(o2->name()); // use wl_output.name to find the compositor side output
QCOMPARE(o2->globalPosition(), serverOutput2->geometry().topLeft());
QCOMPARE(o2->pixelSize(), serverOutput2->modeSize());
// and check XDGOutput is synced // and check XDGOutput is synced
std::unique_ptr<XdgOutput> xdgO1(xdgOutputManager->getXdgOutput(o1.get())); std::unique_ptr<XdgOutput> xdgO1(xdgOutputManager->getXdgOutput(o1.get()));
QSignalSpy xdgO1ChangedSpy(xdgO1.get(), &XdgOutput::changed); QSignalSpy xdgO1ChangedSpy(xdgO1.get(), &XdgOutput::changed);
QVERIFY(xdgO1ChangedSpy.isValid()); QVERIFY(xdgO1ChangedSpy.isValid());
QVERIFY(xdgO1ChangedSpy.wait()); QVERIFY(xdgO1ChangedSpy.wait());
QCOMPARE(xdgO1->logicalPosition(), geometries.at(0).topLeft()); QCOMPARE(xdgO1->logicalPosition(), serverOutput1->geometry().topLeft());
QCOMPARE(xdgO1->logicalSize(), geometries.at(0).size()); QCOMPARE(xdgO1->logicalSize(), serverOutput1->geometry().size());
std::unique_ptr<XdgOutput> xdgO2(xdgOutputManager->getXdgOutput(o2.get())); std::unique_ptr<XdgOutput> xdgO2(xdgOutputManager->getXdgOutput(o2.get()));
QSignalSpy xdgO2ChangedSpy(xdgO2.get(), &XdgOutput::changed); QSignalSpy xdgO2ChangedSpy(xdgO2.get(), &XdgOutput::changed);
QVERIFY(xdgO2ChangedSpy.isValid()); QVERIFY(xdgO2ChangedSpy.isValid());
QVERIFY(xdgO2ChangedSpy.wait()); QVERIFY(xdgO2ChangedSpy.wait());
QCOMPARE(xdgO2->logicalPosition(), geometries.at(1).topLeft()); QCOMPARE(xdgO2->logicalPosition(), serverOutput2->geometry().topLeft());
QCOMPARE(xdgO2->logicalSize(), geometries.at(1).size()); QCOMPARE(xdgO2->logicalSize(), serverOutput2->geometry().size());
QVERIFY(xdgO1->name().startsWith("Virtual-")); QVERIFY(xdgO1->name().startsWith("Virtual-"));
QVERIFY(xdgO1->name() != xdgO2->name()); QVERIFY(xdgO1->name() != xdgO2->name());

View file

@ -640,6 +640,16 @@ QVector<KWayland::Client::Output *> waylandOutputs()
return s_waylandConnection.outputs; return s_waylandConnection.outputs;
} }
KWayland::Client::Output *waylandOutput(const QString &name)
{
for (KWayland::Client::Output *output : std::as_const(s_waylandConnection.outputs)) {
if (output->name() == name) {
return output;
}
}
return nullptr;
}
QVector<KWin::Test::WaylandOutputDeviceV2 *> waylandOutputDevicesV2() QVector<KWin::Test::WaylandOutputDeviceV2 *> waylandOutputDevicesV2()
{ {
return s_waylandConnection.outputDevicesV2; return s_waylandConnection.outputDevicesV2;

View file

@ -561,7 +561,7 @@ void TestXdgShellWindow::testFullscreenMultipleOutputs()
// this test verifies that kwin will place fullscreen windows in the outputs its instructed to // this test verifies that kwin will place fullscreen windows in the outputs its instructed to
const auto outputs = workspace()->outputs(); const auto outputs = workspace()->outputs();
for (int i = 0; i < outputs.count(); ++i) { for (KWin::Output *output : outputs) {
Test::XdgToplevel::States states; Test::XdgToplevel::States states;
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface(); std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
@ -590,10 +590,10 @@ void TestXdgShellWindow::testFullscreenMultipleOutputs()
QVERIFY(states.testFlag(Test::XdgToplevel::State::Activated)); QVERIFY(states.testFlag(Test::XdgToplevel::State::Activated));
// Ask the compositor to show the window in full screen mode. // Ask the compositor to show the window in full screen mode.
shellSurface->set_fullscreen(*Test::waylandOutputs()[i]); shellSurface->set_fullscreen(*Test::waylandOutput(output->name()));
QVERIFY(surfaceConfigureRequestedSpy.wait()); QVERIFY(surfaceConfigureRequestedSpy.wait());
QCOMPARE(surfaceConfigureRequestedSpy.count(), 2); QCOMPARE(surfaceConfigureRequestedSpy.count(), 2);
QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), outputs[i]->geometry().size()); QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), output->geometry().size());
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>()); shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
Test::render(surface.get(), toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), Qt::red); Test::render(surface.get(), toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), Qt::red);
@ -605,7 +605,7 @@ void TestXdgShellWindow::testFullscreenMultipleOutputs()
QVERIFY(window->isFullScreen()); QVERIFY(window->isFullScreen());
QCOMPARE(window->frameGeometry(), outputs[i]->geometry()); QCOMPARE(window->frameGeometry(), output->geometry());
} }
} }