2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-07-20 09:42:52 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-07-20 09:42:52 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-07-20 09:42:52 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2023-02-09 13:07:56 +00:00
|
|
|
#include "pointer_input.h"
|
2016-07-20 09:42:52 +00:00
|
|
|
#include "wayland_server.h"
|
2021-08-28 18:58:29 +00:00
|
|
|
#include "workspace.h"
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
#include <KWayland/Client/output.h>
|
|
|
|
#include <KWayland/Client/registry.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <KWayland/Client/xdgoutput.h>
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_screen_changes-0");
|
|
|
|
|
|
|
|
class ScreenChangesTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testScreenAddRemove();
|
|
|
|
};
|
|
|
|
|
|
|
|
void ScreenChangesTest::initTestCase()
|
|
|
|
{
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2022-11-16 21:03:50 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024)));
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2016-07-20 09:42:52 +00:00
|
|
|
setenv("QT_QPA_PLATFORM", "wayland", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenChangesTest::init()
|
|
|
|
{
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
2016-07-20 09:42:52 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2023-02-09 13:07:56 +00:00
|
|
|
KWin::input()->pointer()->warp(QPoint(640, 512));
|
2016-07-20 09:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenChangesTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenChangesTest::testScreenAddRemove()
|
|
|
|
{
|
|
|
|
// this test verifies that when a new screen is added it gets synced to Wayland
|
|
|
|
|
|
|
|
// first create a registry to get signals about Outputs announced/removed
|
2022-11-07 21:33:00 +00:00
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy allAnnounced(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
|
|
|
QSignalSpy outputAnnouncedSpy(®istry, &KWayland::Client::Registry::outputAnnounced);
|
|
|
|
QSignalSpy outputRemovedSpy(®istry, &KWayland::Client::Registry::outputRemoved);
|
2016-07-20 09:42:52 +00:00
|
|
|
registry.create(Test::waylandConnection());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(allAnnounced.wait());
|
2022-11-07 21:33:00 +00:00
|
|
|
const auto xdgOMData = registry.interface(KWayland::Client::Registry::Interface::XdgOutputUnstableV1);
|
2018-05-18 13:16:13 +00:00
|
|
|
auto xdgOutputManager = registry.createXdgOutputManager(xdgOMData.name, xdgOMData.version);
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
// should be one output
|
2022-07-11 10:41:15 +00:00
|
|
|
QCOMPARE(workspace()->outputs().count(), 1);
|
2016-07-20 09:42:52 +00:00
|
|
|
QCOMPARE(outputAnnouncedSpy.count(), 1);
|
|
|
|
const quint32 firstOutputId = outputAnnouncedSpy.first().first().value<quint32>();
|
|
|
|
QVERIFY(firstOutputId != 0u);
|
|
|
|
outputAnnouncedSpy.clear();
|
|
|
|
|
|
|
|
// let's announce a new output
|
|
|
|
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
|
2022-11-05 10:43:41 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs",
|
2016-07-20 09:42:52 +00:00
|
|
|
Qt::DirectConnection,
|
|
|
|
Q_ARG(QVector<QRect>, geometries));
|
2022-07-11 10:41:15 +00:00
|
|
|
auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), geometries[0]);
|
|
|
|
QCOMPARE(outputs[1]->geometry(), geometries[1]);
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
// this should result in it getting announced, two new outputs are added...
|
|
|
|
QVERIFY(outputAnnouncedSpy.wait());
|
|
|
|
if (outputAnnouncedSpy.count() < 2) {
|
|
|
|
QVERIFY(outputAnnouncedSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(outputAnnouncedSpy.count(), 2);
|
|
|
|
// ... and afterward the previous output gets removed
|
|
|
|
if (outputRemovedSpy.isEmpty()) {
|
|
|
|
QVERIFY(outputRemovedSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(outputRemovedSpy.count(), 1);
|
|
|
|
QCOMPARE(outputRemovedSpy.first().first().value<quint32>(), firstOutputId);
|
|
|
|
|
|
|
|
// let's wait a little bit to ensure we don't get more events
|
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(outputAnnouncedSpy.count(), 2);
|
|
|
|
QCOMPARE(outputRemovedSpy.count(), 1);
|
|
|
|
|
|
|
|
// let's create the output objects to ensure they are correct
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Output> o1(registry.createOutput(outputAnnouncedSpy.first().first().value<quint32>(), outputAnnouncedSpy.first().last().value<quint32>()));
|
2016-07-20 09:42:52 +00:00
|
|
|
QVERIFY(o1->isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy o1ChangedSpy(o1.get(), &KWayland::Client::Output::changed);
|
2016-07-20 09:42:52 +00:00
|
|
|
QVERIFY(o1ChangedSpy.wait());
|
2022-11-05 10:43:41 +00:00
|
|
|
KWin::Output *serverOutput1 = kwinApp()->outputBackend()->findOutput(o1->name()); // use wl_output.name to find the compositor side output
|
2022-09-05 12:29:56 +00:00
|
|
|
QCOMPARE(o1->globalPosition(), serverOutput1->geometry().topLeft());
|
|
|
|
QCOMPARE(o1->pixelSize(), serverOutput1->modeSize());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Output> o2(registry.createOutput(outputAnnouncedSpy.last().first().value<quint32>(), outputAnnouncedSpy.last().last().value<quint32>()));
|
2016-07-20 09:42:52 +00:00
|
|
|
QVERIFY(o2->isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy o2ChangedSpy(o2.get(), &KWayland::Client::Output::changed);
|
2016-07-20 09:42:52 +00:00
|
|
|
QVERIFY(o2ChangedSpy.wait());
|
2022-11-05 10:43:41 +00:00
|
|
|
KWin::Output *serverOutput2 = kwinApp()->outputBackend()->findOutput(o2->name()); // use wl_output.name to find the compositor side output
|
2022-09-05 12:29:56 +00:00
|
|
|
QCOMPARE(o2->globalPosition(), serverOutput2->geometry().topLeft());
|
|
|
|
QCOMPARE(o2->pixelSize(), serverOutput2->modeSize());
|
2016-07-20 09:42:52 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// and check XDGOutput is synced
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::XdgOutput> xdgO1(xdgOutputManager->getXdgOutput(o1.get()));
|
|
|
|
QSignalSpy xdgO1ChangedSpy(xdgO1.get(), &KWayland::Client::XdgOutput::changed);
|
2018-05-18 13:16:13 +00:00
|
|
|
QVERIFY(xdgO1ChangedSpy.wait());
|
2022-09-05 12:29:56 +00:00
|
|
|
QCOMPARE(xdgO1->logicalPosition(), serverOutput1->geometry().topLeft());
|
|
|
|
QCOMPARE(xdgO1->logicalSize(), serverOutput1->geometry().size());
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::XdgOutput> xdgO2(xdgOutputManager->getXdgOutput(o2.get()));
|
|
|
|
QSignalSpy xdgO2ChangedSpy(xdgO2.get(), &KWayland::Client::XdgOutput::changed);
|
2018-05-18 13:16:13 +00:00
|
|
|
QVERIFY(xdgO2ChangedSpy.wait());
|
2022-09-05 12:29:56 +00:00
|
|
|
QCOMPARE(xdgO2->logicalPosition(), serverOutput2->geometry().topLeft());
|
|
|
|
QCOMPARE(xdgO2->logicalSize(), serverOutput2->geometry().size());
|
2018-05-18 13:16:13 +00:00
|
|
|
|
2020-04-08 09:38:41 +00:00
|
|
|
QVERIFY(xdgO1->name().startsWith("Virtual-"));
|
|
|
|
QVERIFY(xdgO1->name() != xdgO2->name());
|
|
|
|
QVERIFY(!xdgO1->description().isEmpty());
|
|
|
|
|
2016-07-20 09:42:52 +00:00
|
|
|
// now let's try to remove one output again
|
|
|
|
outputAnnouncedSpy.clear();
|
|
|
|
outputRemovedSpy.clear();
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy o1RemovedSpy(o1.get(), &KWayland::Client::Output::removed);
|
|
|
|
QSignalSpy o2RemovedSpy(o2.get(), &KWayland::Client::Output::removed);
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
const QVector<QRect> geometries2{QRect(0, 0, 1280, 1024)};
|
2022-11-05 10:43:41 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs",
|
2016-07-20 09:42:52 +00:00
|
|
|
Qt::DirectConnection,
|
|
|
|
Q_ARG(QVector<QRect>, geometries2));
|
2022-07-11 10:41:15 +00:00
|
|
|
outputs = workspace()->outputs();
|
2022-07-11 12:20:35 +00:00
|
|
|
QCOMPARE(outputs.count(), 1);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), geometries2.at(0));
|
2016-07-20 09:42:52 +00:00
|
|
|
|
|
|
|
QVERIFY(outputAnnouncedSpy.wait());
|
|
|
|
QCOMPARE(outputAnnouncedSpy.count(), 1);
|
|
|
|
if (o1RemovedSpy.isEmpty()) {
|
|
|
|
QVERIFY(o1RemovedSpy.wait());
|
|
|
|
}
|
|
|
|
if (o2RemovedSpy.isEmpty()) {
|
|
|
|
QVERIFY(o2RemovedSpy.wait());
|
|
|
|
}
|
|
|
|
// now wait a bit to ensure we don't get more events
|
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(outputAnnouncedSpy.count(), 1);
|
|
|
|
QCOMPARE(o1RemovedSpy.count(), 1);
|
|
|
|
QCOMPARE(o2RemovedSpy.count(), 1);
|
|
|
|
QCOMPARE(outputRemovedSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(ScreenChangesTest)
|
|
|
|
#include "screen_changes_test.moc"
|