2021-03-16 17:33:46 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2021 Kevin Ottens <kevin.ottens@enioka.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2021-03-16 17:33:46 +00:00
|
|
|
// KWin
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/plasmawindowmanagement.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2021-03-16 17:33:46 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/plasmawindowmanagement.h"
|
2021-03-16 17:33:46 +00:00
|
|
|
#include "KWayland/Client/region.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
|
|
|
|
|
|
|
class TestActivities : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestActivities(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testEnterLeaveActivity();
|
|
|
|
|
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display;
|
|
|
|
KWin::CompositorInterface *m_compositorInterface;
|
|
|
|
KWin::PlasmaWindowManagementInterface *m_windowManagementInterface;
|
|
|
|
KWin::PlasmaWindowInterface *m_windowInterface;
|
2021-03-16 17:33:46 +00:00
|
|
|
|
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
|
|
|
KWayland::Client::EventQueue *m_queue;
|
|
|
|
KWayland::Client::PlasmaWindowManagement *m_windowManagement;
|
|
|
|
KWayland::Client::PlasmaWindow *m_window;
|
|
|
|
|
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-activities-0");
|
|
|
|
|
|
|
|
TestActivities::TestActivities(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
|
|
|
, m_queue(nullptr)
|
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestActivities::init()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2021-03-16 17:33:46 +00:00
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2021-03-16 17:33:46 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2021-03-16 17:33:46 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
|
2021-03-16 17:33:46 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy windowManagementSpy(®istry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced);
|
2021-03-16 17:33:46 +00:00
|
|
|
|
|
|
|
QVERIFY(!registry.eventQueue());
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
QCOMPARE(registry.eventQueue(), m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
|
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
|
|
|
QVERIFY(compositorSpy.wait());
|
|
|
|
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
|
|
|
|
|
|
|
|
m_windowManagementInterface = new PlasmaWindowManagementInterface(m_display, m_display);
|
|
|
|
|
|
|
|
QVERIFY(windowManagementSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
m_windowManagement =
|
|
|
|
registry.createPlasmaWindowManagement(windowManagementSpy.first().first().value<quint32>(), windowManagementSpy.first().last().value<quint32>(), this);
|
2021-03-16 17:33:46 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy windowSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
|
2021-03-16 17:33:46 +00:00
|
|
|
m_windowInterface = m_windowManagementInterface->createWindow(this, QUuid::createUuid());
|
|
|
|
m_windowInterface->setPid(1337);
|
|
|
|
|
|
|
|
QVERIFY(windowSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
m_window = windowSpy.first().first().value<KWayland::Client::PlasmaWindow *>();
|
2021-03-16 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestActivities::cleanup()
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
2021-03-16 17:33:46 +00:00
|
|
|
}
|
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_windowInterface)
|
|
|
|
CLEANUP(m_windowManagement)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
CLEANUP(m_compositorInterface)
|
|
|
|
CLEANUP(m_windowManagementInterface)
|
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestActivities::testEnterLeaveActivity()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy enterRequestedSpy(m_windowInterface, &KWin::PlasmaWindowInterface::enterPlasmaActivityRequested);
|
2021-03-16 17:33:46 +00:00
|
|
|
m_window->requestEnterActivity(QStringLiteral("0-1"));
|
|
|
|
enterRequestedSpy.wait();
|
|
|
|
|
|
|
|
QCOMPARE(enterRequestedSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
|
|
|
|
|
|
|
|
QSignalSpy activityEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaActivityEntered);
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// agree to the request
|
2021-03-16 17:33:46 +00:00
|
|
|
m_windowInterface->addPlasmaActivity(QStringLiteral("0-1"));
|
|
|
|
QCOMPARE(m_windowInterface->plasmaActivities().length(), 1);
|
|
|
|
QCOMPARE(m_windowInterface->plasmaActivities().first(), QStringLiteral("0-1"));
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// check if the client received the enter
|
2021-03-16 17:33:46 +00:00
|
|
|
activityEnteredSpy.wait();
|
|
|
|
QCOMPARE(activityEnteredSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
|
|
|
|
QCOMPARE(m_window->plasmaActivities().length(), 1);
|
|
|
|
QCOMPARE(m_window->plasmaActivities().first(), QStringLiteral("0-1"));
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// add another activity, server side
|
2021-03-16 17:33:46 +00:00
|
|
|
m_windowInterface->addPlasmaActivity(QStringLiteral("0-3"));
|
|
|
|
activityEnteredSpy.wait();
|
|
|
|
QCOMPARE(activityEnteredSpy.takeFirst().at(0).toString(), QStringLiteral("0-3"));
|
|
|
|
QCOMPARE(m_windowInterface->plasmaActivities().length(), 2);
|
|
|
|
QCOMPARE(m_window->plasmaActivities().length(), 2);
|
|
|
|
QCOMPARE(m_window->plasmaActivities()[1], QStringLiteral("0-3"));
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// remove an activity
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy leaveRequestedSpy(m_windowInterface, &KWin::PlasmaWindowInterface::leavePlasmaActivityRequested);
|
2021-03-16 17:33:46 +00:00
|
|
|
m_window->requestLeaveActivity(QStringLiteral("0-1"));
|
|
|
|
leaveRequestedSpy.wait();
|
|
|
|
|
|
|
|
QCOMPARE(leaveRequestedSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
|
|
|
|
|
|
|
|
QSignalSpy activityLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaActivityLeft);
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// agree to the request
|
2021-03-16 17:33:46 +00:00
|
|
|
m_windowInterface->removePlasmaActivity(QStringLiteral("0-1"));
|
|
|
|
QCOMPARE(m_windowInterface->plasmaActivities().length(), 1);
|
|
|
|
QCOMPARE(m_windowInterface->plasmaActivities().first(), QStringLiteral("0-3"));
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// check if the client received the leave
|
2021-03-16 17:33:46 +00:00
|
|
|
activityLeftSpy.wait();
|
|
|
|
QCOMPARE(activityLeftSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
|
|
|
|
QCOMPARE(m_window->plasmaActivities().length(), 1);
|
|
|
|
QCOMPARE(m_window->plasmaActivities().first(), QStringLiteral("0-3"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestActivities)
|
|
|
|
#include "test_plasma_activities.moc"
|