Commit 2189579d authored by David Edmundson's avatar David Edmundson Committed by David Edmundson
Browse files

[BlurInterface] Port to the new approach

BlurInterface always used to be my go-to template when starting a new
protocol, we may as well make it up-to-date with the generation.

Code is reduced by a third.
parent 584b1b48
......@@ -105,9 +105,6 @@ void TestBlur::init()
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_blurManagerInterface = m_display->createBlurManager(m_display);
m_blurManagerInterface->create();
QVERIFY(m_blurManagerInterface->isValid());
QVERIFY(blurSpy.wait());
m_blurManager = registry.createBlurManager(blurSpy.first().first().value<quint32>(), blurSpy.first().last().value<quint32>(), this);
}
......
......@@ -86,8 +86,6 @@ void TestFilter::init()
QVERIFY(m_compositorInterface->isValid());
m_blurManagerInterface = m_display->createBlurManager(m_display);
m_blurManagerInterface->create();
QVERIFY(m_blurManagerInterface->isValid());
}
void TestFilter::cleanup()
......
......@@ -156,7 +156,6 @@ void TestWaylandRegistry::init()
m_outputDevice->create();
QVERIFY(m_outputManagement->isValid());
m_blur = m_display->createBlurManager(this);
m_blur->create();
m_contrast = m_display->createContrastManager(this);
m_contrast->create();
m_display->createSlideManager(this)->create();
......
......@@ -122,7 +122,7 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME dpms
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/blur.xml
BASENAME blur
)
......
/*
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "blur_interface.h"
#include "region_interface.h"
#include "display.h"
#include "global_p.h"
#include "resource_p.h"
#include "surface_interface_p.h"
#include <wayland-server.h>
#include <wayland-blur-server-protocol.h>
#include "qwayland-server-blur.h"
namespace KWaylandServer
{
class BlurManagerInterface::Private : public Global::Private
class BlurManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_blur_manager
{
public:
Private(BlurManagerInterface *q, Display *d);
BlurManagerInterfacePrivate(BlurManagerInterface *q, Display *d);
private:
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void createBlur(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
static void createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
static void unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface);
static void unbind(wl_resource *resource);
static Private *cast(wl_resource *r) {
auto blurManager = reinterpret_cast<QPointer<BlurManagerInterface>*>(wl_resource_get_user_data(r))->data();
if (blurManager) {
return static_cast<Private*>(blurManager->d.data());
}
return nullptr;
}
BlurManagerInterface *q;
static const struct org_kde_kwin_blur_manager_interface s_interface;
static const quint32 s_version;
};
const quint32 BlurManagerInterface::Private::s_version = 1;
#ifndef K_DOXYGEN
const struct org_kde_kwin_blur_manager_interface BlurManagerInterface::Private::s_interface = {
createCallback,
unsetCallback
protected:
void org_kde_kwin_blur_manager_create(Resource *resource, uint32_t id, wl_resource *surface);
void org_kde_kwin_blur_manager_unset(Resource *resource, wl_resource *surface);
};
#endif
BlurManagerInterface::Private::Private(BlurManagerInterface *q, Display *d)
: Global::Private(d, &org_kde_kwin_blur_manager_interface, s_version)
, q(q)
{
}
void BlurManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&org_kde_kwin_blur_manager_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
auto ref = new QPointer<BlurManagerInterface>(q);//deleted in unbind
wl_resource_set_implementation(resource, &s_interface, ref, unbind);
}
const quint32 BlurManagerInterfacePrivate::s_version = 1;
void BlurManagerInterface::Private::unbind(wl_resource *r)
BlurManagerInterfacePrivate::BlurManagerInterfacePrivate(BlurManagerInterface *_q, Display *d)
: QtWaylandServer::org_kde_kwin_blur_manager(*d, s_version)
, q(_q)
{
delete reinterpret_cast<QPointer<BlurManagerInterface>*>(wl_resource_get_user_data(r));
}
void BlurManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
{
auto m = cast(resource);
if (!m) {
return;// will happen if global is deleted
}
m->createBlur(client, resource, id, surface);
}
void BlurManagerInterface::Private::createBlur(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_unset(Resource *resource, wl_resource *surface)
{
Q_UNUSED(resource);
SurfaceInterface *s = SurfaceInterface::get(surface);
if (!s) {
return;
}
BlurInterface *blur = new BlurInterface(q, resource);
blur->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!blur->resource()) {
wl_resource_post_no_memory(resource);
delete blur;
return;
}
s->d_func()->setBlur(QPointer<BlurInterface>(blur));
s->d_func()->setBlur(QPointer<BlurInterface>());
}
void BlurManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface)
void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
{
Q_UNUSED(client)
Q_UNUSED(resource)
SurfaceInterface *s = SurfaceInterface::get(surface);
if (!s) {
wl_resource_post_error(resource->handle, 0, "Invalid surface");
return;
}
s->d_func()->setBlur(QPointer<BlurInterface>());
wl_resource *blur_resource = wl_resource_create(resource->client(), &org_kde_kwin_blur_interface, resource->version(), id);
if (!blur_resource) {
wl_client_post_no_memory(resource->client());
return;
}
auto blur = new BlurInterface(blur_resource);
s->d_func()->setBlur(blur);
}
BlurManagerInterface::BlurManagerInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
: QObject(parent)
, d(new BlurManagerInterfacePrivate(this, display))
{
}
BlurManagerInterface::~BlurManagerInterface() = default;
class BlurInterface::Private : public Resource::Private
class BlurInterfacePrivate : public QtWaylandServer::org_kde_kwin_blur
{
public:
Private(BlurInterface *q, BlurManagerInterface *c, wl_resource *parentResource);
~Private();
BlurInterfacePrivate(BlurInterface *q, wl_resource *resource);
QRegion pendingRegion;
QRegion currentRegion;
private:
void commit();
//TODO
BlurInterface *q_func() {
return reinterpret_cast<BlurInterface *>(q);
}
static void commitCallback(wl_client *client, wl_resource *resource);
static void setRegionCallback(wl_client *client, wl_resource *resource, wl_resource *region);
BlurInterface *q;
static const struct org_kde_kwin_blur_interface s_interface;
protected:
void org_kde_kwin_blur_destroy_resource(Resource *resource);
void org_kde_kwin_blur_commit(Resource *resource);
void org_kde_kwin_blur_set_region(Resource *resource, wl_resource *region);
void org_kde_kwin_blur_release(Resource *resource);
};
#ifndef K_DOXYGEN
const struct org_kde_kwin_blur_interface BlurInterface::Private::s_interface = {
commitCallback,
setRegionCallback,
resourceDestroyedCallback
};
#endif
void BlurInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast<Private>(resource)->commit();
}
void BlurInterface::Private::commit()
void BlurInterfacePrivate::org_kde_kwin_blur_commit(Resource *resource)
{
Q_UNUSED(resource)
currentRegion = pendingRegion;
}
void BlurInterface::Private::setRegionCallback(wl_client *client, wl_resource *resource, wl_resource *region)
void BlurInterfacePrivate::org_kde_kwin_blur_set_region(Resource *resource, wl_resource *region)
{
Q_UNUSED(client)
Private *p = cast<Private>(resource);
Q_UNUSED(resource)
RegionInterface *r = RegionInterface::get(region);
if (r) {
p->pendingRegion = r->region();
pendingRegion = r->region();
} else {
p->pendingRegion = QRegion();
pendingRegion = QRegion();
}
}
BlurInterface::Private::Private(BlurInterface *q, BlurManagerInterface *c, wl_resource *parentResource)
: Resource::Private(q, c, parentResource, &org_kde_kwin_blur_interface, &s_interface)
void BlurInterfacePrivate::org_kde_kwin_blur_release(QtWaylandServer::org_kde_kwin_blur::Resource *resource)
{
wl_resource_destroy(resource->handle);
}
BlurInterface::Private::~Private() = default;
void BlurInterfacePrivate::org_kde_kwin_blur_destroy_resource(QtWaylandServer::org_kde_kwin_blur::Resource *resource)
{
Q_UNUSED(resource)
delete q;
}
BlurInterface::BlurInterface(BlurManagerInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
BlurInterfacePrivate::BlurInterfacePrivate(BlurInterface *_q, wl_resource *resource)
: QtWaylandServer::org_kde_kwin_blur(resource)
, q(_q)
{
}
BlurInterface::BlurInterface(wl_resource *resource)
: QObject()
, d(new BlurInterfacePrivate(this, resource))
{
}
......@@ -186,13 +135,7 @@ BlurInterface::~BlurInterface() = default;
QRegion BlurInterface::region()
{
Q_D();
return d->currentRegion;
}
BlurInterface::Private *BlurInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
}
/*
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef KWAYLAND_SERVER_BLUR_INTERFACE_H
#define KWAYLAND_SERVER_BLUR_INTERFACE_H
#include "global.h"
#include "resource.h"
#pragma once
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
struct wl_resource;
namespace KWaylandServer
{
class Display;
class BlurManagerInterfacePrivate;
class BlurInterfacePrivate;
/**
* @brief Represents the Global for org_kde_kwin_blur_manager interface.
......@@ -26,18 +27,17 @@ class Display;
*
* @see BlurInterface
* @see SurfaceInterface
* @since 5.5
**/
class KWAYLANDSERVER_EXPORT BlurManagerInterface : public Global
class KWAYLANDSERVER_EXPORT BlurManagerInterface : public QObject
{
Q_OBJECT
public:
virtual ~BlurManagerInterface();
~BlurManagerInterface() override;
private:
explicit BlurManagerInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
QScopedPointer<BlurManagerInterfacePrivate> d;
};
/**
......@@ -49,15 +49,16 @@ private:
* the BlurInterface is only available on the SurfaceInterface after it has been
* committed.
*
* Lifespan matches the underlying client resource
*
* @see BlurManagerInterface
* @see SurfaceInterface
* @since 5.5
**/
class KWAYLANDSERVER_EXPORT BlurInterface : public Resource
class KWAYLANDSERVER_EXPORT BlurInterface : public QObject
{
Q_OBJECT
public:
virtual ~BlurInterface();
~BlurInterface() override;
/**
* @returns The region or the SurfaceInterface which should be blurred, null Region implies complete surface.
......@@ -65,13 +66,10 @@ public:
QRegion region();
private:
explicit BlurInterface(BlurManagerInterface *parent, wl_resource *parentResource);
friend class BlurManagerInterface;
explicit BlurInterface(wl_resource *resource);
friend class BlurManagerInterfacePrivate;
class Private;
Private *d_func() const;
QScopedPointer<BlurInterfacePrivate> d;
};
}
#endif
......@@ -375,7 +375,7 @@ private:
friend class CompositorInterface;
friend class SubSurfaceInterface;
friend class ShadowManagerInterface;
friend class BlurManagerInterface;
friend class BlurManagerInterfacePrivate;
friend class SlideManagerInterface;
friend class ContrastManagerInterface;
friend class IdleInhibitManagerUnstableV1Interface;
......
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