Port away from KWayland's server-decoration implementation

This commit is contained in:
Vlad Zahorodnii 2023-09-24 10:34:38 +03:00
parent f24a0a5e17
commit dc6dba231d
12 changed files with 78 additions and 83 deletions

View file

@ -79,7 +79,7 @@ void SlidingPopupsTest::initTestCase()
void SlidingPopupsTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection());
}
void SlidingPopupsTest::cleanup()

View file

@ -73,7 +73,7 @@ void WobblyWindowsShadeTest::initTestCase()
void WobblyWindowsShadeTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection());
}
void WobblyWindowsShadeTest::cleanup()

View file

@ -19,7 +19,6 @@
#include <KWayland/Client/compositor.h>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/output.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/surface.h>
#include <QDBusConnection>

View file

@ -47,7 +47,6 @@ class PlasmaWindowManagement;
class Pointer;
class PointerConstraints;
class Seat;
class ServerSideDecorationManager;
class ShadowManager;
class ShmPool;
class SubCompositor;
@ -530,7 +529,6 @@ public:
enum class AdditionalWaylandInterface {
Seat = 1 << 0,
Decoration = 1 << 1,
PlasmaShell = 1 << 2,
WindowManagement = 1 << 3,
PointerConstraints = 1 << 4,
@ -633,7 +631,6 @@ KWayland::Client::SubCompositor *waylandSubCompositor();
KWayland::Client::ShadowManager *waylandShadowManager();
KWayland::Client::ShmPool *waylandShmPool();
KWayland::Client::Seat *waylandSeat();
KWayland::Client::ServerSideDecorationManager *waylandServerSideDecoration();
KWayland::Client::PlasmaShell *waylandPlasmaShell();
KWayland::Client::PlasmaWindowManagement *waylandWindowManagement();
KWayland::Client::PointerConstraints *waylandPointerConstraints();

View file

@ -29,7 +29,6 @@
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/region.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h>
@ -161,7 +160,7 @@ void PointerInputTest::initTestCase()
void PointerInputTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::Decoration | Test::AdditionalWaylandInterface::XdgDecorationV1 | Test::AdditionalWaylandInterface::CursorShapeV1));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::XdgDecorationV1 | Test::AdditionalWaylandInterface::CursorShapeV1));
QVERIFY(Test::waitForWaylandPointer());
m_compositor = Test::waylandCompositor();
m_seat = Test::waylandSeat();

View file

@ -26,7 +26,6 @@
#include <KWayland/Client/compositor.h>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/surface.h>
#include <QDBusConnection>
@ -111,7 +110,7 @@ void QuickTilingTest::initTestCase()
void QuickTilingTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::XdgDecorationV1));
m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor();
@ -452,17 +451,15 @@ void QuickTilingTest::testQuickTilingTouchMove()
{
// test verifies that touch on decoration also allows quick tiling
// see BUG: 390113
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
QVERIFY(surface != nullptr);
std::unique_ptr<KWayland::Client::ServerSideDecoration> deco(Test::waylandServerSideDecoration()->create(surface.get()));
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly));
QVERIFY(shellSurface != nullptr);
std::unique_ptr<Test::XdgToplevelDecorationV1> deco(Test::createXdgToplevelDecorationV1(shellSurface.get()));
QSignalSpy decorationConfigureRequestedSpy(deco.get(), &Test::XdgToplevelDecorationV1::configureRequested);
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested);
// wait for the initial configure event
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested);
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
surface->commit(KWayland::Client::Surface::CommitFlag::None);
QVERIFY(surfaceConfigureRequestedSpy.wait());
QCOMPARE(surfaceConfigureRequestedSpy.count(), 1);

View file

@ -32,7 +32,6 @@
#include <KWayland/Client/pointerconstraints.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/shadow.h>
#include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/subcompositor.h>
@ -271,7 +270,6 @@ static struct
KWayland::Client::EventQueue *queue = nullptr;
KWayland::Client::Compositor *compositor = nullptr;
KWayland::Client::SubCompositor *subCompositor = nullptr;
KWayland::Client::ServerSideDecorationManager *decoration = nullptr;
KWayland::Client::ShadowManager *shadowManager = nullptr;
XdgShell *xdgShell = nullptr;
KWayland::Client::ShmPool *shm = nullptr;
@ -535,13 +533,6 @@ bool setupWaylandConnection(AdditionalWaylandInterfaces flags)
return false;
}
}
if (flags.testFlag(AdditionalWaylandInterface::Decoration)) {
s_waylandConnection.decoration = registry->createServerSideDecorationManager(registry->interface(KWayland::Client::Registry::Interface::ServerSideDecorationManager).name,
registry->interface(KWayland::Client::Registry::Interface::ServerSideDecorationManager).version);
if (!s_waylandConnection.decoration->isValid()) {
return false;
}
}
if (flags.testFlag(AdditionalWaylandInterface::PlasmaShell)) {
s_waylandConnection.plasmaShell = registry->createPlasmaShell(registry->interface(KWayland::Client::Registry::Interface::PlasmaShell).name,
registry->interface(KWayland::Client::Registry::Interface::PlasmaShell).version);
@ -589,10 +580,6 @@ void destroyWaylandConnection()
s_waylandConnection.windowManagement = nullptr;
delete s_waylandConnection.plasmaShell;
s_waylandConnection.plasmaShell = nullptr;
delete s_waylandConnection.decoration;
s_waylandConnection.decoration = nullptr;
delete s_waylandConnection.decoration;
s_waylandConnection.decoration = nullptr;
delete s_waylandConnection.seat;
s_waylandConnection.seat = nullptr;
delete s_waylandConnection.pointerConstraints;
@ -675,11 +662,6 @@ KWayland::Client::Seat *waylandSeat()
return s_waylandConnection.seat;
}
KWayland::Client::ServerSideDecorationManager *waylandServerSideDecoration()
{
return s_waylandConnection.decoration;
}
KWayland::Client::PlasmaShell *waylandPlasmaShell()
{
return s_waylandConnection.plasmaShell;

View file

@ -24,7 +24,6 @@
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/touch.h>
@ -79,7 +78,7 @@ void TransientPlacementTest::initTestCase()
void TransientPlacementTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration | Test::AdditionalWaylandInterface::LayerShellV1));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1));
workspace()->setActiveOutput(QPoint(640, 512));
input()->pointer()->warp(QPoint(640, 512));

View file

@ -31,7 +31,6 @@
#include <KWayland/Client/output.h>
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/subsurface.h>
#include <KWayland/Client/surface.h>

View file

@ -131,6 +131,8 @@ set( testServerSideDecoration_SRCS
test_server_side_decoration.cpp
)
add_executable(testServerSideDecoration ${testServerSideDecoration_SRCS})
qt6_generate_wayland_protocol_client_sources(testServerSideDecoration FILES
${PLASMA_WAYLAND_PROTOCOLS_DIR}/server-decoration.xml)
target_link_libraries( testServerSideDecoration Qt::Test Qt::Gui KF6::WaylandClient kwin Wayland::Client)
add_test(NAME kwayland-testServerSideDecoration COMMAND testServerSideDecoration)
ecm_mark_as_test(testServerSideDecoration)

View file

@ -11,13 +11,38 @@
#include "wayland/display.h"
#include "wayland/server_decoration.h"
#include "qwayland-server-decoration.h"
#include "KWayland/Client/compositor.h"
#include "KWayland/Client/connection_thread.h"
#include "KWayland/Client/event_queue.h"
#include "KWayland/Client/registry.h"
#include "KWayland/Client/server_decoration.h"
#include "KWayland/Client/surface.h"
class ServerSideDecorationManager : public QtWayland::org_kde_kwin_server_decoration_manager
{
};
class ServerSideDecoration : public QObject, public QtWayland::org_kde_kwin_server_decoration
{
Q_OBJECT
public:
~ServerSideDecoration() override
{
release();
}
Q_SIGNALS:
void modeChanged(ServerSideDecorationManager::mode mode);
protected:
void org_kde_kwin_server_decoration_mode(uint32_t mode) override
{
Q_EMIT modeChanged(ServerSideDecorationManager::mode(mode));
}
};
class TestServerSideDecoration : public QObject
{
Q_OBJECT
@ -42,7 +67,7 @@ private:
KWayland::Client::ConnectionThread *m_connection = nullptr;
KWayland::Client::Compositor *m_compositor = nullptr;
KWayland::Client::EventQueue *m_queue = nullptr;
KWayland::Client::ServerSideDecorationManager *m_serverSideDecorationManager = nullptr;
ServerSideDecorationManager *m_serverSideDecorationManager = nullptr;
QThread *m_thread = nullptr;
KWayland::Client::Registry *m_registry = nullptr;
};
@ -80,9 +105,19 @@ void TestServerSideDecoration::init()
m_queue->setup(m_connection);
QVERIFY(m_queue->isValid());
m_compositorInterface = new CompositorInterface(m_display, m_display);
m_serverSideDecorationManagerInterface = new ServerSideDecorationManagerInterface(m_display, m_display);
m_registry = new KWayland::Client::Registry();
connect(m_registry, &KWayland::Client::Registry::interfaceAnnounced, this, [this](const QByteArray &interfaceName, quint32 name, quint32 version) {
if (interfaceName == org_kde_kwin_server_decoration_manager_interface.name) {
m_serverSideDecorationManager = new ServerSideDecorationManager();
m_serverSideDecorationManager->init(*m_registry, name, version);
}
});
QSignalSpy interfacesAnnouncedSpy(m_registry, &KWayland::Client::Registry::interfacesAnnounced);
QSignalSpy compositorSpy(m_registry, &KWayland::Client::Registry::compositorAnnounced);
QSignalSpy serverSideDecoManagerSpy(m_registry, &KWayland::Client::Registry::serverSideDecorationManagerAnnounced);
QVERIFY(!m_registry->eventQueue());
m_registry->setEventQueue(m_queue);
@ -90,17 +125,12 @@ void TestServerSideDecoration::init()
m_registry->create(m_connection);
QVERIFY(m_registry->isValid());
m_registry->setup();
QVERIFY(interfacesAnnouncedSpy.wait());
m_compositorInterface = new CompositorInterface(m_display, m_display);
QVERIFY(compositorSpy.wait());
m_compositor = m_registry->createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_serverSideDecorationManagerInterface = new ServerSideDecorationManagerInterface(m_display, m_display);
QVERIFY(serverSideDecoManagerSpy.wait());
m_serverSideDecorationManager = m_registry->createServerSideDecorationManager(serverSideDecoManagerSpy.first().first().value<quint32>(),
serverSideDecoManagerSpy.first().last().value<quint32>(),
this);
QVERIFY(m_compositor);
QVERIFY(m_serverSideDecorationManager);
}
void TestServerSideDecoration::cleanup()
@ -138,11 +168,11 @@ void TestServerSideDecoration::testCreate_data()
{
using namespace KWin;
QTest::addColumn<ServerSideDecorationManagerInterface::Mode>("serverMode");
QTest::addColumn<KWayland::Client::ServerSideDecoration::Mode>("clientMode");
QTest::addColumn<ServerSideDecorationManager::mode>("clientMode");
QTest::newRow("none") << ServerSideDecorationManagerInterface::Mode::None << KWayland::Client::ServerSideDecoration::Mode::None;
QTest::newRow("client") << ServerSideDecorationManagerInterface::Mode::Client << KWayland::Client::ServerSideDecoration::Mode::Client;
QTest::newRow("server") << ServerSideDecorationManagerInterface::Mode::Server << KWayland::Client::ServerSideDecoration::Mode::Server;
QTest::newRow("none") << ServerSideDecorationManagerInterface::Mode::None << ServerSideDecorationManager::mode_None;
QTest::newRow("client") << ServerSideDecorationManagerInterface::Mode::Client << ServerSideDecorationManager::mode_Client;
QTest::newRow("server") << ServerSideDecorationManagerInterface::Mode::Server << ServerSideDecorationManager::mode_Server;
}
void TestServerSideDecoration::testCreate()
@ -162,9 +192,9 @@ void TestServerSideDecoration::testCreate()
QVERIFY(!ServerSideDecorationInterface::get(serverSurface));
// create server side deco
std::unique_ptr<KWayland::Client::ServerSideDecoration> serverSideDecoration(m_serverSideDecorationManager->create(surface.get()));
QCOMPARE(serverSideDecoration->mode(), KWayland::Client::ServerSideDecoration::Mode::None);
QSignalSpy modeChangedSpy(serverSideDecoration.get(), &KWayland::Client::ServerSideDecoration::modeChanged);
auto serverSideDecoration = std::make_unique<ServerSideDecoration>();
serverSideDecoration->init(m_serverSideDecorationManager->create(*surface.get()));
QSignalSpy modeChangedSpy(serverSideDecoration.get(), &ServerSideDecoration::modeChanged);
QVERIFY(decorationCreated.wait());
@ -176,7 +206,7 @@ void TestServerSideDecoration::testCreate()
// after binding the client should get the default mode
QVERIFY(modeChangedSpy.wait());
QCOMPARE(modeChangedSpy.count(), 1);
QTEST(serverSideDecoration->mode(), "clientMode");
QTEST(modeChangedSpy.last().at(0).value<ServerSideDecorationManager::mode>(), "clientMode");
// and destroy
QSignalSpy destroyedSpy(serverDeco, &QObject::destroyed);
@ -188,16 +218,16 @@ void TestServerSideDecoration::testRequest_data()
{
using namespace KWin;
QTest::addColumn<ServerSideDecorationManagerInterface::Mode>("defaultMode");
QTest::addColumn<KWayland::Client::ServerSideDecoration::Mode>("clientMode");
QTest::addColumn<KWayland::Client::ServerSideDecoration::Mode>("clientRequestMode");
QTest::addColumn<ServerSideDecorationManager::mode>("clientMode");
QTest::addColumn<ServerSideDecorationManager::mode>("clientRequestMode");
QTest::addColumn<ServerSideDecorationManagerInterface::Mode>("serverRequestedMode");
const auto serverNone = ServerSideDecorationManagerInterface::Mode::None;
const auto serverClient = ServerSideDecorationManagerInterface::Mode::Client;
const auto serverServer = ServerSideDecorationManagerInterface::Mode::Server;
const auto clientNone = KWayland::Client::ServerSideDecoration::Mode::None;
const auto clientClient = KWayland::Client::ServerSideDecoration::Mode::Client;
const auto clientServer = KWayland::Client::ServerSideDecoration::Mode::Server;
const auto clientNone = ServerSideDecorationManager::mode_None;
const auto clientClient = ServerSideDecorationManager::mode_Client;
const auto clientServer = ServerSideDecorationManager::mode_Server;
QTest::newRow("none->none") << serverNone << clientNone << clientNone << serverNone;
QTest::newRow("none->client") << serverNone << clientNone << clientClient << serverClient;
@ -222,9 +252,10 @@ void TestServerSideDecoration::testRequest()
// create server side deco
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
std::unique_ptr<KWayland::Client::ServerSideDecoration> serverSideDecoration(m_serverSideDecorationManager->create(surface.get()));
QCOMPARE(serverSideDecoration->mode(), KWayland::Client::ServerSideDecoration::Mode::None);
QSignalSpy modeChangedSpy(serverSideDecoration.get(), &KWayland::Client::ServerSideDecoration::modeChanged);
auto serverSideDecoration = std::make_unique<ServerSideDecoration>();
serverSideDecoration->init(m_serverSideDecorationManager->create(*surface.get()));
QSignalSpy modeChangedSpy(serverSideDecoration.get(), &ServerSideDecoration::modeChanged);
QVERIFY(decorationCreated.wait());
auto serverDeco = decorationCreated.first().first().value<ServerSideDecorationInterface *>();
@ -234,13 +265,13 @@ void TestServerSideDecoration::testRequest()
// after binding the client should get the default mode
QVERIFY(modeChangedSpy.wait());
QCOMPARE(modeChangedSpy.count(), 1);
QTEST(serverSideDecoration->mode(), "clientMode");
QTEST(modeChangedSpy.last().at(0).value<ServerSideDecorationManager::mode>(), "clientMode");
// request a change
QFETCH(KWayland::Client::ServerSideDecoration::Mode, clientRequestMode);
serverSideDecoration->requestMode(clientRequestMode);
QFETCH(ServerSideDecorationManager::mode, clientRequestMode);
serverSideDecoration->request_mode(clientRequestMode);
// mode not yet changed
QTEST(serverSideDecoration->mode(), "clientMode");
QCOMPARE(modeChangedSpy.count(), 1);
QVERIFY(preferredModeChangedSpy.wait());
QCOMPARE(preferredModeChangedSpy.count(), 1);
@ -255,7 +286,7 @@ void TestServerSideDecoration::testRequest()
// should be sent to client
QVERIFY(modeChangedSpy.wait());
QCOMPARE(modeChangedSpy.count(), 2);
QCOMPARE(serverSideDecoration->mode(), clientRequestMode);
QCOMPARE(modeChangedSpy.last().at(0).value<ServerSideDecorationManager::mode>(), clientRequestMode);
}
void TestServerSideDecoration::testSurfaceDestroy()
@ -268,8 +299,9 @@ void TestServerSideDecoration::testSurfaceDestroy()
QVERIFY(serverSurfaceCreated.wait());
auto serverSurface = serverSurfaceCreated.first().first().value<SurfaceInterface *>();
std::unique_ptr<KWayland::Client::ServerSideDecoration> serverSideDecoration(m_serverSideDecorationManager->create(surface.get()));
QCOMPARE(serverSideDecoration->mode(), KWayland::Client::ServerSideDecoration::Mode::None);
auto serverSideDecoration = std::make_unique<ServerSideDecoration>();
serverSideDecoration->init(m_serverSideDecorationManager->create(*surface.get()));
QSignalSpy modeChangedSpy(serverSideDecoration.get(), &ServerSideDecoration::modeChanged);
QVERIFY(decorationCreated.wait());
auto serverDeco = decorationCreated.first().first().value<ServerSideDecorationInterface *>();
QVERIFY(serverDeco);

View file

@ -9,7 +9,6 @@
#include "KWayland/Client/connection_thread.h"
#include "KWayland/Client/event_queue.h"
#include "KWayland/Client/registry.h"
#include "KWayland/Client/server_decoration.h"
#include "KWayland/Client/shell.h"
#include "KWayland/Client/shm_pool.h"
#include "KWayland/Client/xdgshell.h"
@ -49,7 +48,6 @@ private:
KWayland::Client::XdgImporter *m_importer = nullptr;
KWayland::Client::XdgExported *m_exported = nullptr;
KWayland::Client::XdgImported *m_imported = nullptr;
KWayland::Client::ServerSideDecorationManager *m_decoration = nullptr;
};
XdgForeignTest::XdgForeignTest(QObject *parent)
@ -105,10 +103,6 @@ void XdgForeignTest::setupRegistry(Registry *registry)
m_importer = registry->createXdgImporter(name, version, this);
m_importer->setEventQueue(m_eventQueue);
});
connect(registry, &Registry::serverSideDecorationManagerAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_decoration = registry->createServerSideDecorationManager(name, version, this);
m_decoration->setEventQueue(m_eventQueue);
});
connect(registry, &Registry::interfacesAnnounced, this, [this] {
Q_ASSERT(m_compositor);
Q_ASSERT(m_shell);
@ -117,22 +111,17 @@ void XdgForeignTest::setupRegistry(Registry *registry)
Q_ASSERT(m_importer);
m_surface = m_compositor->createSurface(this);
Q_ASSERT(m_surface);
auto parentDeco = m_decoration->create(m_surface, this);
Q_ASSERT(parentDeco);
m_shellSurface = m_shell->createSurface(m_surface, this);
Q_ASSERT(m_shellSurface);
connect(m_shellSurface, &XdgShellSurface::sizeChanged, this, &XdgForeignTest::render);
m_childSurface = m_compositor->createSurface(this);
Q_ASSERT(m_childSurface);
auto childDeco = m_decoration->create(m_childSurface, this);
Q_ASSERT(childDeco);
m_childShellSurface = m_shell->createSurface(m_childSurface, this);
Q_ASSERT(m_childShellSurface);
connect(m_childShellSurface, &XdgShellSurface::sizeChanged, this, &XdgForeignTest::render);
m_exported = m_exporter->exportTopLevel(m_surface, this);
Q_ASSERT(m_decoration);
connect(m_exported, &XdgExported::done, this, [this]() {
m_imported = m_importer->importTopLevel(m_exported->handle(), this);
m_imported->setParentOf(m_childSurface);