Add a parentResource to Resource

This commit is contained in:
Martin Gräßlin 2014-11-20 16:40:14 +01:00
parent 9e3aa9a7e3
commit 68ce470231
27 changed files with 69 additions and 55 deletions

View file

@ -189,6 +189,7 @@ void TestDataDevice::testCreate()
QVERIFY(!deviceInterface->origin());
QVERIFY(!deviceInterface->icon());
QVERIFY(!deviceInterface->selection());
QVERIFY(deviceInterface->parentResource());
}
void TestDataDevice::testDrag()

View file

@ -143,6 +143,7 @@ void TestDataSource::testOffer()
QPointer<DataSourceInterface> serverDataSource = dataSourceCreatedSpy.first().first().value<DataSourceInterface*>();
QVERIFY(!serverDataSource.isNull());
QCOMPARE(serverDataSource->mimeTypes().count(), 0);
QVERIFY(serverDataSource->parentResource());
QSignalSpy offeredSpy(serverDataSource.data(), SIGNAL(mimeTypeOffered(const QString&)));
QVERIFY(offeredSpy.isValid());

View file

@ -167,6 +167,7 @@ void TestRegion::testCreateWithRegion()
auto serverRegion = regionCreatedSpy.first().first().value<KWayland::Server::RegionInterface*>();
QVERIFY(serverRegion);
QCOMPARE(serverRegion->region(), QRegion(0, 0, 10, 20));
QVERIFY(serverRegion->parentResource());
}
void TestRegion::testCreateUniquePtr()

View file

@ -223,6 +223,7 @@ void TestWaylandShell::testFullscreen()
QVERIFY(serverSurfaceSpy.wait());
ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value<ShellSurfaceInterface*>();
QVERIFY(serverSurface);
QVERIFY(serverSurface->parentResource());
QSignalSpy fullscreenSpy(serverSurface, SIGNAL(fullscreenChanged(bool)));
QVERIFY(fullscreenSpy.isValid());

View file

@ -188,6 +188,7 @@ void TestSubSurface::testCreate()
QVERIFY(subSurfaceCreatedSpy.wait());
SubSurfaceInterface *serverSubSurface = subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>();
QVERIFY(serverSubSurface);
QVERIFY(serverSubSurface->parentSurface());
QCOMPARE(serverSubSurface->parentSurface().data(), serverParentSurface);
QCOMPARE(serverSubSurface->surface().data(), serverSurface);
QCOMPARE(serverSurface->subSurface().data(), serverSubSurface);

View file

@ -193,6 +193,7 @@ void TestWaylandSurface::testDamage()
KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
QVERIFY(serverSurface);
QCOMPARE(serverSurface->damage(), QRegion());
QVERIFY(serverSurface->parentResource());
QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion)));
QVERIFY(damageSpy.isValid());

View file

@ -95,7 +95,7 @@ void CompositorInterface::Private::createSurfaceCallback(wl_client *client, wl_r
void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id)
{
SurfaceInterface *surface = new SurfaceInterface(q);
SurfaceInterface *surface = new SurfaceInterface(q, resource);
surface->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!surface->resource()) {
wl_resource_post_no_memory(resource);
@ -112,7 +112,7 @@ 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);
RegionInterface *region = new RegionInterface(q, resource);
region->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!region->resource()) {
wl_resource_post_no_memory(resource);

View file

@ -36,7 +36,7 @@ namespace Server
class DataDeviceInterface::Private : public Resource::Private
{
public:
Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager);
Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager, wl_resource *parentResource);
~Private();
DataOfferInterface *createDataOffer(DataSourceInterface *source);
@ -65,8 +65,8 @@ const struct wl_data_device_interface DataDeviceInterface::Private::s_interface
setSelectionCallback
};
DataDeviceInterface::Private::Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager)
: Resource::Private(q, manager, &wl_data_device_interface, &s_interface)
DataDeviceInterface::Private::Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager, wl_resource *parentResource)
: Resource::Private(q, manager, parentResource, &wl_data_device_interface, &s_interface)
, seat(seat)
{
}
@ -116,7 +116,7 @@ void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source)
{
Q_Q(DataDeviceInterface);
DataOfferInterface *offer = new DataOfferInterface(source, q);
DataOfferInterface *offer = new DataOfferInterface(source, q, resource);
auto c = q->global()->display()->getConnection(wl_resource_get_client(resource));
offer->create(c, wl_resource_get_version(resource), 0);
if (!offer->resource()) {
@ -129,8 +129,8 @@ DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInte
return offer;
}
DataDeviceInterface::DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent)
: Resource(new Private(seat, this, parent))
DataDeviceInterface::DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent, wl_resource *parentResource)
: Resource(new Private(seat, this, parent, parentResource))
{
}

View file

@ -58,7 +58,7 @@ Q_SIGNALS:
private:
friend class DataDeviceManagerInterface;
explicit DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent);
explicit DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;

View file

@ -87,7 +87,7 @@ void DataDeviceManagerInterface::Private::createDataSourceCallback(wl_client *cl
void DataDeviceManagerInterface::Private::createDataSource(wl_client *client, wl_resource *resource, uint32_t id)
{
DataSourceInterface *dataSource = new DataSourceInterface(q);
DataSourceInterface *dataSource = new DataSourceInterface(q, resource);
dataSource->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!dataSource->resource()) {
wl_resource_post_no_memory(resource);
@ -104,7 +104,7 @@ void DataDeviceManagerInterface::Private::getDataDeviceCallback(wl_client *clien
void DataDeviceManagerInterface::Private::getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat)
{
DataDeviceInterface *dataDevice = new DataDeviceInterface(SeatInterface::get(seat), q);
DataDeviceInterface *dataDevice = new DataDeviceInterface(SeatInterface::get(seat), q, resource);
dataDevice->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!dataDevice->resource()) {
wl_resource_post_no_memory(resource);

View file

@ -34,7 +34,7 @@ namespace Server
class DataOfferInterface::Private : public Resource::Private
{
public:
Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q);
Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource);
~Private();
DataSourceInterface *source;
DataDeviceInterface *dataDevice;
@ -57,8 +57,8 @@ const struct wl_data_offer_interface DataOfferInterface::Private::s_interface =
destroyCallback
};
DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q)
: Resource::Private(q, nullptr, &wl_data_offer_interface, &s_interface)
DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource)
: Resource::Private(q, nullptr, parentResource, &wl_data_offer_interface, &s_interface)
, source(source)
, dataDevice(parentInterface)
{
@ -92,8 +92,8 @@ void DataOfferInterface::Private::receive(const QString &mimeType, qint32 fd)
source->requestData(mimeType, fd);
}
DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface)
: Resource(new Private(source, parentInterface, this), parentInterface)
DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource)
: Resource(new Private(source, parentInterface, this, parentResource), parentInterface)
{
connect(source, &DataSourceInterface::mimeTypeOffered, this,
[this](const QString &mimeType) {

View file

@ -44,7 +44,7 @@ public:
private:
friend class DataDeviceInterface;
explicit DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface);
explicit DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource);
class Private;
Private *d_func() const;

View file

@ -33,7 +33,7 @@ namespace Server
class DataSourceInterface::Private : public Resource::Private
{
public:
Private(DataSourceInterface *q, DataDeviceManagerInterface *parent);
Private(DataSourceInterface *q, DataDeviceManagerInterface *parent, wl_resource *parentResource);
~Private();
QStringList mimeTypes;
@ -55,8 +55,8 @@ const struct wl_data_source_interface DataSourceInterface::Private::s_interface
destroyCallack
};
DataSourceInterface::Private::Private(DataSourceInterface *q, DataDeviceManagerInterface *parent)
: Resource::Private(q, parent, &wl_data_source_interface, &s_interface)
DataSourceInterface::Private::Private(DataSourceInterface *q, DataDeviceManagerInterface *parent, wl_resource *parentResource)
: Resource::Private(q, parent, parentResource, &wl_data_source_interface, &s_interface)
{
}
@ -81,8 +81,8 @@ void DataSourceInterface::Private::offer(const QString &mimeType)
emit q->mimeTypeOffered(mimeType);
}
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent)
: Resource(new Private(this, parent))
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
{
}

View file

@ -51,7 +51,7 @@ Q_SIGNALS:
private:
friend class DataDeviceManagerInterface;
explicit DataSourceInterface(DataDeviceManagerInterface *parent);
explicit DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;

View file

@ -31,7 +31,7 @@ namespace Server
class RegionInterface::Private : public Resource::Private
{
public:
Private(CompositorInterface *compositor, RegionInterface *q);
Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource);
~Private();
QRegion qtRegion;
@ -55,8 +55,8 @@ const struct wl_region_interface RegionInterface::Private::s_interface = {
subtractCallback
};
RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q)
: Resource::Private(q, compositor, &wl_region_interface, &s_interface)
RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource)
: Resource::Private(q, compositor, parentResource, &wl_region_interface, &s_interface)
{
}
@ -97,8 +97,8 @@ void RegionInterface::Private::destroyCallback(wl_client *client, wl_resource *r
cast<Private>(r)->q_func()->deleteLater();
}
RegionInterface::RegionInterface(CompositorInterface *parent)
: Resource(new Private(parent, this), parent)
RegionInterface::RegionInterface(CompositorInterface *parent, wl_resource *parentResource)
: Resource(new Private(parent, this, parentResource), parent)
{
}

View file

@ -48,7 +48,7 @@ Q_SIGNALS:
private:
friend class CompositorInterface;
explicit RegionInterface(CompositorInterface *parent);
explicit RegionInterface(CompositorInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;

View file

@ -30,8 +30,9 @@ namespace Server
QList<Resource::Private*> Resource::Private::s_allResources;
Resource::Private::Private(Resource *q, Global *g, const wl_interface *interface, const void *implementation)
: global(g)
Resource::Private::Private(Resource *q, Global *g, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
: parentResource(parentResource)
, global(g)
, q(q)
, m_interface(interface)
, m_interfaceImplementation(implementation)
@ -94,5 +95,10 @@ wl_resource *Resource::resource()
return d->resource;
}
wl_resource *Resource::parentResource() const
{
return d->parentResource;
}
}
}

View file

@ -45,6 +45,7 @@ public:
wl_resource *resource();
ClientConnection *client();
Global *global();
wl_resource *parentResource() const;
protected:
class Private;

View file

@ -35,6 +35,7 @@ public:
virtual ~Private();
void create(ClientConnection *client, quint32 version, quint32 id);
wl_resource *parentResource = nullptr;
wl_resource *resource = nullptr;
ClientConnection *client = nullptr;
Global *global;
@ -55,7 +56,7 @@ public:
}
protected:
explicit Private(Resource *q, Global *g, const wl_interface *interface, const void *implementation);
explicit Private(Resource *q, Global *g, wl_resource *parentResource, const wl_interface *interface, const void *implementation);
template <typename Derived>
static Derived *cast(wl_resource *r) {

View file

@ -44,7 +44,7 @@ public:
private:
static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface);
void createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource);
ShellInterface *q;
static const struct wl_shell_interface s_interface;
@ -65,7 +65,7 @@ const struct wl_shell_interface ShellInterface::Private::s_interface = {
class ShellSurfaceInterface::Private : public Resource::Private
{
public:
Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface);
Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource);
void setFullscreen(bool fullscreen);
void setToplevel(bool toplevel);
void ping();
@ -126,10 +126,10 @@ void ShellInterface::Private::bind(wl_client *client, uint32_t version, uint32_t
void ShellInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
{
auto s = reinterpret_cast<ShellInterface::Private*>(wl_resource_get_user_data(resource));
s->createSurface(client, wl_resource_get_version(resource), id, SurfaceInterface::get(surface));
s->createSurface(client, wl_resource_get_version(resource), id, SurfaceInterface::get(surface), resource);
}
void ShellInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface)
void ShellInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource)
{
auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(),
[surface](ShellSurfaceInterface *s) {
@ -140,7 +140,7 @@ void ShellInterface::Private::createSurface(wl_client *client, uint32_t version,
wl_resource_post_error(surface->resource(), WL_DISPLAY_ERROR_INVALID_OBJECT, "ShellSurface already created");
return;
}
ShellSurfaceInterface *shellSurface = new ShellSurfaceInterface(q, surface);
ShellSurfaceInterface *shellSurface = new ShellSurfaceInterface(q, surface, parentResource);
surfaces << shellSurface;
QObject::connect(shellSurface, &ShellSurfaceInterface::destroyed, q,
[this, shellSurface] {
@ -154,8 +154,8 @@ void ShellInterface::Private::createSurface(wl_client *client, uint32_t version,
/*********************************
* ShellSurfaceInterface
*********************************/
ShellSurfaceInterface::Private::Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface)
: Resource::Private(q, shell, &wl_shell_surface_interface, &s_interface)
ShellSurfaceInterface::Private::Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource)
: Resource::Private(q, shell, parentResource, &wl_shell_surface_interface, &s_interface)
, surface(surface)
, pingTimer(new QTimer)
{
@ -176,8 +176,8 @@ const struct wl_shell_surface_interface ShellSurfaceInterface::Private::s_interf
setClassCallback
};
ShellSurfaceInterface::ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent)
: Resource(new Private(this, shell, parent), parent)
ShellSurfaceInterface::ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, shell, parent, parentResource), parent)
{
Q_D();
connect(d->pingTimer.data(), &QTimer::timeout, this, &ShellSurfaceInterface::pingTimeout);

View file

@ -87,7 +87,7 @@ Q_SIGNALS:
private:
friend class ShellInterface;
explicit ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent);
explicit ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;
};

View file

@ -106,7 +106,7 @@ void SubCompositorInterface::Private::subsurface(wl_client *client, wl_resource
}
// TODO: add check that surface is not already used in an interface (e.g. Shell)
// TODO: add check that parentSurface is not a child of surface
SubSurfaceInterface *s = new SubSurfaceInterface(q);
SubSurfaceInterface *s = new SubSurfaceInterface(q, resource);
s->d_func()->create(display->getConnection(client), wl_resource_get_version(resource), id, surface, parentSurface);
if (!s->resource()) {
wl_resource_post_no_memory(resource);
@ -132,8 +132,8 @@ const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface =
setDeSyncCallback
};
SubSurfaceInterface::Private::Private(SubSurfaceInterface *q, SubCompositorInterface *compositor)
: Resource::Private(q, compositor, &wl_subsurface_interface, &s_interface)
SubSurfaceInterface::Private::Private(SubSurfaceInterface *q, SubCompositorInterface *compositor, wl_resource *parentResource)
: Resource::Private(q, compositor, parentResource, &wl_subsurface_interface, &s_interface)
{
}
@ -250,8 +250,8 @@ void SubSurfaceInterface::Private::setMode(Mode m)
emit q->modeChanged(m);
}
SubSurfaceInterface::SubSurfaceInterface(SubCompositorInterface *parent)
: Resource(new Private(this, parent))
SubSurfaceInterface::SubSurfaceInterface(SubCompositorInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
{
Q_UNUSED(parent)
}

View file

@ -80,7 +80,7 @@ Q_SIGNALS:
private:
friend class SubCompositorInterface;
friend class SurfaceInterface;
explicit SubSurfaceInterface(SubCompositorInterface *parent);
explicit SubSurfaceInterface(SubCompositorInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;

View file

@ -35,7 +35,7 @@ namespace Server
class SubSurfaceInterface::Private : public Resource::Private
{
public:
Private(SubSurfaceInterface *q, SubCompositorInterface *compositor);
Private(SubSurfaceInterface *q, SubCompositorInterface *compositor, wl_resource *parentResource);
~Private();
using Resource::Private::create;

View file

@ -35,8 +35,8 @@ namespace KWayland
namespace Server
{
SurfaceInterface::Private::Private(SurfaceInterface *q, CompositorInterface *c)
: Resource::Private(q, c, &wl_surface_interface, &s_interface)
SurfaceInterface::Private::Private(SurfaceInterface *q, CompositorInterface *c, wl_resource *parentResource)
: Resource::Private(q, c, parentResource, &wl_surface_interface, &s_interface)
{
}
@ -136,8 +136,8 @@ const struct wl_surface_interface SurfaceInterface::Private::s_interface = {
bufferScaleCallback
};
SurfaceInterface::SurfaceInterface(CompositorInterface *parent)
: Resource(new Private(this, parent))
SurfaceInterface::SurfaceInterface(CompositorInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
{
}

View file

@ -80,7 +80,7 @@ Q_SIGNALS:
private:
friend class CompositorInterface;
friend class SubSurfaceInterface;
explicit SurfaceInterface(CompositorInterface *parent);
explicit SurfaceInterface(CompositorInterface *parent, wl_resource *parentResource);
class Private;
Private *d_func() const;

View file

@ -48,7 +48,7 @@ public:
// stacking order: bottom (first) -> top (last)
QList<QPointer<SubSurfaceInterface>> children;
};
Private(SurfaceInterface *q, CompositorInterface *c);
Private(SurfaceInterface *q, CompositorInterface *c, wl_resource *parentResource);
~Private();
void destroy();