Port away from KWayland's server-decoration-palette implementation

This commit is contained in:
Vlad Zahorodnii 2023-09-24 11:04:58 +03:00
parent dc6dba231d
commit ff9a6cd3fa
2 changed files with 41 additions and 19 deletions

View file

@ -261,7 +261,9 @@ set( testServerSideDecorationPalette_SRCS
test_server_side_decoration_palette.cpp
)
add_executable(testServerSideDecorationPalette ${testServerSideDecorationPalette_SRCS})
target_link_libraries( testServerSideDecorationPalette Qt::Test Qt::Gui KF6::WaylandClient kwin)
qt6_generate_wayland_protocol_client_sources(testServerSideDecorationPalette FILES
${PLASMA_WAYLAND_PROTOCOLS_DIR}/server-decoration-palette.xml)
target_link_libraries( testServerSideDecorationPalette Qt::Test Qt::Gui KF6::WaylandClient Wayland::Client kwin)
add_test(NAME kwayland-testServerSideDecorationPalette COMMAND testServerSideDecorationPalette)
ecm_mark_as_test(testServerSideDecorationPalette)

View file

@ -12,14 +12,29 @@
#include "wayland/display.h"
#include "wayland/server_decoration_palette.h"
#include "qwayland-server-decoration-palette.h"
#include "KWayland/Client/compositor.h"
#include "KWayland/Client/connection_thread.h"
#include "KWayland/Client/event_queue.h"
#include "KWayland/Client/region.h"
#include "KWayland/Client/registry.h"
#include "KWayland/Client/server_decoration_palette.h"
#include "KWayland/Client/surface.h"
class ServerSideDecorationPaletteManager : public QtWayland::org_kde_kwin_server_decoration_palette_manager
{
};
class ServerSideDecorationPalette : public QObject, public QtWayland::org_kde_kwin_server_decoration_palette
{
Q_OBJECT
public:
~ServerSideDecorationPalette()
{
release();
}
};
class TestServerSideDecorationPalette : public QObject
{
Q_OBJECT
@ -37,7 +52,7 @@ private:
KWin::ServerSideDecorationPaletteManagerInterface *m_paletteManagerInterface;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::Compositor *m_compositor;
KWayland::Client::ServerSideDecorationPaletteManager *m_paletteManager;
ServerSideDecorationPaletteManager *m_paletteManager;
KWayland::Client::EventQueue *m_queue;
QThread *m_thread;
};
@ -81,10 +96,20 @@ void TestServerSideDecorationPalette::init()
m_queue->setup(m_connection);
QVERIFY(m_queue->isValid());
KWayland::Client::Registry registry;
QSignalSpy compositorSpy(&registry, &KWayland::Client::Registry::compositorAnnounced);
m_compositorInterface = new CompositorInterface(m_display, m_display);
m_paletteManagerInterface = new ServerSideDecorationPaletteManagerInterface(m_display, m_display);
QSignalSpy registrySpy(&registry, &KWayland::Client::Registry::serverSideDecorationPaletteManagerAnnounced);
KWayland::Client::Registry registry;
connect(&registry, &KWayland::Client::Registry::interfaceAnnounced, this, [this, &registry](const QByteArray &interfaceName, quint32 name, quint32 version) {
if (interfaceName == org_kde_kwin_server_decoration_palette_manager_interface.name) {
m_paletteManager = new ServerSideDecorationPaletteManager();
m_paletteManager->init(registry.registry(), name, version);
}
});
QSignalSpy interfacesAnnouncedSpy(&registry, &KWayland::Client::Registry::interfacesAnnounced);
QSignalSpy compositorSpy(&registry, &KWayland::Client::Registry::compositorAnnounced);
QVERIFY(!registry.eventQueue());
registry.setEventQueue(m_queue);
@ -92,16 +117,12 @@ void TestServerSideDecorationPalette::init()
registry.create(m_connection->display());
QVERIFY(registry.isValid());
registry.setup();
QVERIFY(interfacesAnnouncedSpy.wait());
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_paletteManagerInterface = new ServerSideDecorationPaletteManagerInterface(m_display, m_display);
QVERIFY(registrySpy.wait());
m_paletteManager =
registry.createServerSideDecorationPaletteManager(registrySpy.first().first().value<quint32>(), registrySpy.first().last().value<quint32>(), this);
QVERIFY(m_compositor);
QVERIFY(m_paletteManager);
}
void TestServerSideDecorationPalette::cleanup()
@ -142,7 +163,8 @@ void TestServerSideDecorationPalette::testCreateAndSet()
QVERIFY(!m_paletteManagerInterface->paletteForSurface(serverSurface));
auto palette = m_paletteManager->create(surface.get(), surface.get());
auto palette = std::make_unique<ServerSideDecorationPalette>();
palette->init(m_paletteManager->create(*surface.get()));
QVERIFY(paletteCreatedSpy.wait());
auto paletteInterface = paletteCreatedSpy.first().first().value<KWin::ServerSideDecorationPaletteInterface *>();
QCOMPARE(m_paletteManagerInterface->paletteForSurface(serverSurface), paletteInterface);
@ -150,15 +172,13 @@ void TestServerSideDecorationPalette::testCreateAndSet()
QCOMPARE(paletteInterface->palette(), QString());
QSignalSpy changedSpy(paletteInterface, &KWin::ServerSideDecorationPaletteInterface::paletteChanged);
palette->setPalette("foobar");
palette->set_palette(QStringLiteral("foobar"));
QVERIFY(changedSpy.wait());
QCOMPARE(paletteInterface->palette(), QString("foobar"));
// and destroy
QSignalSpy destroyedSpy(paletteInterface, &QObject::destroyed);
delete palette;
palette.reset();
QVERIFY(destroyedSpy.wait());
QVERIFY(!m_paletteManagerInterface->paletteForSurface(serverSurface));
}