2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2017 David Edmundson <kde@davidedmundson.co.uk>
|
2018-01-03 10:24:57 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2018-01-03 10:24:57 +00:00
|
|
|
#include "server_decoration_palette_interface.h"
|
|
|
|
#include "display.h"
|
2018-11-20 07:13:42 +00:00
|
|
|
#include "logging.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "surface_interface.h"
|
2018-01-03 10:24:57 +00:00
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
#include <qwayland-server-server-decoration-palette.h>
|
2018-01-03 10:24:57 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
2020-10-02 06:59:57 +00:00
|
|
|
static const quint32 s_version = 1;
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
class ServerSideDecorationPaletteManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration_palette_manager
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteManagerInterfacePrivate(ServerSideDecorationPaletteManagerInterface *q, Display *display);
|
2018-01-03 10:24:57 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
QVector<ServerSideDecorationPaletteInterface *> palettes;
|
2018-01-03 10:24:57 +00:00
|
|
|
ServerSideDecorationPaletteManagerInterface *q;
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
protected:
|
|
|
|
void org_kde_kwin_server_decoration_palette_manager_create(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
|
2018-01-03 10:24:57 +00:00
|
|
|
};
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void ServerSideDecorationPaletteManagerInterfacePrivate::org_kde_kwin_server_decoration_palette_manager_create(Resource *resource,
|
|
|
|
uint32_t id,
|
|
|
|
wl_resource *surface)
|
2020-07-13 07:41:56 +00:00
|
|
|
{
|
2018-01-03 10:24:57 +00:00
|
|
|
SurfaceInterface *s = SurfaceInterface::get(surface);
|
|
|
|
if (!s) {
|
2020-07-13 07:41:56 +00:00
|
|
|
wl_resource_post_error(resource->handle, 0, "invalid surface");
|
2018-01-03 10:24:57 +00:00
|
|
|
qCWarning(KWAYLAND_SERVER) << "ServerSideDecorationPaletteInterface requested for non existing SurfaceInterface";
|
|
|
|
return;
|
|
|
|
}
|
2021-08-29 05:11:06 +00:00
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
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());
|
2018-01-03 10:24:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-13 07:41:56 +00:00
|
|
|
auto palette = new ServerSideDecorationPaletteInterface(s, palette_resource);
|
|
|
|
|
|
|
|
palettes.append(palette);
|
|
|
|
QObject::connect(palette, &QObject::destroyed, q, [=]() {
|
|
|
|
palettes.removeOne(palette);
|
2018-01-03 10:24:57 +00:00
|
|
|
});
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->paletteCreated(palette);
|
2018-01-03 10:24:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
ServerSideDecorationPaletteManagerInterfacePrivate::ServerSideDecorationPaletteManagerInterfacePrivate(ServerSideDecorationPaletteManagerInterface *_q,
|
|
|
|
Display *display)
|
2020-07-13 07:41:56 +00:00
|
|
|
: QtWaylandServer::org_kde_kwin_server_decoration_palette_manager(*display, s_version)
|
|
|
|
, q(_q)
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteManagerInterface::ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new ServerSideDecorationPaletteManagerInterfacePrivate(this, display))
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteManagerInterface::~ServerSideDecorationPaletteManagerInterface() = default;
|
|
|
|
|
|
|
|
ServerSideDecorationPaletteInterface *ServerSideDecorationPaletteManagerInterface::paletteForSurface(SurfaceInterface *surface)
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
2020-07-13 07:41:56 +00:00
|
|
|
for (ServerSideDecorationPaletteInterface *menu : qAsConst(d->palettes)) {
|
|
|
|
if (menu->surface() == surface) {
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2018-01-03 10:24:57 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
class ServerSideDecorationPaletteInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration_palette
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteInterfacePrivate(ServerSideDecorationPaletteInterface *_q, SurfaceInterface *surface, wl_resource *resource);
|
2018-01-03 10:24:57 +00:00
|
|
|
|
|
|
|
SurfaceInterface *surface;
|
|
|
|
QString palette;
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteInterface *q;
|
2018-01-03 10:24:57 +00:00
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
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;
|
2018-01-03 10:24:57 +00:00
|
|
|
};
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_release(Resource *resource)
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
2020-07-13 07:41:56 +00:00
|
|
|
wl_resource_destroy(resource->handle);
|
2018-01-03 10:24:57 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_set_palette(Resource *resource, const QString &palette)
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
2020-07-13 07:41:56 +00:00
|
|
|
Q_UNUSED(resource)
|
2018-01-03 10:24:57 +00:00
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
if (this->palette == palette) {
|
|
|
|
return;
|
2018-01-03 10:24:57 +00:00
|
|
|
}
|
2020-07-13 07:41:56 +00:00
|
|
|
this->palette = palette;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->paletteChanged(this->palette);
|
2018-01-03 10:24:57 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_destroy_resource(Resource *resource)
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
2020-07-13 07:41:56 +00:00
|
|
|
Q_UNUSED(resource)
|
|
|
|
delete q;
|
2018-01-03 10:24:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
ServerSideDecorationPaletteInterfacePrivate::ServerSideDecorationPaletteInterfacePrivate(ServerSideDecorationPaletteInterface *_q,
|
|
|
|
SurfaceInterface *surface,
|
|
|
|
wl_resource *resource)
|
2020-07-13 07:41:56 +00:00
|
|
|
: QtWaylandServer::org_kde_kwin_server_decoration_palette(resource)
|
|
|
|
, surface(surface)
|
|
|
|
, q(_q)
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteInterface::ServerSideDecorationPaletteInterface(SurfaceInterface *surface, wl_resource *resource)
|
|
|
|
: QObject()
|
|
|
|
, d(new ServerSideDecorationPaletteInterfacePrivate(this, surface, resource))
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:41:56 +00:00
|
|
|
ServerSideDecorationPaletteInterface::~ServerSideDecorationPaletteInterface() = default;
|
2018-01-03 10:24:57 +00:00
|
|
|
|
|
|
|
QString ServerSideDecorationPaletteInterface::palette() const
|
|
|
|
{
|
|
|
|
return d->palette;
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
SurfaceInterface *ServerSideDecorationPaletteInterface::surface() const
|
2018-01-03 10:24:57 +00:00
|
|
|
{
|
|
|
|
return d->surface;
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
} // namespace
|