Move q-ptr to Resource::Private
In the derived classes a q_func() is added which casts the q-ptr back to the Resource derived class.
This commit is contained in:
parent
de62216357
commit
0fb42d102e
11 changed files with 67 additions and 40 deletions
|
@ -50,14 +50,15 @@ public:
|
|||
DataSourceInterface *selection = nullptr;
|
||||
|
||||
private:
|
||||
DataDeviceInterface *q_func() {
|
||||
return reinterpret_cast<DataDeviceInterface*>(q);
|
||||
}
|
||||
void startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *icon);
|
||||
void setSelection(DataSourceInterface *dataSource);
|
||||
static void startDragCallback(wl_client *client, wl_resource *resource, wl_resource *source, wl_resource *origin, wl_resource *icon, uint32_t serial);
|
||||
static void setSelectionCallback(wl_client *client, wl_resource *resource, wl_resource *source, uint32_t serial);
|
||||
static void unbind(wl_resource *resource);
|
||||
|
||||
DataDeviceInterface *q;
|
||||
|
||||
static const struct wl_data_device_interface s_interface;
|
||||
};
|
||||
|
||||
|
@ -67,9 +68,8 @@ const struct wl_data_device_interface DataDeviceInterface::Private::s_interface
|
|||
};
|
||||
|
||||
DataDeviceInterface::Private::Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager)
|
||||
: Resource::Private(manager)
|
||||
: Resource::Private(q, manager)
|
||||
, seat(seat)
|
||||
, q(q)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,7 @@ void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, Su
|
|||
source = dataSource;
|
||||
surface = origin;
|
||||
icon = i;
|
||||
Q_Q(DataDeviceInterface);
|
||||
emit q->dragStarted();
|
||||
}
|
||||
|
||||
|
@ -105,6 +106,7 @@ void DataDeviceInterface::Private::setSelectionCallback(wl_client *client, wl_re
|
|||
|
||||
void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
|
||||
{
|
||||
Q_Q(DataDeviceInterface);
|
||||
selection = dataSource;
|
||||
if (selection) {
|
||||
emit q->selectionChanged(selection);
|
||||
|
@ -117,7 +119,7 @@ void DataDeviceInterface::Private::unbind(wl_resource *resource)
|
|||
{
|
||||
auto s = cast<Private>(resource);
|
||||
s->resource = nullptr;
|
||||
s->q->deleteLater();
|
||||
s->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void DataDeviceInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
|
@ -132,6 +134,7 @@ void DataDeviceInterface::Private::create(wl_client *client, quint32 version, qu
|
|||
|
||||
DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source)
|
||||
{
|
||||
Q_Q(DataDeviceInterface);
|
||||
DataOfferInterface *offer = new DataOfferInterface(source, q);
|
||||
offer->create(wl_resource_get_client(resource), wl_resource_get_version(resource), 0);
|
||||
if (!offer->resource()) {
|
||||
|
|
|
@ -41,14 +41,15 @@ public:
|
|||
DataDeviceInterface *dataDevice;
|
||||
|
||||
private:
|
||||
DataOfferInterface *q_func() {
|
||||
return reinterpret_cast<DataOfferInterface *>(q);
|
||||
}
|
||||
void receive(const QString &mimeType, qint32 fd);
|
||||
static void acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *mimeType);
|
||||
static void receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd);
|
||||
static void destroyCallback(wl_client *client, wl_resource *resource);
|
||||
static void unbind(wl_resource *resource);
|
||||
|
||||
DataOfferInterface *q;
|
||||
|
||||
static const struct wl_data_offer_interface s_interface;
|
||||
};
|
||||
|
||||
|
@ -59,10 +60,9 @@ const struct wl_data_offer_interface DataOfferInterface::Private::s_interface =
|
|||
};
|
||||
|
||||
DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q)
|
||||
: Resource::Private(nullptr)
|
||||
: Resource::Private(q, nullptr)
|
||||
, source(source)
|
||||
, dataDevice(parentInterface)
|
||||
, q(q)
|
||||
{
|
||||
// TODO: connect to new selections
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void DataOfferInterface::Private::acceptCallback(wl_client *client, wl_resource
|
|||
void DataOfferInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
cast<Private>(resource)->q->deleteLater();
|
||||
cast<Private>(resource)->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void DataOfferInterface::Private::receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd)
|
||||
|
@ -108,7 +108,7 @@ void DataOfferInterface::Private::unbind(wl_resource *resource)
|
|||
{
|
||||
auto o = cast<Private>(resource);
|
||||
o->resource = nullptr;
|
||||
o->q->deleteLater();
|
||||
o->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface)
|
||||
|
|
|
@ -39,12 +39,15 @@ public:
|
|||
|
||||
static DataSourceInterface *get(wl_resource *r) {
|
||||
auto s = cast<Private>(r);
|
||||
return s ? s->q : nullptr;
|
||||
return s ? s->q_func() : nullptr;
|
||||
}
|
||||
|
||||
QStringList mimeTypes;
|
||||
|
||||
private:
|
||||
DataSourceInterface *q_func() {
|
||||
return reinterpret_cast<DataSourceInterface *>(q);
|
||||
}
|
||||
void offer(const QString &mimeType);
|
||||
|
||||
static void offerCallback(wl_client *client, wl_resource *resource, const char *mimeType);
|
||||
|
@ -52,7 +55,6 @@ private:
|
|||
static void unbind(wl_resource *resource);
|
||||
|
||||
const static struct wl_data_source_interface s_interface;
|
||||
DataSourceInterface *q;
|
||||
};
|
||||
|
||||
const struct wl_data_source_interface DataSourceInterface::Private::s_interface = {
|
||||
|
@ -61,8 +63,7 @@ const struct wl_data_source_interface DataSourceInterface::Private::s_interface
|
|||
};
|
||||
|
||||
DataSourceInterface::Private::Private(DataSourceInterface *q, DataDeviceManagerInterface *parent)
|
||||
: Resource::Private(parent)
|
||||
, q(q)
|
||||
: Resource::Private(q, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -72,13 +73,13 @@ void DataSourceInterface::Private::unbind(wl_resource *resource)
|
|||
{
|
||||
auto s = cast<Private>(resource);
|
||||
s->resource = nullptr;
|
||||
s->q->deleteLater();
|
||||
s->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void DataSourceInterface::Private::destroyCallack(wl_client *client, wl_resource *resource)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
cast<Private>(resource)->q->deleteLater();
|
||||
cast<Private>(resource)->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void DataSourceInterface::Private::offerCallback(wl_client *client, wl_resource *resource, const char *mimeType)
|
||||
|
@ -90,6 +91,7 @@ void DataSourceInterface::Private::offerCallback(wl_client *client, wl_resource
|
|||
void DataSourceInterface::Private::offer(const QString &mimeType)
|
||||
{
|
||||
mimeTypes << mimeType;
|
||||
Q_Q(DataSourceInterface);
|
||||
emit q->mimeTypeOffered(mimeType);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,9 @@ public:
|
|||
static RegionInterface *get(wl_resource *native);
|
||||
|
||||
private:
|
||||
RegionInterface *q_func() {
|
||||
return reinterpret_cast<RegionInterface*>(q);
|
||||
}
|
||||
void add(const QRect &rect);
|
||||
void subtract(const QRect &rect);
|
||||
|
||||
|
@ -48,7 +51,6 @@ private:
|
|||
static void subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height);
|
||||
|
||||
static const struct wl_region_interface s_interface;
|
||||
RegionInterface *q;
|
||||
};
|
||||
|
||||
const struct wl_region_interface RegionInterface::Private::s_interface = {
|
||||
|
@ -58,8 +60,7 @@ const struct wl_region_interface RegionInterface::Private::s_interface = {
|
|||
};
|
||||
|
||||
RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q)
|
||||
: Resource::Private(compositor)
|
||||
, q(q)
|
||||
: Resource::Private(q, compositor)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -68,6 +69,7 @@ RegionInterface::Private::~Private() = default;
|
|||
void RegionInterface::Private::add(const QRect &rect)
|
||||
{
|
||||
qtRegion = qtRegion.united(rect);
|
||||
Q_Q(RegionInterface);
|
||||
emit q->regionChanged(qtRegion);
|
||||
}
|
||||
|
||||
|
@ -77,6 +79,7 @@ void RegionInterface::Private::subtract(const QRect &rect)
|
|||
return;
|
||||
}
|
||||
qtRegion = qtRegion.subtracted(rect);
|
||||
Q_Q(RegionInterface);
|
||||
emit q->regionChanged(qtRegion);
|
||||
}
|
||||
|
||||
|
@ -95,14 +98,14 @@ void RegionInterface::Private::subtractCallback(wl_client *client, wl_resource *
|
|||
void RegionInterface::Private::destroyCallback(wl_client *client, wl_resource *r)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
cast<Private>(r)->q->deleteLater();
|
||||
cast<Private>(r)->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void RegionInterface::Private::unbind(wl_resource *r)
|
||||
{
|
||||
auto region = cast<Private>(r);
|
||||
region->resource = nullptr;
|
||||
region->q->deleteLater();
|
||||
region->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void RegionInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
||||
|
@ -120,7 +123,7 @@ RegionInterface *RegionInterface::Private::get(wl_resource *native)
|
|||
if (!native) {
|
||||
return nullptr;
|
||||
}
|
||||
return cast<Private>(native)->q;
|
||||
return cast<Private>(native)->q_func();
|
||||
}
|
||||
|
||||
RegionInterface::RegionInterface(CompositorInterface *parent)
|
||||
|
|
|
@ -27,8 +27,9 @@ namespace KWayland
|
|||
namespace Server
|
||||
{
|
||||
|
||||
Resource::Private::Private(Global *g)
|
||||
Resource::Private::Private(Resource *q, Global *g)
|
||||
: global(g)
|
||||
, q(q)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
Global *global;
|
||||
|
||||
protected:
|
||||
explicit Private(Global *g);
|
||||
explicit Private(Resource *q, Global *g);
|
||||
|
||||
template <typename Derived>
|
||||
static Derived *cast(wl_resource *r) {
|
||||
|
@ -49,6 +49,7 @@ protected:
|
|||
return r ? reinterpret_cast<Derived*>(wl_resource_get_user_data(r)) : nullptr;
|
||||
}
|
||||
|
||||
Resource *q;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -103,8 +103,10 @@ private:
|
|||
void setTitle(const QString &title);
|
||||
void setWindowClass(const QByteArray &windowClass);
|
||||
void pong(quint32 serial);
|
||||
ShellSurfaceInterface *q_func() {
|
||||
return reinterpret_cast<ShellSurfaceInterface *>(q);
|
||||
}
|
||||
|
||||
ShellSurfaceInterface *q;
|
||||
static const struct wl_shell_surface_interface s_interface;
|
||||
};
|
||||
|
||||
|
@ -157,10 +159,9 @@ void ShellInterface::Private::createSurface(wl_client *client, uint32_t version,
|
|||
* ShellSurfaceInterface
|
||||
*********************************/
|
||||
ShellSurfaceInterface::Private::Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface)
|
||||
: Resource::Private(shell)
|
||||
: Resource::Private(q, shell)
|
||||
, surface(surface)
|
||||
, pingTimer(new QTimer)
|
||||
, q(q)
|
||||
{
|
||||
pingTimer->setSingleShot(true);
|
||||
pingTimer->setInterval(1000);
|
||||
|
@ -225,7 +226,7 @@ void ShellSurfaceInterface::Private::unbind(wl_resource *r)
|
|||
{
|
||||
auto s = cast<Private>(r);
|
||||
s->resource = nullptr;
|
||||
s->q->deleteLater();
|
||||
s->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void ShellSurfaceInterface::Private::pongCallback(wl_client *client, wl_resource *resource, uint32_t serial)
|
||||
|
@ -239,6 +240,7 @@ void ShellSurfaceInterface::Private::pong(quint32 serial)
|
|||
{
|
||||
if (pingTimer->isActive() && serial == pingSerial) {
|
||||
pingTimer->stop();
|
||||
Q_Q(ShellSurfaceInterface);
|
||||
emit q->pongReceived();
|
||||
}
|
||||
}
|
||||
|
@ -312,6 +314,7 @@ void ShellSurfaceInterface::Private::setToplevel(bool t)
|
|||
return;
|
||||
}
|
||||
toplevel = t;
|
||||
Q_Q(ShellSurfaceInterface);
|
||||
emit q->toplevelChanged(toplevel);
|
||||
}
|
||||
|
||||
|
@ -345,6 +348,7 @@ void ShellSurfaceInterface::Private::setFullscreen(bool f)
|
|||
return;
|
||||
}
|
||||
fullscreen = f;
|
||||
Q_Q(ShellSurfaceInterface);
|
||||
emit q->fullscreenChanged(fullscreen);
|
||||
}
|
||||
|
||||
|
@ -383,6 +387,7 @@ void ShellSurfaceInterface::Private::setTitle(const QString &t)
|
|||
return;
|
||||
}
|
||||
title = t;
|
||||
Q_Q(ShellSurfaceInterface);
|
||||
emit q->titleChanged(title);
|
||||
}
|
||||
|
||||
|
@ -399,6 +404,7 @@ void ShellSurfaceInterface::Private::setWindowClass(const QByteArray &wc)
|
|||
return;
|
||||
}
|
||||
windowClass = wc;
|
||||
Q_Q(ShellSurfaceInterface);
|
||||
emit q->windowClassChanged(windowClass);
|
||||
}
|
||||
|
||||
|
|
|
@ -132,8 +132,7 @@ const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface =
|
|||
};
|
||||
|
||||
SubSurfaceInterface::Private::Private(SubSurfaceInterface *q, SubCompositorInterface *compositor)
|
||||
: Resource::Private(compositor)
|
||||
, q(q)
|
||||
: Resource::Private(q, compositor)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -141,6 +140,7 @@ SubSurfaceInterface::Private::~Private()
|
|||
{
|
||||
// no need to notify the surface as it's tracking a QPointer which will be reset automatically
|
||||
if (parent) {
|
||||
Q_Q(SubSurfaceInterface);
|
||||
reinterpret_cast<SurfaceInterface::Private*>(parent->d.data())->removeChild(QPointer<SubSurfaceInterface>(q));
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +163,7 @@ void SubSurfaceInterface::Private::create(wl_client *client, quint32 version, qu
|
|||
}
|
||||
surface = s;
|
||||
parent = p;
|
||||
Q_Q(SubSurfaceInterface);
|
||||
surface->d_func()->subSurface = QPointer<SubSurfaceInterface>(q);
|
||||
parent->d_func()->addChild(QPointer<SubSurfaceInterface>(q));
|
||||
}
|
||||
|
@ -173,6 +174,7 @@ void SubSurfaceInterface::Private::commit()
|
|||
scheduledPosChange = false;
|
||||
pos = scheduledPos;
|
||||
scheduledPos = QPoint();
|
||||
Q_Q(SubSurfaceInterface);
|
||||
emit q->positionChanged(pos);
|
||||
}
|
||||
}
|
||||
|
@ -181,13 +183,13 @@ void SubSurfaceInterface::Private::unbind(wl_resource *r)
|
|||
{
|
||||
auto s = cast<Private>(r);
|
||||
s->resource = nullptr;
|
||||
s->q->deleteLater();
|
||||
s->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void SubSurfaceInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
cast<Private>(resource)->q->deleteLater();
|
||||
cast<Private>(resource)->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void SubSurfaceInterface::Private::setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y)
|
||||
|
@ -218,6 +220,7 @@ void SubSurfaceInterface::Private::placeAbove(SurfaceInterface *sibling)
|
|||
// TODO: raise error
|
||||
return;
|
||||
}
|
||||
Q_Q(SubSurfaceInterface);
|
||||
if (!parent->d_func()->raiseChild(QPointer<SubSurfaceInterface>(q), sibling)) {
|
||||
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Incorrect sibling");
|
||||
}
|
||||
|
@ -235,6 +238,7 @@ void SubSurfaceInterface::Private::placeBelow(SurfaceInterface *sibling)
|
|||
// TODO: raise error
|
||||
return;
|
||||
}
|
||||
Q_Q(SubSurfaceInterface);
|
||||
if (!parent->d_func()->lowerChild(QPointer<SubSurfaceInterface>(q), sibling)) {
|
||||
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Incorrect sibling");
|
||||
}
|
||||
|
@ -258,6 +262,7 @@ void SubSurfaceInterface::Private::setMode(Mode m)
|
|||
return;
|
||||
}
|
||||
mode = m;
|
||||
Q_Q(SubSurfaceInterface);
|
||||
emit q->modeChanged(m);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
QPointer<SurfaceInterface> parent;
|
||||
|
||||
private:
|
||||
SubSurfaceInterface *q_func() {
|
||||
return reinterpret_cast<SubSurfaceInterface *>(q);
|
||||
}
|
||||
void setMode(Mode mode);
|
||||
void setPosition(const QPoint &pos);
|
||||
void placeAbove(SurfaceInterface *sibling);
|
||||
|
@ -63,8 +66,6 @@ private:
|
|||
static void setSyncCallback(wl_client *client, wl_resource *resource);
|
||||
static void setDeSyncCallback(wl_client *client, wl_resource *resource);
|
||||
|
||||
SubSurfaceInterface *q;
|
||||
|
||||
static const struct wl_subsurface_interface s_interface;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@ namespace Server
|
|||
QList<SurfaceInterface::Private*> SurfaceInterface::Private::s_allSurfaces;
|
||||
|
||||
SurfaceInterface::Private::Private(SurfaceInterface *q, CompositorInterface *c)
|
||||
: Resource::Private(c)
|
||||
, q(q)
|
||||
: Resource::Private(q, c)
|
||||
{
|
||||
s_allSurfaces << this;
|
||||
}
|
||||
|
@ -61,6 +60,7 @@ void SurfaceInterface::Private::removeChild(QPointer< SubSurfaceInterface > subS
|
|||
|
||||
bool SurfaceInterface::Private::raiseChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface *sibling)
|
||||
{
|
||||
Q_Q(SurfaceInterface);
|
||||
auto it = std::find(pending.children.begin(), pending.children.end(), subsurface);
|
||||
if (it == pending.children.end()) {
|
||||
return false;
|
||||
|
@ -94,6 +94,7 @@ bool SurfaceInterface::Private::raiseChild(QPointer<SubSurfaceInterface> subsurf
|
|||
|
||||
bool SurfaceInterface::Private::lowerChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface *sibling)
|
||||
{
|
||||
Q_Q(SurfaceInterface);
|
||||
auto it = std::find(pending.children.begin(), pending.children.end(), subsurface);
|
||||
if (it == pending.children.end()) {
|
||||
return false;
|
||||
|
@ -134,7 +135,7 @@ SurfaceInterface *SurfaceInterface::Private::get(wl_resource *native)
|
|||
if (it == s_allSurfaces.constEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
return (*it)->q;
|
||||
return (*it)->q_func();
|
||||
}
|
||||
|
||||
const struct wl_surface_interface SurfaceInterface::Private::s_interface = {
|
||||
|
@ -183,7 +184,7 @@ void SurfaceInterface::Private::unbind(wl_resource *r)
|
|||
{
|
||||
auto s = cast<Private>(r);
|
||||
s->resource = nullptr;
|
||||
s->q->deleteLater();
|
||||
s->q_func()->deleteLater();
|
||||
}
|
||||
|
||||
void SurfaceInterface::Private::destroy()
|
||||
|
@ -205,6 +206,7 @@ void SurfaceInterface::Private::destroy()
|
|||
|
||||
void SurfaceInterface::Private::commit()
|
||||
{
|
||||
Q_Q(SurfaceInterface);
|
||||
for (wl_resource *c : current.callbacks) {
|
||||
wl_resource_destroy(c);
|
||||
}
|
||||
|
@ -282,6 +284,7 @@ void SurfaceInterface::Private::attachBuffer(wl_resource *buffer, const QPoint &
|
|||
if (pending.buffer) {
|
||||
delete pending.buffer;
|
||||
}
|
||||
Q_Q(SurfaceInterface);
|
||||
pending.buffer = new BufferInterface(buffer, q);
|
||||
QObject::connect(pending.buffer, &BufferInterface::aboutToBeDestroyed, q,
|
||||
[this](BufferInterface *buffer) {
|
||||
|
|
|
@ -66,6 +66,9 @@ public:
|
|||
QPointer<SubSurfaceInterface> subSurface;
|
||||
|
||||
private:
|
||||
SurfaceInterface *q_func() {
|
||||
return reinterpret_cast<SurfaceInterface *>(q);
|
||||
}
|
||||
void commit();
|
||||
void damage(const QRect &rect);
|
||||
void setScale(qint32 scale);
|
||||
|
@ -90,7 +93,6 @@ private:
|
|||
// since version 3
|
||||
static void bufferScaleCallback(wl_client *client, wl_resource *resource, int32_t scale);
|
||||
|
||||
SurfaceInterface *q;
|
||||
static const struct wl_surface_interface s_interface;
|
||||
static QList<SurfaceInterface::Private*> s_allSurfaces;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue