Commit 1c4a22b3 authored by Adrien Faveraux's avatar Adrien Faveraux Committed by Vlad Zahorodnii
Browse files

move server decoration palette to new approach

parent 82277dbb
......@@ -105,8 +105,6 @@ void TestServerSideDecorationPalette::init()
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_paletteManagerInterface = m_display->createServerSideDecorationPaletteManager(m_display);
m_paletteManagerInterface->create();
QVERIFY(m_paletteManagerInterface->isValid());
QVERIFY(registrySpy.wait());
m_paletteManager = registry.createServerSideDecorationPaletteManager(registrySpy.first().first().value<quint32>(), registrySpy.first().last().value<quint32>(), this);
......
......@@ -188,9 +188,9 @@ ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
BASENAME appmenu
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/server-decoration-palette.xml
BASENAME server_decoration_palette
BASENAME server-decoration-palette
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
......
......@@ -6,192 +6,138 @@
#include "server_decoration_palette_interface.h"
#include "display.h"
#include "surface_interface.h"
#include "global_p.h"
#include "resource_p.h"
#include "logging.h"
#include <QtGlobal>
#include <wayland-server_decoration_palette-server-protocol.h>
#include <qwayland-server-server-decoration-palette.h>
namespace KWaylandServer
{
class ServerSideDecorationPaletteManagerInterface::Private : public Global::Private
class ServerSideDecorationPaletteManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration_palette_manager
{
public:
Private(ServerSideDecorationPaletteManagerInterface *q, Display *d);
ServerSideDecorationPaletteManagerInterfacePrivate(ServerSideDecorationPaletteManagerInterface *q, Display *display);
QVector<ServerSideDecorationPaletteInterface*> palettes;
private:
void bind(wl_client *client, uint32_t version, uint32_t id) override;
static void unbind(wl_resource *resource);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
static void createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface);
private:
ServerSideDecorationPaletteManagerInterface *q;
static const struct org_kde_kwin_server_decoration_palette_manager_interface s_interface;
static const quint32 s_version;
};
const quint32 ServerSideDecorationPaletteManagerInterface::Private::s_version = 1;
protected:
void org_kde_kwin_server_decoration_palette_manager_create(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
#ifndef K_DOXYGEN
const struct org_kde_kwin_server_decoration_palette_manager_interface ServerSideDecorationPaletteManagerInterface::Private::s_interface = {
createCallback
};
#endif
void ServerSideDecorationPaletteManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
{
auto p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
Q_ASSERT(p);
const quint32 ServerSideDecorationPaletteManagerInterfacePrivate::s_version = 1;
void ServerSideDecorationPaletteManagerInterfacePrivate::org_kde_kwin_server_decoration_palette_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
{
SurfaceInterface *s = SurfaceInterface::get(surface);
if (!s) {
// TODO: send error?
wl_resource_post_error(resource->handle, 0, "invalid surface");
qCWarning(KWAYLAND_SERVER) << "ServerSideDecorationPaletteInterface requested for non existing SurfaceInterface";
return;
}
auto palette = new ServerSideDecorationPaletteInterface(p->q, s, resource);
palette->create(p->display->getConnection(client), wl_resource_get_version(resource), id);
if (!palette->resource()) {
wl_resource_post_no_memory(resource);
delete palette;
wl_resource *palette_resource = wl_resource_create(resource->client(), &org_kde_kwin_server_decoration_palette_interface, resource->version(), id);
if (!palette_resource) {
wl_client_post_no_memory(resource->client());
return;
}
p->palettes.append(palette);
QObject::connect(palette, &QObject::destroyed, p->q, [=]() {
p->palettes.removeOne(palette);
auto palette = new ServerSideDecorationPaletteInterface(s, palette_resource);
palettes.append(palette);
QObject::connect(palette, &QObject::destroyed, q, [=]() {
palettes.removeOne(palette);
});
emit p->q->paletteCreated(palette);
emit q->paletteCreated(palette);
}
ServerSideDecorationPaletteManagerInterface::Private::Private(ServerSideDecorationPaletteManagerInterface *q, Display *d)
: Global::Private(d, &org_kde_kwin_server_decoration_palette_manager_interface, s_version)
, q(q)
ServerSideDecorationPaletteManagerInterfacePrivate::ServerSideDecorationPaletteManagerInterfacePrivate(ServerSideDecorationPaletteManagerInterface *_q, Display *display)
: QtWaylandServer::org_kde_kwin_server_decoration_palette_manager(*display, s_version)
, q(_q)
{
}
void ServerSideDecorationPaletteManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
ServerSideDecorationPaletteManagerInterface::ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent)
: QObject(parent)
, d(new ServerSideDecorationPaletteManagerInterfacePrivate(this, display))
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&org_kde_kwin_server_decoration_palette_manager_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &s_interface, this, unbind);
}
void ServerSideDecorationPaletteManagerInterface::Private::unbind(wl_resource *resource)
ServerSideDecorationPaletteManagerInterface::~ServerSideDecorationPaletteManagerInterface() = default;
ServerSideDecorationPaletteInterface *ServerSideDecorationPaletteManagerInterface::paletteForSurface(SurfaceInterface *surface)
{
Q_UNUSED(resource)
for (ServerSideDecorationPaletteInterface *menu : qAsConst(d->palettes)) {
if (menu->surface() == surface) {
return menu;
}
}
return nullptr;
}
class ServerSideDecorationPaletteInterface::Private : public Resource::Private
class ServerSideDecorationPaletteInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration_palette
{
public:
Private(ServerSideDecorationPaletteInterface *q, ServerSideDecorationPaletteManagerInterface *c, SurfaceInterface *surface, wl_resource *parentResource);
~Private();
ServerSideDecorationPaletteInterfacePrivate(ServerSideDecorationPaletteInterface *_q, SurfaceInterface *surface, wl_resource *resource);
SurfaceInterface *surface;
QString palette;
private:
static void setPaletteCallback(wl_client *client, wl_resource *resource, const char * palette);
ServerSideDecorationPaletteInterface *q_func() {
return reinterpret_cast<ServerSideDecorationPaletteInterface *>(q);
}
static ServerSideDecorationPaletteInterface *get(SurfaceInterface *s);
static const struct org_kde_kwin_server_decoration_palette_interface s_interface;
};
ServerSideDecorationPaletteInterface *q;
#ifndef K_DOXYGEN
const struct org_kde_kwin_server_decoration_palette_interface ServerSideDecorationPaletteInterface::Private::s_interface = {
setPaletteCallback,
resourceDestroyedCallback
protected:
void org_kde_kwin_server_decoration_palette_destroy_resource(Resource *resource) override;
void org_kde_kwin_server_decoration_palette_set_palette(Resource *resource, const QString &palette) override;
void org_kde_kwin_server_decoration_palette_release(Resource *resource) override;
};
#endif
void ServerSideDecorationPaletteInterface::Private::setPaletteCallback(wl_client *client, wl_resource *resource, const char * palette)
void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_release(Resource *resource)
{
Q_UNUSED(client);
auto p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
Q_ASSERT(p);
if (p->palette == QLatin1String(palette)) {
return;
}
p->palette = QString::fromUtf8(palette);
emit p->q_func()->paletteChanged(p->palette);
wl_resource_destroy(resource->handle);
}
ServerSideDecorationPaletteInterface::Private::Private(ServerSideDecorationPaletteInterface *q, ServerSideDecorationPaletteManagerInterface *c, SurfaceInterface *s, wl_resource *parentResource)
: Resource::Private(q, c, parentResource, &org_kde_kwin_server_decoration_palette_interface, &s_interface),
surface(s)
void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_set_palette(Resource *resource, const QString &palette)
{
}
Q_UNUSED(resource)
ServerSideDecorationPaletteInterface::Private::~Private()
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
if (this->palette == palette) {
return;
}
this->palette = palette;
emit q->paletteChanged(this->palette);
}
ServerSideDecorationPaletteManagerInterface::ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
{
}
ServerSideDecorationPaletteManagerInterface::~ServerSideDecorationPaletteManagerInterface()
void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
delete q;
}
ServerSideDecorationPaletteManagerInterface::Private *ServerSideDecorationPaletteManagerInterface::d_func() const
{
return reinterpret_cast<ServerSideDecorationPaletteManagerInterface::Private*>(d.data());
}
ServerSideDecorationPaletteInterface* ServerSideDecorationPaletteManagerInterface::paletteForSurface(SurfaceInterface *surface)
{
Q_D();
for (ServerSideDecorationPaletteInterface* menu: d->palettes) {
if (menu->surface() == surface) {
return menu;
}
}
return nullptr;
}
ServerSideDecorationPaletteInterface::ServerSideDecorationPaletteInterface(ServerSideDecorationPaletteManagerInterface *parent, SurfaceInterface *s, wl_resource *parentResource):
Resource(new Private(this, parent, s, parentResource))
ServerSideDecorationPaletteInterfacePrivate::ServerSideDecorationPaletteInterfacePrivate(ServerSideDecorationPaletteInterface *_q, SurfaceInterface *surface, wl_resource *resource)
: QtWaylandServer::org_kde_kwin_server_decoration_palette(resource)
, surface(surface)
, q(_q)
{
}
ServerSideDecorationPaletteInterface::Private *ServerSideDecorationPaletteInterface::d_func() const
ServerSideDecorationPaletteInterface::ServerSideDecorationPaletteInterface(SurfaceInterface *surface, wl_resource *resource)
: QObject()
, d(new ServerSideDecorationPaletteInterfacePrivate(this, surface, resource))
{
return reinterpret_cast<ServerSideDecorationPaletteInterface::Private*>(d.data());
}
ServerSideDecorationPaletteInterface::~ServerSideDecorationPaletteInterface()
{}
ServerSideDecorationPaletteInterface::~ServerSideDecorationPaletteInterface() = default;
QString ServerSideDecorationPaletteInterface::palette() const
{
Q_D();
return d->palette;
}
SurfaceInterface* ServerSideDecorationPaletteInterface::surface() const
{
Q_D();
return d->surface;
}
......
......@@ -6,9 +6,9 @@
#ifndef KWAYLAND_SERVER_DECORATION_PALETTE_INTERFACE_H
#define KWAYLAND_SERVER_DECORATION_PALETTE_INTERFACE_H
#include "global.h"
#include "resource.h"
struct wl_resource;
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
namespace KWaylandServer
......@@ -17,6 +17,8 @@ namespace KWaylandServer
class Display;
class SurfaceInterface;
class ServerSideDecorationPaletteInterface;
class ServerSideDecorationPaletteManagerInterfacePrivate;
class ServerSideDecorationPaletteInterfacePrivate;
/**
* Allows a client to specify a preferred palette to use for server-side window decorations
......@@ -25,11 +27,11 @@ class ServerSideDecorationPaletteInterface;
* and notifies when a new one is created
* @since 5.42
*/
class KWAYLANDSERVER_EXPORT ServerSideDecorationPaletteManagerInterface : public Global
class KWAYLANDSERVER_EXPORT ServerSideDecorationPaletteManagerInterface : public QObject
{
Q_OBJECT
public:
virtual ~ServerSideDecorationPaletteManagerInterface();
~ServerSideDecorationPaletteManagerInterface() override;
/**
* Returns any existing palette for a given surface
* This returns a null pointer if no ServerSideDecorationPaletteInterface exists.
......@@ -45,8 +47,7 @@ Q_SIGNALS:
private:
explicit ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
Private *d_func() const;
QScopedPointer<ServerSideDecorationPaletteManagerInterfacePrivate> d;
};
/**
......@@ -54,11 +55,11 @@ private:
* This interface is attached to a wl_surface and informs the server of a requested palette
* @since 5.42
*/
class KWAYLANDSERVER_EXPORT ServerSideDecorationPaletteInterface : public Resource
class KWAYLANDSERVER_EXPORT ServerSideDecorationPaletteInterface : public QObject
{
Q_OBJECT
public:
virtual ~ServerSideDecorationPaletteInterface();
~ServerSideDecorationPaletteInterface() override;
/**
* @returns the palette or an empty string if unset
......@@ -77,11 +78,10 @@ Q_SIGNALS:
void paletteChanged(const QString &palette);
private:
explicit ServerSideDecorationPaletteInterface(ServerSideDecorationPaletteManagerInterface *parent, SurfaceInterface *s, wl_resource *parentResource);
friend class ServerSideDecorationPaletteManagerInterface;
explicit ServerSideDecorationPaletteInterface(SurfaceInterface *surface, wl_resource *resource);
friend class ServerSideDecorationPaletteManagerInterfacePrivate;
class Private;
Private *d_func() const;
QScopedPointer<ServerSideDecorationPaletteInterfacePrivate> d;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment