2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-08-28 07:52:35 +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
|
|
|
|
*/
|
2014-08-28 07:52:35 +00:00
|
|
|
#include "compositor_interface.h"
|
|
|
|
#include "display.h"
|
2014-11-13 14:07:31 +00:00
|
|
|
#include "global_p.h"
|
2014-08-28 07:52:35 +00:00
|
|
|
#include "surface_interface.h"
|
2014-09-18 13:31:01 +00:00
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
class CompositorInterface::Private : public Global::Private
|
2014-09-18 13:31:01 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private(CompositorInterface *q, Display *d);
|
|
|
|
|
|
|
|
private:
|
2014-11-13 17:43:18 +00:00
|
|
|
void bind(wl_client *client, uint32_t version, uint32_t id) override;
|
2014-09-18 13:31:01 +00:00
|
|
|
void createSurface(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
void createRegion(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
|
|
|
|
static void unbind(wl_resource *resource);
|
|
|
|
static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
static void createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
|
|
|
static Private *cast(wl_resource *r) {
|
|
|
|
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositorInterface *q;
|
|
|
|
static const struct wl_compositor_interface s_interface;
|
2015-09-10 07:23:36 +00:00
|
|
|
static const quint32 s_version;
|
2014-09-18 13:31:01 +00:00
|
|
|
};
|
|
|
|
|
2019-05-08 07:38:37 +00:00
|
|
|
const quint32 CompositorInterface::Private::s_version = 4;
|
2015-09-10 07:23:36 +00:00
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
CompositorInterface::Private::Private(CompositorInterface *q, Display *d)
|
2014-11-13 17:43:18 +00:00
|
|
|
: Global::Private(d, &wl_compositor_interface, s_version)
|
2014-09-18 13:31:01 +00:00
|
|
|
, q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-23 11:20:45 +00:00
|
|
|
#ifndef K_DOXYGEN
|
2014-09-18 13:31:01 +00:00
|
|
|
const struct wl_compositor_interface CompositorInterface::Private::s_interface = {
|
|
|
|
createSurfaceCallback,
|
|
|
|
createRegionCallback
|
2014-08-28 07:52:35 +00:00
|
|
|
};
|
2015-09-09 14:39:50 +00:00
|
|
|
#endif
|
2014-08-28 07:52:35 +00:00
|
|
|
|
|
|
|
CompositorInterface::CompositorInterface(Display *display, QObject *parent)
|
2014-11-13 14:07:31 +00:00
|
|
|
: Global(new Private(this, display), parent)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
CompositorInterface::~CompositorInterface() = default;
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
void CompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2014-11-19 18:01:15 +00:00
|
|
|
auto c = display->getConnection(client);
|
|
|
|
wl_resource *resource = c->createResource(&wl_compositor_interface, qMin(version, s_version), id);
|
2014-08-28 07:52:35 +00:00
|
|
|
if (!resource) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-18 13:31:01 +00:00
|
|
|
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
2014-08-28 07:52:35 +00:00
|
|
|
// TODO: should we track?
|
|
|
|
}
|
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
void CompositorInterface::Private::unbind(wl_resource *resource)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
// TODO: implement?
|
|
|
|
}
|
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
void CompositorInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2014-09-18 13:31:01 +00:00
|
|
|
cast(resource)->createSurface(client, resource, id);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2014-11-20 15:40:14 +00:00
|
|
|
SurfaceInterface *surface = new SurfaceInterface(q, resource);
|
2014-11-19 15:53:56 +00:00
|
|
|
surface->create(display->getConnection(client), wl_resource_get_version(resource), id);
|
2014-11-13 12:05:01 +00:00
|
|
|
if (!surface->resource()) {
|
2014-08-28 07:52:35 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
delete surface;
|
|
|
|
return;
|
|
|
|
}
|
2014-09-18 13:31:01 +00:00
|
|
|
emit q->surfaceCreated(surface);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
void CompositorInterface::Private::createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2014-09-18 13:31:01 +00:00
|
|
|
cast(resource)->createRegion(client, resource, id);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 13:31:01 +00:00
|
|
|
void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *resource, uint32_t id)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2020-07-01 18:38:27 +00:00
|
|
|
wl_resource *regionResource = wl_resource_create(client, &wl_region_interface,
|
|
|
|
wl_resource_get_version(resource), id);
|
|
|
|
if (!regionResource) {
|
2014-10-16 11:04:51 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
2020-07-01 18:38:27 +00:00
|
|
|
emit q->regionCreated(new RegionInterface(q, regionResource));
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|