Create wl_resource in Resource::Private instead of subclasses
Required information is passed through the ctor of Private. ::create is still virtual as ShellSurfaceInterface is retrieving client information. This can be fixed once we have a better wl_client encapsulation class.
This commit is contained in:
parent
57de2df55e
commit
8685a0e972
11 changed files with 30 additions and 89 deletions
|
@ -38,8 +38,6 @@ public:
|
|||
Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager);
|
||||
~Private();
|
||||
|
||||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
|
||||
DataOfferInterface *createDataOffer(DataSourceInterface *source);
|
||||
|
||||
SeatInterface *seat;
|
||||
|
@ -67,7 +65,7 @@ const struct wl_data_device_interface DataDeviceInterface::Private::s_interface
|
|||
};
|
||||
|
||||
DataDeviceInterface::Private::Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager)
|
||||
: Resource::Private(q, manager)
|
||||
: Resource::Private(q, manager, &wl_data_device_interface, &s_interface)
|
||||
, seat(seat)
|
||||
{
|
||||
}
|
||||
|
@ -114,16 +112,6 @@ void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
|
|||
}
|
||||
}
|
||||
|
||||
void DataDeviceInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
resource = wl_resource_create(client, &wl_data_device_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source)
|
||||
{
|
||||
Q_Q(DataDeviceInterface);
|
||||
|
|
|
@ -36,7 +36,6 @@ class DataOfferInterface::Private : public Resource::Private
|
|||
public:
|
||||
Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q);
|
||||
~Private();
|
||||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
DataSourceInterface *source;
|
||||
DataDeviceInterface *dataDevice;
|
||||
|
||||
|
@ -59,7 +58,7 @@ const struct wl_data_offer_interface DataOfferInterface::Private::s_interface =
|
|||
};
|
||||
|
||||
DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q)
|
||||
: Resource::Private(q, nullptr)
|
||||
: Resource::Private(q, nullptr, &wl_data_offer_interface, &s_interface)
|
||||
, source(source)
|
||||
, dataDevice(parentInterface)
|
||||
{
|
||||
|
@ -68,16 +67,6 @@ DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInte
|
|||
|
||||
DataOfferInterface::Private::~Private() = default;
|
||||
|
||||
void DataOfferInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
resource = wl_resource_create(client, &wl_data_offer_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
void DataOfferInterface::Private::acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *mimeType)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
|
|
|
@ -35,7 +35,6 @@ class DataSourceInterface::Private : public Resource::Private
|
|||
public:
|
||||
Private(DataSourceInterface *q, DataDeviceManagerInterface *parent);
|
||||
~Private();
|
||||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
|
||||
QStringList mimeTypes;
|
||||
|
||||
|
@ -57,7 +56,7 @@ const struct wl_data_source_interface DataSourceInterface::Private::s_interface
|
|||
};
|
||||
|
||||
DataSourceInterface::Private::Private(DataSourceInterface *q, DataDeviceManagerInterface *parent)
|
||||
: Resource::Private(q, parent)
|
||||
: Resource::Private(q, parent, &wl_data_source_interface, &s_interface)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -82,16 +81,6 @@ void DataSourceInterface::Private::offer(const QString &mimeType)
|
|||
emit q->mimeTypeOffered(mimeType);
|
||||
}
|
||||
|
||||
void DataSourceInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
resource = wl_resource_create(client, &wl_data_source_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent)
|
||||
: Resource(new Private(this, parent))
|
||||
{
|
||||
|
|
|
@ -33,7 +33,6 @@ class RegionInterface::Private : public Resource::Private
|
|||
public:
|
||||
Private(CompositorInterface *compositor, RegionInterface *q);
|
||||
~Private();
|
||||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
QRegion qtRegion;
|
||||
|
||||
private:
|
||||
|
@ -57,7 +56,7 @@ const struct wl_region_interface RegionInterface::Private::s_interface = {
|
|||
};
|
||||
|
||||
RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q)
|
||||
: Resource::Private(q, compositor)
|
||||
: Resource::Private(q, compositor, &wl_region_interface, &s_interface)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -98,16 +97,6 @@ void RegionInterface::Private::destroyCallback(wl_client *client, wl_resource *r
|
|||
cast<Private>(r)->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void RegionInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
resource = wl_resource_create(client, &wl_region_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
RegionInterface::RegionInterface(CompositorInterface *parent)
|
||||
: Resource(new Private(parent, this), parent)
|
||||
{
|
||||
|
|
|
@ -29,9 +29,11 @@ namespace Server
|
|||
|
||||
QList<Resource::Private*> Resource::Private::s_allResources;
|
||||
|
||||
Resource::Private::Private(Resource *q, Global *g)
|
||||
Resource::Private::Private(Resource *q, Global *g, const wl_interface *interface, const void *implementation)
|
||||
: global(g)
|
||||
, q(q)
|
||||
, m_interface(interface)
|
||||
, m_interfaceImplementation(implementation)
|
||||
{
|
||||
s_allResources << this;
|
||||
}
|
||||
|
@ -44,6 +46,18 @@ Resource::Private::~Private()
|
|||
}
|
||||
}
|
||||
|
||||
void Resource::Private::create(wl_client *c, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
Q_ASSERT(!client);
|
||||
client = c;
|
||||
resource = wl_resource_create(client, m_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, m_interfaceImplementation, this, unbind);
|
||||
}
|
||||
|
||||
void Resource::Private::unbind(wl_resource *r)
|
||||
{
|
||||
Private *p = cast<Private>(r);
|
||||
|
|
|
@ -33,7 +33,7 @@ class Resource::Private
|
|||
{
|
||||
public:
|
||||
virtual ~Private();
|
||||
virtual void create(wl_client *client, quint32 version, quint32 id) = 0;
|
||||
virtual void create(wl_client *client, quint32 version, quint32 id);
|
||||
|
||||
wl_resource *resource = nullptr;
|
||||
wl_client *client = nullptr;
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
explicit Private(Resource *q, Global *g);
|
||||
explicit Private(Resource *q, Global *g, const wl_interface *interface, const void *implementation);
|
||||
|
||||
template <typename Derived>
|
||||
static Derived *cast(wl_resource *r) {
|
||||
|
@ -67,6 +67,10 @@ protected:
|
|||
|
||||
Resource *q;
|
||||
static QList<Private*> s_allResources;
|
||||
|
||||
private:
|
||||
const wl_interface *const m_interface;
|
||||
const void *const m_interfaceImplementation;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ void ShellInterface::Private::createSurface(wl_client *client, uint32_t version,
|
|||
* ShellSurfaceInterface
|
||||
*********************************/
|
||||
ShellSurfaceInterface::Private::Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface)
|
||||
: Resource::Private(q, shell)
|
||||
: Resource::Private(q, shell, &wl_shell_surface_interface, &s_interface)
|
||||
, surface(surface)
|
||||
, pingTimer(new QTimer)
|
||||
{
|
||||
|
@ -208,17 +208,8 @@ ShellSurfaceInterface::~ShellSurfaceInterface() = default;
|
|||
|
||||
void ShellSurfaceInterface::Private::create(wl_client *c, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!client);
|
||||
Q_ASSERT(!resource);
|
||||
resource = wl_resource_create(c, &wl_shell_surface_interface, version, id);
|
||||
if (!resource) {
|
||||
wl_client_post_no_memory(c);
|
||||
return;
|
||||
}
|
||||
client = c;
|
||||
Resource::Private::create(c, version, id);
|
||||
wl_client_get_credentials(client, &clientPid, &clientUser, &clientGroup);
|
||||
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
void ShellSurfaceInterface::Private::pongCallback(wl_client *client, wl_resource *resource, uint32_t serial)
|
||||
|
|
|
@ -132,7 +132,7 @@ const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface =
|
|||
};
|
||||
|
||||
SubSurfaceInterface::Private::Private(SubSurfaceInterface *q, SubCompositorInterface *compositor)
|
||||
: Resource::Private(q, compositor)
|
||||
: Resource::Private(q, compositor, &wl_subsurface_interface, &s_interface)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -145,16 +145,6 @@ SubSurfaceInterface::Private::~Private()
|
|||
}
|
||||
}
|
||||
|
||||
void SubSurfaceInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
resource = wl_resource_create(client, &wl_subsurface_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
void SubSurfaceInterface::Private::create(wl_client *client, quint32 version, quint32 id, SurfaceInterface *s, SurfaceInterface *p)
|
||||
{
|
||||
create(client, version, id);
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
Private(SubSurfaceInterface *q, SubCompositorInterface *compositor);
|
||||
~Private();
|
||||
|
||||
void create(wl_client *client, quint32 version, quint32 id) override;
|
||||
using Resource::Private::create;
|
||||
void create(wl_client *client, quint32 version, quint32 id, SurfaceInterface *surface, SurfaceInterface *parent);
|
||||
void commit();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Server
|
|||
{
|
||||
|
||||
SurfaceInterface::Private::Private(SurfaceInterface *q, CompositorInterface *c)
|
||||
: Resource::Private(q, c)
|
||||
: Resource::Private(q, c, &wl_surface_interface, &s_interface)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -142,18 +142,6 @@ SurfaceInterface::SurfaceInterface(CompositorInterface *parent)
|
|||
|
||||
SurfaceInterface::~SurfaceInterface() = default;
|
||||
|
||||
void SurfaceInterface::Private::create(wl_client *c, quint32 version, quint32 id)
|
||||
{
|
||||
Q_ASSERT(!resource);
|
||||
Q_ASSERT(!client);
|
||||
client = c;
|
||||
resource = wl_resource_create(client, &wl_surface_interface, version, id);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
void SurfaceInterface::frameRendered(quint32 msec)
|
||||
{
|
||||
Q_D();
|
||||
|
|
|
@ -51,7 +51,6 @@ public:
|
|||
Private(SurfaceInterface *q, CompositorInterface *c);
|
||||
~Private();
|
||||
|
||||
void create(wl_client *client, quint32 version, quint32 id);
|
||||
void destroy();
|
||||
|
||||
void addChild(QPointer<SubSurfaceInterface> subsurface);
|
||||
|
|
Loading…
Reference in a new issue