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

Global::Private can create the wl_global

Version and interface get passed to the ctor allowing Global::Private
to implement ::create instead of providing a pure virtual method.
Also the static bind method is added to the Global::Private which
delegates into a pure virtual method.
parent 22197da9
......@@ -35,14 +35,12 @@ class CompositorInterface::Private : public Global::Private
{
public:
Private(CompositorInterface *q, Display *d);
void create() override;
private:
void bind(wl_client *client, uint32_t version, uint32_t id);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void createSurface(wl_client *client, wl_resource *resource, uint32_t id);
void createRegion(wl_client *client, wl_resource *resource, uint32_t id);
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
static void unbind(wl_resource *resource);
static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id);
static void createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id);
......@@ -55,17 +53,11 @@ private:
};
CompositorInterface::Private::Private(CompositorInterface *q, Display *d)
: Global::Private(d)
: Global::Private(d, &wl_compositor_interface, s_version)
, q(q)
{
}
void CompositorInterface::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, &wl_compositor_interface, s_version, this, bind);
}
const struct wl_compositor_interface CompositorInterface::Private::s_interface = {
createSurfaceCallback,
createRegionCallback
......@@ -78,12 +70,6 @@ CompositorInterface::CompositorInterface(Display *display, QObject *parent)
CompositorInterface::~CompositorInterface() = default;
void CompositorInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
auto compositor = reinterpret_cast<CompositorInterface::Private*>(data);
compositor->bind(client, version, id);
}
void CompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
wl_resource *resource = wl_resource_create(client, &wl_compositor_interface, qMin(version, s_version), id);
......
......@@ -35,14 +35,12 @@ class DataDeviceManagerInterface::Private : public Global::Private
{
public:
Private(DataDeviceManagerInterface *q, Display *d);
void create() override;
private:
void bind(wl_client *client, uint32_t version, uint32_t id);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void createDataSource(wl_client *client, wl_resource *resource, uint32_t id);
void getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat);
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
static void unbind(wl_resource *resource);
static void createDataSourceCallback(wl_client *client, wl_resource *resource, uint32_t id);
static void getDataDeviceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat);
......@@ -60,17 +58,11 @@ const struct wl_data_device_manager_interface DataDeviceManagerInterface::Privat
};
DataDeviceManagerInterface::Private::Private(DataDeviceManagerInterface *q, Display *d)
: Global::Private(d)
: Global::Private(d, &wl_data_device_manager_interface, s_version)
, q(q)
{
}
void DataDeviceManagerInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
auto m = reinterpret_cast<DataDeviceManagerInterface::Private*>(data);
m->bind(client, version, id);
}
void DataDeviceManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
wl_resource *resource = wl_resource_create(client, &wl_data_device_manager_interface, qMin(version, s_version), id);
......@@ -123,12 +115,6 @@ void DataDeviceManagerInterface::Private::getDataDevice(wl_client *client, wl_re
emit q->dataDeviceCreated(dataDevice);
}
void DataDeviceManagerInterface::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, &wl_data_device_manager_interface, s_version, this, bind);
}
DataDeviceManagerInterface::DataDeviceManagerInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
{
......
......@@ -38,7 +38,6 @@ public:
uint32_t version;
};
Private(OutputInterface *q, Display *d);
void create() override;
void sendMode(wl_resource *resource, const Mode &mode);
void sendDone(const ResourceData &data);
void updateGeometry();
......@@ -55,9 +54,8 @@ public:
QList<ResourceData> resources;
private:
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
static void unbind(wl_resource *resource);
void bind(wl_client *client, uint32_t version, uint32_t id);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
int32_t toTransform() const;
int32_t toSubPixel() const;
void sendGeometry(wl_resource *resource);
......@@ -67,17 +65,11 @@ private:
};
OutputInterface::Private::Private(OutputInterface *q, Display *d)
: Global::Private(d)
: Global::Private(d, &wl_output_interface, s_version)
, q(q)
{
}
void OutputInterface::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, &wl_output_interface, s_version, this, bind);
}
OutputInterface::OutputInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
{
......@@ -220,12 +212,6 @@ void OutputInterface::setCurrentMode(const QSize &size, int refreshRate)
emit currentModeChanged();
}
void OutputInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
auto output = reinterpret_cast<OutputInterface::Private*>(data);
output->bind(client, version, id);
}
int32_t OutputInterface::Private::toTransform() const
{
switch (transform) {
......
......@@ -46,8 +46,7 @@ class SeatInterface::Private : public Global::Private
{
public:
Private(SeatInterface *q, Display *d);
void create() override;
void bind(wl_client *client, uint32_t version, uint32_t id);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void sendCapabilities(wl_resource *r);
void sendName(wl_resource *r);
......@@ -66,7 +65,6 @@ public:
private:
static Private *cast(wl_resource *r);
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
static void unbind(wl_resource *r);
// interface
......@@ -79,17 +77,11 @@ private:
};
SeatInterface::Private::Private(SeatInterface *q, Display *display)
: Global::Private(display)
: Global::Private(display, &wl_seat_interface, s_version)
, q(q)
{
}
void SeatInterface::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, &wl_seat_interface, s_version, this, &bind);
}
const struct wl_seat_interface SeatInterface::Private::s_interface = {
getPointerCallback,
getKeyboardCallback,
......@@ -127,11 +119,6 @@ SeatInterface::~SeatInterface()
}
}
void SeatInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
reinterpret_cast<SeatInterface::Private*>(data)->bind(client, version, id);
}
void SeatInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
wl_resource *r = wl_resource_create(client, &wl_seat_interface, qMin(s_version, version), id);
......
......@@ -19,6 +19,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "global.h"
#include "global_p.h"
#include "display.h"
// wayland
#include <wayland-server.h>
......@@ -27,13 +28,27 @@ namespace KWayland
namespace Server
{
Global::Private::Private(Display *d)
Global::Private::Private(Display *d, const wl_interface *interface, quint32 version)
: display(d)
, m_interface(interface)
, m_version(version)
{
}
Global::Private::~Private() = default;
void Global::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
auto d = reinterpret_cast<Private*>(data);
d->bind(client, version, id);
}
void Global::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, m_interface, m_version, this, bind);
}
Global::Global(Global::Private *d, QObject *parent)
: QObject(parent)
, d(d)
......
......@@ -22,6 +22,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "global.h"
struct wl_client;
struct wl_interface;
namespace KWayland
{
namespace Server
......@@ -30,14 +33,21 @@ namespace Server
class Global::Private
{
public:
static constexpr quint32 version = 0;
virtual ~Private();
virtual void create() = 0;
void create();
Display *display = nullptr;
wl_global *global = nullptr;
protected:
Private(Display *d);
Private(Display *d, const wl_interface *interface, quint32 version);
virtual void bind(wl_client *client, uint32_t version, uint32_t id) = 0;
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
const wl_interface *const m_interface;
const quint32 m_version;
};
}
......
......@@ -37,14 +37,12 @@ class ShellInterface::Private : public Global::Private
{
public:
Private(ShellInterface *q, Display *d);
void create() override;
QList<ShellSurfaceInterface*> surfaces;
private:
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
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);
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);
ShellInterface *q;
......@@ -52,17 +50,11 @@ private:
};
ShellInterface::Private::Private(ShellInterface *q, Display *d)
: Global::Private(d)
: Global::Private(d, &wl_shell_interface, s_version)
, q(q)
{
}
void ShellInterface::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, &wl_shell_interface, s_version, this, &bind);
}
const struct wl_shell_interface ShellInterface::Private::s_interface = {
createSurfaceCallback
};
......@@ -129,11 +121,6 @@ ShellInterface::ShellInterface(Display *display, QObject *parent)
ShellInterface::~ShellInterface() = default;
void ShellInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
reinterpret_cast<ShellInterface::Private*>(data)->bind(client, version, id);
}
void ShellInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
wl_resource *shell = wl_resource_create(client, &wl_shell_interface, qMin(version, s_version), id);
......
......@@ -36,13 +36,11 @@ class SubCompositorInterface::Private : public Global::Private
{
public:
Private(SubCompositorInterface *q, Display *d);
void create() override;
private:
void bind(wl_client *client, uint32_t version, uint32_t id);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void subsurface(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *parent);
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
static void unbind(wl_resource *resource);
static void destroyCallback(wl_client *client, wl_resource *resource);
static void subsurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *parent);
......@@ -61,22 +59,11 @@ const struct wl_subcompositor_interface SubCompositorInterface::Private::s_inter
};
SubCompositorInterface::Private::Private(SubCompositorInterface *q, Display *d)
: Global::Private(d)
: Global::Private(d, &wl_subcompositor_interface, s_version)
, q(q)
{
}
void SubCompositorInterface::Private::create()
{
Q_ASSERT(!global);
global = wl_global_create(*display, &wl_subcompositor_interface, s_version, this, bind);
}
void SubCompositorInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
reinterpret_cast<SubCompositorInterface::Private*>(data)->bind(client, version, id);
}
void SubCompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
wl_resource *resource = wl_resource_create(client, &wl_subcompositor_interface, qMin(version, s_version), id);
......
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