Track all created Resources in Resource::Private
Also provide static method to map a wl_resource to the Resource sub class.
This commit is contained in:
parent
cee32f902a
commit
57de2df55e
6 changed files with 23 additions and 36 deletions
|
@ -37,11 +37,6 @@ public:
|
|||
~Private();
|
||||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
|
||||
static DataSourceInterface *get(wl_resource *r) {
|
||||
auto s = cast<Private>(r);
|
||||
return s ? s->q_func() : nullptr;
|
||||
}
|
||||
|
||||
QStringList mimeTypes;
|
||||
|
||||
private:
|
||||
|
@ -132,7 +127,7 @@ QStringList DataSourceInterface::mimeTypes() const
|
|||
|
||||
DataSourceInterface *DataSourceInterface::get(wl_resource *native)
|
||||
{
|
||||
return Private::get(native);
|
||||
return Private::get<DataSourceInterface>(native);
|
||||
}
|
||||
|
||||
DataSourceInterface::Private *DataSourceInterface::d_func() const
|
||||
|
|
|
@ -36,8 +36,6 @@ public:
|
|||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
QRegion qtRegion;
|
||||
|
||||
static RegionInterface *get(wl_resource *native);
|
||||
|
||||
private:
|
||||
RegionInterface *q_func() {
|
||||
return reinterpret_cast<RegionInterface*>(q);
|
||||
|
@ -110,14 +108,6 @@ void RegionInterface::Private::create(wl_client *client, quint32 version, quint3
|
|||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
RegionInterface *RegionInterface::Private::get(wl_resource *native)
|
||||
{
|
||||
if (!native) {
|
||||
return nullptr;
|
||||
}
|
||||
return cast<Private>(native)->q_func();
|
||||
}
|
||||
|
||||
RegionInterface::RegionInterface(CompositorInterface *parent)
|
||||
: Resource(new Private(parent, this), parent)
|
||||
{
|
||||
|
@ -133,7 +123,7 @@ QRegion RegionInterface::region() const
|
|||
|
||||
RegionInterface *RegionInterface::get(wl_resource *native)
|
||||
{
|
||||
return Private::get(native);
|
||||
return Private::get<RegionInterface>(native);
|
||||
}
|
||||
|
||||
RegionInterface::Private *RegionInterface::d_func() const
|
||||
|
|
|
@ -27,14 +27,18 @@ namespace KWayland
|
|||
namespace Server
|
||||
{
|
||||
|
||||
QList<Resource::Private*> Resource::Private::s_allResources;
|
||||
|
||||
Resource::Private::Private(Resource *q, Global *g)
|
||||
: global(g)
|
||||
, q(q)
|
||||
{
|
||||
s_allResources << this;
|
||||
}
|
||||
|
||||
Resource::Private::~Private()
|
||||
{
|
||||
s_allResources.removeAll(this);
|
||||
if (resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,21 @@ public:
|
|||
wl_client *client = nullptr;
|
||||
Global *global;
|
||||
|
||||
template <typename ResourceDerived>
|
||||
static ResourceDerived *get(wl_resource *native) {
|
||||
static_assert(std::is_base_of<Resource, ResourceDerived>::value,
|
||||
"ResourceDerived must be derived from Resource");
|
||||
auto it = std::find_if(s_allResources.constBegin(), s_allResources.constEnd(),
|
||||
[native](Private *p) {
|
||||
return p->resource == native;
|
||||
}
|
||||
);
|
||||
if (it == s_allResources.constEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<ResourceDerived*>((*it)->q);
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit Private(Resource *q, Global *g);
|
||||
|
||||
|
@ -51,6 +66,7 @@ protected:
|
|||
static void unbind(wl_resource *resource);
|
||||
|
||||
Resource *q;
|
||||
static QList<Private*> s_allResources;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,18 +34,14 @@ namespace KWayland
|
|||
namespace Server
|
||||
{
|
||||
|
||||
QList<SurfaceInterface::Private*> SurfaceInterface::Private::s_allSurfaces;
|
||||
|
||||
SurfaceInterface::Private::Private(SurfaceInterface *q, CompositorInterface *c)
|
||||
: Resource::Private(q, c)
|
||||
{
|
||||
s_allSurfaces << this;
|
||||
}
|
||||
|
||||
SurfaceInterface::Private::~Private()
|
||||
{
|
||||
destroy();
|
||||
s_allSurfaces.removeAll(this);
|
||||
}
|
||||
|
||||
void SurfaceInterface::Private::addChild(QPointer< SubSurfaceInterface > subSurface)
|
||||
|
@ -127,17 +123,6 @@ bool SurfaceInterface::Private::lowerChild(QPointer<SubSurfaceInterface> subsurf
|
|||
return true;
|
||||
}
|
||||
|
||||
SurfaceInterface *SurfaceInterface::Private::get(wl_resource *native)
|
||||
{
|
||||
auto it = std::find_if(s_allSurfaces.constBegin(), s_allSurfaces.constEnd(), [native](Private *s) {
|
||||
return s->resource == native;
|
||||
});
|
||||
if (it == s_allSurfaces.constEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
return (*it)->q_func();
|
||||
}
|
||||
|
||||
const struct wl_surface_interface SurfaceInterface::Private::s_interface = {
|
||||
destroyCallback,
|
||||
attachCallback,
|
||||
|
@ -421,7 +406,7 @@ QPoint SurfaceInterface::offset() const
|
|||
|
||||
SurfaceInterface *SurfaceInterface::get(wl_resource *native)
|
||||
{
|
||||
return Private::get(native);
|
||||
return Private::get<SurfaceInterface>(native);
|
||||
}
|
||||
|
||||
QList< QPointer< SubSurfaceInterface > > SurfaceInterface::childSubSurfaces() const
|
||||
|
|
|
@ -59,8 +59,6 @@ public:
|
|||
bool raiseChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface *sibling);
|
||||
bool lowerChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface *sibling);
|
||||
|
||||
static SurfaceInterface *get(wl_resource *native);
|
||||
|
||||
State current;
|
||||
State pending;
|
||||
QPointer<SubSurfaceInterface> subSurface;
|
||||
|
@ -93,7 +91,6 @@ private:
|
|||
static void bufferScaleCallback(wl_client *client, wl_resource *resource, int32_t scale);
|
||||
|
||||
static const struct wl_surface_interface s_interface;
|
||||
static QList<SurfaceInterface::Private*> s_allSurfaces;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue