Commit de622163 authored by Martin Flöser's avatar Martin Flöser
Browse files

Add cast from wl_resource to Private to Resource::Private

Replaces the custom implementation in each of the derived classes.
parent 53a4455c
......@@ -55,9 +55,6 @@ private:
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);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
DataDeviceInterface *q;
......@@ -83,7 +80,7 @@ void DataDeviceInterface::Private::startDragCallback(wl_client *client, wl_resou
Q_UNUSED(client)
Q_UNUSED(serial)
// TODO: verify serial
cast(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon));
cast<Private>(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon));
}
void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *i)
......@@ -103,7 +100,7 @@ void DataDeviceInterface::Private::setSelectionCallback(wl_client *client, wl_re
Q_UNUSED(client)
Q_UNUSED(serial)
// TODO: verify serial
cast(resource)->setSelection(DataSourceInterface::get(source));
cast<Private>(resource)->setSelection(DataSourceInterface::get(source));
}
void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
......@@ -118,7 +115,7 @@ void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
void DataDeviceInterface::Private::unbind(wl_resource *resource)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
s->resource = nullptr;
s->q->deleteLater();
}
......
......@@ -46,9 +46,6 @@ private:
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);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
DataOfferInterface *q;
......@@ -93,13 +90,13 @@ void DataOfferInterface::Private::acceptCallback(wl_client *client, wl_resource
void DataOfferInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->q->deleteLater();
cast<Private>(resource)->q->deleteLater();
}
void DataOfferInterface::Private::receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd)
{
Q_UNUSED(client)
cast(resource)->receive(QString::fromUtf8(mimeType), fd);
cast<Private>(resource)->receive(QString::fromUtf8(mimeType), fd);
}
void DataOfferInterface::Private::receive(const QString &mimeType, qint32 fd)
......@@ -109,7 +106,7 @@ void DataOfferInterface::Private::receive(const QString &mimeType, qint32 fd)
void DataOfferInterface::Private::unbind(wl_resource *resource)
{
auto o = cast(resource);
auto o = cast<Private>(resource);
o->resource = nullptr;
o->q->deleteLater();
}
......
......@@ -38,7 +38,7 @@ public:
void create(wl_client *client, quint32 version, quint32 id) override;
static DataSourceInterface *get(wl_resource *r) {
auto s = cast(r);
auto s = cast<Private>(r);
return s ? s->q : nullptr;
}
......@@ -50,9 +50,6 @@ private:
static void offerCallback(wl_client *client, wl_resource *resource, const char *mimeType);
static void destroyCallack(wl_client *client, wl_resource *resource);
static void unbind(wl_resource *resource);
static Private *cast(wl_resource *r) {
return r ? reinterpret_cast<Private*>(wl_resource_get_user_data(r)) : nullptr;
}
const static struct wl_data_source_interface s_interface;
DataSourceInterface *q;
......@@ -73,7 +70,7 @@ DataSourceInterface::Private::~Private() = default;
void DataSourceInterface::Private::unbind(wl_resource *resource)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
s->resource = nullptr;
s->q->deleteLater();
}
......@@ -81,13 +78,13 @@ void DataSourceInterface::Private::unbind(wl_resource *resource)
void DataSourceInterface::Private::destroyCallack(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->q->deleteLater();
cast<Private>(resource)->q->deleteLater();
}
void DataSourceInterface::Private::offerCallback(wl_client *client, wl_resource *resource, const char *mimeType)
{
Q_UNUSED(client)
cast(resource)->offer(QString::fromUtf8(mimeType));
cast<Private>(resource)->offer(QString::fromUtf8(mimeType));
}
void DataSourceInterface::Private::offer(const QString &mimeType)
......
......@@ -47,10 +47,6 @@ private:
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);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
static const struct wl_region_interface s_interface;
RegionInterface *q;
};
......@@ -87,24 +83,24 @@ void RegionInterface::Private::subtract(const QRect &rect)
void RegionInterface::Private::addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
{
Q_UNUSED(client)
cast(r)->add(QRect(x, y, width, height));
cast<Private>(r)->add(QRect(x, y, width, height));
}
void RegionInterface::Private::subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
{
Q_UNUSED(client)
cast(r)->subtract(QRect(x, y, width, height));
cast<Private>(r)->subtract(QRect(x, y, width, height));
}
void RegionInterface::Private::destroyCallback(wl_client *client, wl_resource *r)
{
Q_UNUSED(client)
cast(r)->q->deleteLater();
cast<Private>(r)->q->deleteLater();
}
void RegionInterface::Private::unbind(wl_resource *r)
{
auto region = cast(r);
auto region = cast<Private>(r);
region->resource = nullptr;
region->q->deleteLater();
}
......@@ -124,7 +120,7 @@ RegionInterface *RegionInterface::Private::get(wl_resource *native)
if (!native) {
return nullptr;
}
return cast(native)->q;
return cast<Private>(native)->q;
}
RegionInterface::RegionInterface(CompositorInterface *parent)
......
......@@ -21,6 +21,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#define WAYLAND_SERVER_RESOURCE_P_H
#include "resource.h"
#include <wayland-server.h>
#include <type_traits>
namespace KWayland
{
......@@ -40,6 +42,13 @@ public:
protected:
explicit Private(Global *g);
template <typename Derived>
static Derived *cast(wl_resource *r) {
static_assert(std::is_base_of<Private, Derived>::value,
"Derived must be derived from Resource::Private");
return r ? reinterpret_cast<Derived*>(wl_resource_get_user_data(r)) : nullptr;
}
};
}
......
......@@ -83,10 +83,6 @@ public:
bool toplevel = false;
private:
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
static void unbind(wl_resource *r);
// interface callbacks
static void pongCallback(wl_client *client, wl_resource *resource, uint32_t serial);
......@@ -227,14 +223,14 @@ void ShellSurfaceInterface::Private::create(wl_client *c, quint32 version, quint
void ShellSurfaceInterface::Private::unbind(wl_resource *r)
{
auto s = cast(r);
auto s = cast<Private>(r);
s->resource = nullptr;
s->q->deleteLater();
}
void ShellSurfaceInterface::Private::pongCallback(wl_client *client, wl_resource *resource, uint32_t serial)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
s->pong(serial);
}
......@@ -288,7 +284,7 @@ void ShellSurfaceInterface::Private::moveCallback(wl_client *client, wl_resource
{
Q_UNUSED(seat)
Q_UNUSED(serial)
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
// TODO: implement
}
......@@ -298,14 +294,14 @@ void ShellSurfaceInterface::Private::resizeCallback(wl_client *client, wl_resour
Q_UNUSED(seat)
Q_UNUSED(serial)
Q_UNUSED(edges)
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
// TODO: implement
}
void ShellSurfaceInterface::Private::setToplevelCallback(wl_client *client, wl_resource *resource)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
s->setToplevel(true);
}
......@@ -326,7 +322,7 @@ void ShellSurfaceInterface::Private::setTransientCallback(wl_client *client, wl_
Q_UNUSED(x)
Q_UNUSED(y)
Q_UNUSED(flags)
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
// TODO: implement
}
......@@ -337,7 +333,7 @@ void ShellSurfaceInterface::Private::setFullscreenCallback(wl_client *client, wl
Q_UNUSED(method)
Q_UNUSED(framerate)
Q_UNUSED(output)
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
// TODO: add method, framerate and output
s->setFullscreen(true);
......@@ -361,7 +357,7 @@ void ShellSurfaceInterface::Private::setPopupCalback(wl_client *client, wl_resou
Q_UNUSED(x)
Q_UNUSED(y)
Q_UNUSED(flags)
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
// TODO: implement
}
......@@ -369,14 +365,14 @@ void ShellSurfaceInterface::Private::setPopupCalback(wl_client *client, wl_resou
void ShellSurfaceInterface::Private::setMaximizedCallback(wl_client *client, wl_resource *resource, wl_resource *output)
{
Q_UNUSED(output)
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
// TODO: implement
}
void ShellSurfaceInterface::Private::setTitleCallback(wl_client *client, wl_resource *resource, const char *title)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
s->setTitle(QString::fromUtf8(title));
}
......@@ -392,7 +388,7 @@ void ShellSurfaceInterface::Private::setTitle(const QString &t)
void ShellSurfaceInterface::Private::setClassCallback(wl_client *client, wl_resource *resource, const char *class_)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
s->setWindowClass(QByteArray(class_));
}
......
......@@ -131,11 +131,6 @@ const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface =
setDeSyncCallback
};
SubSurfaceInterface::Private *SubSurfaceInterface::Private::cast(wl_resource *r)
{
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
SubSurfaceInterface::Private::Private(SubSurfaceInterface *q, SubCompositorInterface *compositor)
: Resource::Private(compositor)
, q(q)
......@@ -184,7 +179,7 @@ void SubSurfaceInterface::Private::commit()
void SubSurfaceInterface::Private::unbind(wl_resource *r)
{
auto s = cast(r);
auto s = cast<Private>(r);
s->resource = nullptr;
s->q->deleteLater();
}
......@@ -192,14 +187,14 @@ void SubSurfaceInterface::Private::unbind(wl_resource *r)
void SubSurfaceInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->q->deleteLater();
cast<Private>(resource)->q->deleteLater();
}
void SubSurfaceInterface::Private::setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y)
{
Q_UNUSED(client)
// TODO: is this a fixed position?
cast(resource)->setPosition(QPoint(x, y));
cast<Private>(resource)->setPosition(QPoint(x, y));
}
void SubSurfaceInterface::Private::setPosition(const QPoint &p)
......@@ -214,7 +209,7 @@ void SubSurfaceInterface::Private::setPosition(const QPoint &p)
void SubSurfaceInterface::Private::placeAboveCallback(wl_client *client, wl_resource *resource, wl_resource *sibling)
{
Q_UNUSED(client)
cast(resource)->placeAbove(SurfaceInterface::get(sibling));
cast<Private>(resource)->placeAbove(SurfaceInterface::get(sibling));
}
void SubSurfaceInterface::Private::placeAbove(SurfaceInterface *sibling)
......@@ -231,7 +226,7 @@ void SubSurfaceInterface::Private::placeAbove(SurfaceInterface *sibling)
void SubSurfaceInterface::Private::placeBelowCallback(wl_client *client, wl_resource *resource, wl_resource *sibling)
{
Q_UNUSED(client)
cast(resource)->placeBelow(SurfaceInterface::get(sibling));
cast<Private>(resource)->placeBelow(SurfaceInterface::get(sibling));
}
void SubSurfaceInterface::Private::placeBelow(SurfaceInterface *sibling)
......@@ -248,13 +243,13 @@ void SubSurfaceInterface::Private::placeBelow(SurfaceInterface *sibling)
void SubSurfaceInterface::Private::setSyncCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->setMode(Mode::Synchronized);
cast<Private>(resource)->setMode(Mode::Synchronized);
}
void SubSurfaceInterface::Private::setDeSyncCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->setMode(Mode::Desynchronized);
cast<Private>(resource)->setMode(Mode::Desynchronized);
}
void SubSurfaceInterface::Private::setMode(Mode m)
......
......@@ -63,8 +63,6 @@ private:
static void setSyncCallback(wl_client *client, wl_resource *resource);
static void setDeSyncCallback(wl_client *client, wl_resource *resource);
static Private *cast(wl_resource *r);
SubSurfaceInterface *q;
static const struct wl_subsurface_interface s_interface;
......
......@@ -49,11 +49,6 @@ SurfaceInterface::Private::~Private()
s_allSurfaces.removeAll(this);
}
SurfaceInterface::Private *SurfaceInterface::Private::cast(wl_resource *r)
{
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
void SurfaceInterface::Private::addChild(QPointer< SubSurfaceInterface > subSurface)
{
pending.children.append(subSurface);
......@@ -186,7 +181,7 @@ void SurfaceInterface::frameRendered(quint32 msec)
void SurfaceInterface::Private::unbind(wl_resource *r)
{
auto s = cast(r);
auto s = cast<Private>(r);
s->resource = nullptr;
s->q->deleteLater();
}
......@@ -303,7 +298,7 @@ void SurfaceInterface::Private::attachBuffer(wl_resource *buffer, const QPoint &
void SurfaceInterface::Private::destroyFrameCallback(wl_resource *r)
{
auto s = cast(r);
auto s = cast<Private>(r);
s->current.callbacks.removeAll(r);
s->pending.callbacks.removeAll(r);
}
......@@ -311,31 +306,31 @@ void SurfaceInterface::Private::destroyFrameCallback(wl_resource *r)
void SurfaceInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->q->deleteLater();
cast<Private>(resource)->q->deleteLater();
}
void SurfaceInterface::Private::attachCallback(wl_client *client, wl_resource *resource, wl_resource *buffer, int32_t sx, int32_t sy)
{
Q_UNUSED(client)
cast(resource)->attachBuffer(buffer, QPoint(sx, sy));
cast<Private>(resource)->attachBuffer(buffer, QPoint(sx, sy));
}
void SurfaceInterface::Private::damageCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
{
Q_UNUSED(client)
cast(resource)->damage(QRect(x, y, width, height));
cast<Private>(resource)->damage(QRect(x, y, width, height));
}
void SurfaceInterface::Private::frameCallaback(wl_client *client, wl_resource *resource, uint32_t callback)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
s->addFrameCallback(callback);
}
void SurfaceInterface::Private::opaqueRegionCallback(wl_client *client, wl_resource *resource, wl_resource *region)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
auto r = RegionInterface::get(region);
s->setOpaque(r ? r->region() : QRegion());
......@@ -349,7 +344,7 @@ void SurfaceInterface::Private::setOpaque(const QRegion &region)
void SurfaceInterface::Private::inputRegionCallback(wl_client *client, wl_resource *resource, wl_resource *region)
{
auto s = cast(resource);
auto s = cast<Private>(resource);
Q_ASSERT(client == s->client);
auto r = RegionInterface::get(region);
s->setInput(r ? r->region() : QRegion(), !r);
......@@ -365,19 +360,19 @@ void SurfaceInterface::Private::setInput(const QRegion &region, bool isInfinite)
void SurfaceInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
cast(resource)->commit();
cast<Private>(resource)->commit();
}
void SurfaceInterface::Private::bufferTransformCallback(wl_client *client, wl_resource *resource, int32_t transform)
{
Q_UNUSED(client)
cast(resource)->setTransform(OutputInterface::Transform(transform));
cast<Private>(resource)->setTransform(OutputInterface::Transform(transform));
}
void SurfaceInterface::Private::bufferScaleCallback(wl_client *client, wl_resource *resource, int32_t scale)
{
Q_UNUSED(client)
cast(resource)->setScale(scale);
cast<Private>(resource)->setScale(scale);
}
QRegion SurfaceInterface::damage() const
......
......@@ -75,8 +75,6 @@ private:
void setOpaque(const QRegion &region);
void setInput(const QRegion &region, bool isInfinite);
static Private *cast(wl_resource *r);
static void unbind(wl_resource *r);
static void destroyFrameCallback(wl_resource *r);
......
Supports Markdown
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