Commit ec1bdbe4 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Port the wl_region wrapper to the new approach

parent 50e6797e
......@@ -136,7 +136,6 @@ void TestRegion::testCreate()
auto serverRegion = regionCreatedSpy.first().first().value<KWaylandServer::RegionInterface*>();
QVERIFY(serverRegion);
QCOMPARE(serverRegion->region(), QRegion());
QCOMPARE(serverRegion->global(), m_compositorInterface);
}
void TestRegion::testCreateWithRegion()
......@@ -154,7 +153,6 @@ void TestRegion::testCreateWithRegion()
auto serverRegion = regionCreatedSpy.first().first().value<KWaylandServer::RegionInterface*>();
QVERIFY(serverRegion);
QCOMPARE(serverRegion->region(), QRegion(0, 0, 10, 20));
QVERIFY(serverRegion->parentResource());
}
void TestRegion::testCreateUniquePtr()
......@@ -282,16 +280,12 @@ void TestRegion::testDisconnect()
auto serverRegion = regionCreatedSpy.first().first().value<RegionInterface*>();
// destroy client
QSignalSpy clientDisconnectedSpy(serverRegion->client(), &ClientConnection::disconnected);
QVERIFY(clientDisconnectedSpy.isValid());
QSignalSpy regionDestroyedSpy(serverRegion, &QObject::destroyed);
QVERIFY(regionDestroyedSpy.isValid());
if (m_connection) {
m_connection->deleteLater();
m_connection = nullptr;
}
QVERIFY(clientDisconnectedSpy.wait());
QCOMPARE(clientDisconnectedSpy.count(), 1);
QCOMPARE(regionDestroyedSpy.count(), 0);
QVERIFY(regionDestroyedSpy.wait());
QCOMPARE(regionDestroyedSpy.count(), 1);
......
......@@ -79,6 +79,11 @@ ecm_qt_declare_logging_category(SERVER_LIB_SRCS
EXPORT KWAYLAND
)
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${Wayland_DATADIR}/wayland.xml
BASENAME wayland
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/output-management.xml
BASENAME output-management
......
......@@ -99,14 +99,13 @@ void CompositorInterface::Private::createRegionCallback(wl_client *client, wl_re
void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *resource, uint32_t id)
{
RegionInterface *region = new RegionInterface(q, resource);
region->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!region->resource()) {
wl_resource *regionResource = wl_resource_create(client, &wl_region_interface,
wl_resource_get_version(resource), id);
if (!regionResource) {
wl_resource_post_no_memory(resource);
delete region;
return;
}
emit q->regionCreated(region);
emit q->regionCreated(new RegionInterface(q, regionResource));
}
}
/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "region_interface.h"
#include "resource_p.h"
#include "compositor_interface.h"
// Wayland
#include <wayland-server.h>
#include "qwayland-server-wayland.h"
namespace KWaylandServer
{
class RegionInterface::Private : public Resource::Private
class RegionInterfacePrivate : public QtWaylandServer::wl_region
{
public:
Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource);
~Private();
QRegion qtRegion;
private:
RegionInterface *q_func() {
return reinterpret_cast<RegionInterface*>(q);
}
void add(const QRect &rect);
void subtract(const QRect &rect);
static void addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height);
static void subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height);
RegionInterfacePrivate(RegionInterface *q, wl_resource *resource);
static const struct wl_region_interface s_interface;
};
RegionInterface *q;
QRegion qtRegion;
#ifndef K_DOXYGEN
const struct wl_region_interface RegionInterface::Private::s_interface = {
resourceDestroyedCallback,
addCallback,
subtractCallback
protected:
void region_destroy_resource(Resource *resource) override;
void region_destroy(Resource *resource) override;
void region_add(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
void region_subtract(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
};
#endif
RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource)
: Resource::Private(q, compositor, parentResource, &wl_region_interface, &s_interface)
RegionInterfacePrivate::RegionInterfacePrivate(RegionInterface *q, wl_resource *resource)
: QtWaylandServer::wl_region(resource)
, q(q)
{
}
RegionInterface::Private::~Private() = default;
void RegionInterfacePrivate::region_destroy_resource(Resource *)
{
delete q;
}
void RegionInterface::Private::add(const QRect &rect)
void RegionInterfacePrivate::region_destroy(Resource *resource)
{
qtRegion = qtRegion.united(rect);
Q_Q(RegionInterface);
emit q->regionChanged(qtRegion);
wl_resource_destroy(resource->handle);
}
void RegionInterface::Private::subtract(const QRect &rect)
void RegionInterfacePrivate::region_add(Resource *, int32_t x, int32_t y, int32_t width, int32_t height)
{
if (qtRegion.isEmpty()) {
return;
}
qtRegion = qtRegion.subtracted(rect);
Q_Q(RegionInterface);
qtRegion += QRegion(x, y, width, height);
emit q->regionChanged(qtRegion);
}
void RegionInterface::Private::addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
void RegionInterfacePrivate::region_subtract(Resource *, int32_t x, int32_t y, int32_t width, int32_t height)
{
Q_UNUSED(client)
cast<Private>(r)->add(QRect(x, y, width, height));
qtRegion -= QRegion(x, y, width, height);
emit q->regionChanged(qtRegion);
}
void RegionInterface::Private::subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
RegionInterface::RegionInterface(CompositorInterface *compositor, wl_resource *resource)
: QObject(compositor)
, d(new RegionInterfacePrivate(this, resource))
{
Q_UNUSED(client)
cast<Private>(r)->subtract(QRect(x, y, width, height));
}
RegionInterface::RegionInterface(CompositorInterface *parent, wl_resource *parentResource)
: Resource(new Private(parent, this, parentResource))
RegionInterface::~RegionInterface()
{
}
RegionInterface::~RegionInterface() = default;
QRegion RegionInterface::region() const
{
Q_D();
return d->qtRegion;
}
RegionInterface *RegionInterface::get(wl_resource *native)
{
return Private::get<RegionInterface>(native);
}
RegionInterface::Private *RegionInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
if (auto region = RegionInterfacePrivate::Resource::fromResource(native)) {
return static_cast<RegionInterfacePrivate *>(region->object())->q;
}
return nullptr;
}
}
} // namespace KWaylandServer
/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
......@@ -11,11 +12,13 @@
#include <KWaylandServer/kwaylandserver_export.h>
#include "resource.h"
struct wl_resource;
namespace KWaylandServer
{
class CompositorInterface;
class RegionInterfacePrivate;
/**
* @brief Resource for the wl_region.
......@@ -25,7 +28,7 @@ class CompositorInterface;
*
* @see CompositorInterface
**/
class KWAYLANDSERVER_EXPORT RegionInterface : public Resource
class KWAYLANDSERVER_EXPORT RegionInterface : public QObject
{
Q_OBJECT
public:
......@@ -49,10 +52,8 @@ Q_SIGNALS:
private:
friend class CompositorInterface;
explicit RegionInterface(CompositorInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;
explicit RegionInterface(CompositorInterface *compositor, wl_resource *resource);
QScopedPointer<RegionInterfacePrivate> 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