diff --git a/src/wayland/compositor_interface.cpp b/src/wayland/compositor_interface.cpp index 42ea59f23c..f1ebd3242e 100644 --- a/src/wayland/compositor_interface.cpp +++ b/src/wayland/compositor_interface.cpp @@ -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(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); diff --git a/src/wayland/datadevicemanager_interface.cpp b/src/wayland/datadevicemanager_interface.cpp index 2802cde56f..0cea478319 100644 --- a/src/wayland/datadevicemanager_interface.cpp +++ b/src/wayland/datadevicemanager_interface.cpp @@ -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(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) { diff --git a/src/wayland/output_interface.cpp b/src/wayland/output_interface.cpp index 502f1918e2..3254150fd1 100644 --- a/src/wayland/output_interface.cpp +++ b/src/wayland/output_interface.cpp @@ -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 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(data); - output->bind(client, version, id); -} - int32_t OutputInterface::Private::toTransform() const { switch (transform) { diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index d897ab93ce..1991c555f1 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -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(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); diff --git a/src/wayland/server/global.cpp b/src/wayland/server/global.cpp index 8d1b85da57..ac929633cc 100644 --- a/src/wayland/server/global.cpp +++ b/src/wayland/server/global.cpp @@ -19,6 +19,7 @@ License along with this library. If not, see . *********************************************************************/ #include "global.h" #include "global_p.h" +#include "display.h" // wayland #include @@ -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(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) diff --git a/src/wayland/server/global_p.h b/src/wayland/server/global_p.h index 778c8223df..71f3736962 100644 --- a/src/wayland/server/global_p.h +++ b/src/wayland/server/global_p.h @@ -22,6 +22,9 @@ License along with this library. If not, see . #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; }; } diff --git a/src/wayland/server/shell_interface.cpp b/src/wayland/server/shell_interface.cpp index 0e538fabdb..0bf890939c 100644 --- a/src/wayland/server/shell_interface.cpp +++ b/src/wayland/server/shell_interface.cpp @@ -37,14 +37,12 @@ class ShellInterface::Private : public Global::Private { public: Private(ShellInterface *q, Display *d); - void create() override; QList 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(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); diff --git a/src/wayland/subcompositor_interface.cpp b/src/wayland/subcompositor_interface.cpp index afdd530e96..68b6cfc8e4 100644 --- a/src/wayland/subcompositor_interface.cpp +++ b/src/wayland/subcompositor_interface.cpp @@ -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(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);