diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt
index 0da74dd772..7bd4d6df33 100644
--- a/src/wayland/CMakeLists.txt
+++ b/src/wayland/CMakeLists.txt
@@ -6,6 +6,7 @@ set(SERVER_LIB_SRCS
dataoffer_interface.cpp
datasource_interface.cpp
display.cpp
+ global.cpp
output_interface.cpp
region_interface.cpp
seat_interface.cpp
@@ -54,6 +55,7 @@ set_target_properties(KF5WaylandServer PROPERTIES VERSION ${KWAYLAND_VERSION_S
# dataoffer_interface.h
# datasource_interface.h
# display.h
+# global.h
# output_interface.h
# region_interface.h
# seat_interface.h
diff --git a/src/wayland/compositor_interface.cpp b/src/wayland/compositor_interface.cpp
index 72dc296d64..42ea59f23c 100644
--- a/src/wayland/compositor_interface.cpp
+++ b/src/wayland/compositor_interface.cpp
@@ -19,6 +19,7 @@ License along with this library. If not, see .
*********************************************************************/
#include "compositor_interface.h"
#include "display.h"
+#include "global_p.h"
#include "surface_interface.h"
// Wayland
#include
@@ -30,14 +31,11 @@ namespace Server
static const quint32 s_version = 3;
-class CompositorInterface::Private
+class CompositorInterface::Private : public Global::Private
{
public:
Private(CompositorInterface *q, Display *d);
- void create();
-
- Display *display;
- wl_global *compositor;
+ void create() override;
private:
void bind(wl_client *client, uint32_t version, uint32_t id);
@@ -57,16 +55,15 @@ private:
};
CompositorInterface::Private::Private(CompositorInterface *q, Display *d)
- : display(d)
- , compositor(nullptr)
+ : Global::Private(d)
, q(q)
{
}
void CompositorInterface::Private::create()
{
- Q_ASSERT(!compositor);
- compositor = wl_global_create(*display, &wl_compositor_interface, s_version, this, bind);
+ Q_ASSERT(!global);
+ global = wl_global_create(*display, &wl_compositor_interface, s_version, this, bind);
}
const struct wl_compositor_interface CompositorInterface::Private::s_interface = {
@@ -75,29 +72,11 @@ const struct wl_compositor_interface CompositorInterface::Private::s_interface =
};
CompositorInterface::CompositorInterface(Display *display, QObject *parent)
- : QObject(parent)
- , d(new Private(this, display))
+ : Global(new Private(this, display), parent)
{
}
-CompositorInterface::~CompositorInterface()
-{
- destroy();
-}
-
-void CompositorInterface::create()
-{
- d->create();
-}
-
-void CompositorInterface::destroy()
-{
- if (!d->compositor) {
- return;
- }
- wl_global_destroy(d->compositor);
- d->compositor = nullptr;
-}
+CompositorInterface::~CompositorInterface() = default;
void CompositorInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
@@ -156,10 +135,5 @@ void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *
emit q->regionCreated(region);
}
-bool CompositorInterface::isValid() const
-{
- return d->compositor != nullptr;
-}
-
}
}
diff --git a/src/wayland/compositor_interface.h b/src/wayland/compositor_interface.h
index 6b972c90cc..9d66e1de21 100644
--- a/src/wayland/compositor_interface.h
+++ b/src/wayland/compositor_interface.h
@@ -20,6 +20,7 @@ License along with this library. If not, see .
#ifndef WAYLAND_SERVER_COMPOSITOR_INTERFACE_H
#define WAYLAND_SERVER_COMPOSITOR_INTERFACE_H
+#include "global.h"
#include "region_interface.h"
#include "surface_interface.h"
@@ -35,16 +36,12 @@ namespace Server
class Display;
class SurfaceInterface;
-class KWAYLANDSERVER_EXPORT CompositorInterface : public QObject
+class KWAYLANDSERVER_EXPORT CompositorInterface : public Global
{
Q_OBJECT
public:
virtual ~CompositorInterface();
- void create();
- void destroy();
- bool isValid() const;
-
Q_SIGNALS:
void surfaceCreated(KWayland::Server::SurfaceInterface*);
void regionCreated(KWayland::Server::RegionInterface*);
@@ -53,7 +50,6 @@ private:
explicit CompositorInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
- QScopedPointer d;
};
}
diff --git a/src/wayland/datadevicemanager_interface.cpp b/src/wayland/datadevicemanager_interface.cpp
index fe3a9653cd..2802cde56f 100644
--- a/src/wayland/datadevicemanager_interface.cpp
+++ b/src/wayland/datadevicemanager_interface.cpp
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see .
*********************************************************************/
#include "datadevicemanager_interface.h"
+#include "global_p.h"
#include "display.h"
#include "seat_interface.h"
// Wayland
@@ -30,14 +31,11 @@ namespace Server
static const quint32 s_version = 1;
-class DataDeviceManagerInterface::Private
+class DataDeviceManagerInterface::Private : public Global::Private
{
public:
Private(DataDeviceManagerInterface *q, Display *d);
- void create();
-
- Display *display;
- wl_global *manager = nullptr;
+ void create() override;
private:
void bind(wl_client *client, uint32_t version, uint32_t id);
@@ -62,7 +60,7 @@ const struct wl_data_device_manager_interface DataDeviceManagerInterface::Privat
};
DataDeviceManagerInterface::Private::Private(DataDeviceManagerInterface *q, Display *d)
- : display(d)
+ : Global::Private(d)
, q(q)
{
}
@@ -127,39 +125,16 @@ void DataDeviceManagerInterface::Private::getDataDevice(wl_client *client, wl_re
void DataDeviceManagerInterface::Private::create()
{
- Q_ASSERT(!manager);
- manager = wl_global_create(*display, &wl_data_device_manager_interface, s_version, this, bind);
+ Q_ASSERT(!global);
+ global = wl_global_create(*display, &wl_data_device_manager_interface, s_version, this, bind);
}
DataDeviceManagerInterface::DataDeviceManagerInterface(Display *display, QObject *parent)
- : QObject(parent)
- , d(new Private(this, display))
+ : Global(new Private(this, display), parent)
{
}
-DataDeviceManagerInterface::~DataDeviceManagerInterface()
-{
- destroy();
-}
-
-void DataDeviceManagerInterface::create()
-{
- d->create();
-}
-
-void DataDeviceManagerInterface::destroy()
-{
- if (!d->manager) {
- return;
- }
- wl_global_destroy(d->manager);
- d->manager = nullptr;
-}
-
-bool DataDeviceManagerInterface::isValid() const
-{
- return d->manager != nullptr;
-}
+DataDeviceManagerInterface::~DataDeviceManagerInterface() = default;
}
}
diff --git a/src/wayland/datadevicemanager_interface.h b/src/wayland/datadevicemanager_interface.h
index 97d992013b..057a7ca18c 100644
--- a/src/wayland/datadevicemanager_interface.h
+++ b/src/wayland/datadevicemanager_interface.h
@@ -23,6 +23,7 @@ License along with this library. If not, see .
#include
#include
+#include "global.h"
#include "datadevice_interface.h"
#include "datasource_interface.h"
@@ -33,16 +34,12 @@ namespace Server
class Display;
-class KWAYLANDSERVER_EXPORT DataDeviceManagerInterface : public QObject
+class KWAYLANDSERVER_EXPORT DataDeviceManagerInterface : public Global
{
Q_OBJECT
public:
virtual ~DataDeviceManagerInterface();
- void create();
- void destroy();
- bool isValid() const;
-
Q_SIGNALS:
void dataSourceCreated(KWayland::Server::DataSourceInterface*);
void dataDeviceCreated(KWayland::Server::DataDeviceInterface*);
@@ -51,7 +48,6 @@ private:
explicit DataDeviceManagerInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
- QScopedPointer d;
};
}
diff --git a/src/wayland/output_interface.cpp b/src/wayland/output_interface.cpp
index 44f3d7fcb9..502f1918e2 100644
--- a/src/wayland/output_interface.cpp
+++ b/src/wayland/output_interface.cpp
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see .
*********************************************************************/
#include "output_interface.h"
+#include "global_p.h"
#include "display.h"
#include
@@ -29,7 +30,7 @@ namespace Server
static const quint32 s_version = 2;
-class OutputInterface::Private
+class OutputInterface::Private : public Global::Private
{
public:
struct ResourceData {
@@ -37,14 +38,12 @@ public:
uint32_t version;
};
Private(OutputInterface *q, Display *d);
- void create();
+ void create() override;
void sendMode(wl_resource *resource, const Mode &mode);
void sendDone(const ResourceData &data);
void updateGeometry();
void updateScale();
- Display *display;
- wl_global *output = nullptr;
QSize physicalSize;
QPoint globalPosition;
QString manufacturer = QStringLiteral("org.kde.kwin");
@@ -68,23 +67,23 @@ private:
};
OutputInterface::Private::Private(OutputInterface *q, Display *d)
- : display(d)
+ : Global::Private(d)
, q(q)
{
}
void OutputInterface::Private::create()
{
- Q_ASSERT(!output);
- output = wl_global_create(*display, &wl_output_interface, s_version, this, bind);
+ Q_ASSERT(!global);
+ global = wl_global_create(*display, &wl_output_interface, s_version, this, bind);
}
OutputInterface::OutputInterface(Display *display, QObject *parent)
- : QObject(parent)
- , d(new Private(this, display))
+ : Global(new Private(this, display), parent)
{
+ Q_D();
connect(this, &OutputInterface::currentModeChanged, this,
- [this] {
+ [this, d] {
auto currentModeIt = std::find_if(d->modes.constBegin(), d->modes.constEnd(), [](const Mode &mode) { return mode.flags.testFlag(ModeFlag::Current); });
if (currentModeIt == d->modes.constEnd()) {
return;
@@ -95,35 +94,19 @@ OutputInterface::OutputInterface(Display *display, QObject *parent)
}
}
);
- connect(this, &OutputInterface::subPixelChanged, this, [this] { d->updateGeometry(); });
- connect(this, &OutputInterface::transformChanged, this, [this] { d->updateGeometry(); });
- connect(this, &OutputInterface::globalPositionChanged, this, [this] { d->updateGeometry(); });
- connect(this, &OutputInterface::modelChanged, this, [this] { d->updateGeometry(); });
- connect(this, &OutputInterface::manufacturerChanged, this, [this] { d->updateGeometry(); });
- connect(this, &OutputInterface::scaleChanged, this, [this] { d->updateScale(); });
+ connect(this, &OutputInterface::subPixelChanged, this, [this, d] { d->updateGeometry(); });
+ connect(this, &OutputInterface::transformChanged, this, [this, d] { d->updateGeometry(); });
+ connect(this, &OutputInterface::globalPositionChanged, this, [this, d] { d->updateGeometry(); });
+ connect(this, &OutputInterface::modelChanged, this, [this, d] { d->updateGeometry(); });
+ connect(this, &OutputInterface::manufacturerChanged, this, [this, d] { d->updateGeometry(); });
+ connect(this, &OutputInterface::scaleChanged, this, [this, d] { d->updateScale(); });
}
-OutputInterface::~OutputInterface()
-{
- destroy();
-}
-
-void OutputInterface::create()
-{
- d->create();
-}
-
-void OutputInterface::destroy()
-{
- if (!d->output) {
- return;
- }
- wl_global_destroy(d->output);
- d->output = nullptr;
-}
+OutputInterface::~OutputInterface() = default;
QSize OutputInterface::pixelSize() const
{
+ Q_D();
auto it = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
@@ -137,6 +120,7 @@ QSize OutputInterface::pixelSize() const
int OutputInterface::refreshRate() const
{
+ Q_D();
auto it = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
@@ -151,6 +135,7 @@ int OutputInterface::refreshRate() const
void OutputInterface::addMode(const QSize &size, OutputInterface::ModeFlags flags, int refreshRate)
{
Q_ASSERT(!isValid());
+ Q_D();
auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
@@ -210,6 +195,7 @@ void OutputInterface::addMode(const QSize &size, OutputInterface::ModeFlags flag
void OutputInterface::setCurrentMode(const QSize &size, int refreshRate)
{
+ Q_D();
auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
@@ -391,6 +377,7 @@ void OutputInterface::Private::updateScale()
#define SETTER(setterName, type, argumentName) \
void OutputInterface::setterName(type arg) \
{ \
+ Q_D(); \
if (d->argumentName == arg) { \
return; \
} \
@@ -408,59 +395,57 @@ SETTER(setTransform, Transform, transform)
#undef SETTER
-bool OutputInterface::isValid() const
-{
- return d->output != nullptr;
-}
-
QSize OutputInterface::physicalSize() const
{
+ Q_D();
return d->physicalSize;
}
QPoint OutputInterface::globalPosition() const
{
+ Q_D();
return d->globalPosition;
}
QString OutputInterface::manufacturer() const
{
+ Q_D();
return d->manufacturer;
}
QString OutputInterface::model() const
{
+ Q_D();
return d->model;
}
int OutputInterface::scale() const
{
+ Q_D();
return d->scale;
}
OutputInterface::SubPixel OutputInterface::subPixel() const
{
+ Q_D();
return d->subPixel;
}
OutputInterface::Transform OutputInterface::transform() const
{
+ Q_D();
return d->transform;
}
QList< OutputInterface::Mode > OutputInterface::modes() const
{
+ Q_D();
return d->modes;
}
-OutputInterface::operator wl_global*()
+OutputInterface::Private *OutputInterface::d_func() const
{
- return d->output;
-}
-
-OutputInterface::operator wl_global*() const
-{
- return d->output;
+ return reinterpret_cast(d.data());
}
}
diff --git a/src/wayland/output_interface.h b/src/wayland/output_interface.h
index f5acdc56c2..080ec7f786 100644
--- a/src/wayland/output_interface.h
+++ b/src/wayland/output_interface.h
@@ -25,6 +25,7 @@ License along with this library. If not, see .
#include
#include
+#include "global.h"
struct wl_global;
struct wl_client;
@@ -37,7 +38,7 @@ namespace Server
class Display;
-class KWAYLANDSERVER_EXPORT OutputInterface : public QObject
+class KWAYLANDSERVER_EXPORT OutputInterface : public Global
{
Q_OBJECT
Q_PROPERTY(QSize physicalSize READ physicalSize WRITE setPhysicalSize NOTIFY physicalSizeChanged)
@@ -77,9 +78,6 @@ public:
ModeFlags flags;
};
virtual ~OutputInterface();
- void create();
- void destroy();
- bool isValid() const;
QSize physicalSize() const;
QPoint globalPosition() const;
@@ -102,9 +100,6 @@ public:
void addMode(const QSize &size, ModeFlags flags = ModeFlags(), int refreshRate = 60000);
void setCurrentMode(const QSize &size, int refreshRate = 60000);
- operator wl_global*();
- operator wl_global*() const;
-
Q_SIGNALS:
void physicalSizeChanged(const QSize&);
void globalPositionChanged(const QPoint&);
@@ -122,7 +117,7 @@ private:
friend class Display;
explicit OutputInterface(Display *display, QObject *parent = nullptr);
class Private;
- QScopedPointer d;
+ Private *d_func() const;
};
}
diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp
index 811f3089e9..d897ab93ce 100644
--- a/src/wayland/seat_interface.cpp
+++ b/src/wayland/seat_interface.cpp
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see .
*********************************************************************/
#include "seat_interface.h"
+#include "global_p.h"
#include "display.h"
#include "surface_interface.h"
// Qt
@@ -41,24 +42,22 @@ namespace Server
static const quint32 s_version = 3;
-class SeatInterface::Private
+class SeatInterface::Private : public Global::Private
{
public:
Private(SeatInterface *q, Display *d);
- void create();
+ void create() override;
void bind(wl_client *client, uint32_t version, uint32_t id);
void sendCapabilities(wl_resource *r);
void sendName(wl_resource *r);
- Display *display;
- wl_global *seat = nullptr;
QString name;
bool pointer = false;
bool keyboard = false;
bool touch = false;
QList resources;
- PointerInterface *pointerInterface;
- KeyboardInterface *keyboardInterface;
+ PointerInterface *pointerInterface = nullptr;
+ KeyboardInterface *keyboardInterface = nullptr;
static SeatInterface *get(wl_resource *native) {
auto s = cast(native);
@@ -79,18 +78,16 @@ private:
SeatInterface *q;
};
-SeatInterface::Private::Private(SeatInterface *q, Display *d)
- : display(d)
- , pointerInterface(new PointerInterface(d, q))
- , keyboardInterface(new KeyboardInterface(d, q))
+SeatInterface::Private::Private(SeatInterface *q, Display *display)
+ : Global::Private(display)
, q(q)
{
}
void SeatInterface::Private::create()
{
- Q_ASSERT(!seat);
- seat = wl_global_create(*display, &wl_seat_interface, s_version, this, &bind);
+ Q_ASSERT(!global);
+ global = wl_global_create(*display, &wl_seat_interface, s_version, this, &bind);
}
const struct wl_seat_interface SeatInterface::Private::s_interface = {
@@ -100,17 +97,19 @@ const struct wl_seat_interface SeatInterface::Private::s_interface = {
};
SeatInterface::SeatInterface(Display *display, QObject *parent)
- : QObject(parent)
- , d(new Private(this, display))
+ : Global(new Private(this, display), parent)
{
+ Q_D();
+ d->pointerInterface = new PointerInterface(display, this);
+ d->keyboardInterface = new KeyboardInterface(display, this);
connect(this, &SeatInterface::nameChanged, this,
- [this] {
+ [this, d] {
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
d->sendName(*it);
}
}
);
- auto sendCapabilitiesAll = [this] {
+ auto sendCapabilitiesAll = [this, d] {
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
d->sendCapabilities(*it);
}
@@ -122,23 +121,10 @@ SeatInterface::SeatInterface(Display *display, QObject *parent)
SeatInterface::~SeatInterface()
{
- destroy();
-}
-
-void SeatInterface::create()
-{
- d->create();
-}
-
-void SeatInterface::destroy()
-{
+ Q_D();
while (!d->resources.isEmpty()) {
wl_resource_destroy(d->resources.takeLast());
}
- if (d->seat) {
- wl_global_destroy(d->seat);
- d->seat = nullptr;
- }
}
void SeatInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
@@ -196,6 +182,7 @@ SeatInterface::Private *SeatInterface::Private::cast(wl_resource *r)
void SeatInterface::setHasKeyboard(bool has)
{
+ Q_D();
if (d->keyboard == has) {
return;
}
@@ -205,6 +192,7 @@ void SeatInterface::setHasKeyboard(bool has)
void SeatInterface::setHasPointer(bool has)
{
+ Q_D();
if (d->pointer == has) {
return;
}
@@ -214,6 +202,7 @@ void SeatInterface::setHasPointer(bool has)
void SeatInterface::setHasTouch(bool has)
{
+ Q_D();
if (d->touch == has) {
return;
}
@@ -223,6 +212,7 @@ void SeatInterface::setHasTouch(bool has)
void SeatInterface::setName(const QString &name)
{
+ Q_D();
if (d->name == name) {
return;
}
@@ -247,37 +237,39 @@ void SeatInterface::Private::getTouchCallback(wl_client *client, wl_resource *re
Q_UNUSED(id)
}
-bool SeatInterface::isValid() const {
- return d->seat != nullptr;
-}
-
QString SeatInterface::name() const
{
+ Q_D();
return d->name;
}
bool SeatInterface::hasPointer() const
{
+ Q_D();
return d->pointer;
}
bool SeatInterface::hasKeyboard() const
{
+ Q_D();
return d->keyboard;
}
bool SeatInterface::hasTouch() const
{
+ Q_D();
return d->touch;
}
PointerInterface *SeatInterface::pointer()
{
+ Q_D();
return d->pointerInterface;
}
KeyboardInterface *SeatInterface::keyboard()
{
+ Q_D();
return d->keyboardInterface;
}
@@ -286,6 +278,11 @@ SeatInterface *SeatInterface::get(wl_resource *native)
return Private::get(native);
}
+SeatInterface::Private *SeatInterface::d_func() const
+{
+ return reinterpret_cast(d.data());
+}
+
/****************************************
* PointerInterface
***************************************/
diff --git a/src/wayland/seat_interface.h b/src/wayland/seat_interface.h
index 2d64632377..a6dffb85c9 100644
--- a/src/wayland/seat_interface.h
+++ b/src/wayland/seat_interface.h
@@ -24,6 +24,7 @@ License along with this library. If not, see .
#include
#include
+#include "global.h"
struct wl_client;
struct wl_resource;
@@ -38,7 +39,7 @@ class KeyboardInterface;
class PointerInterface;
class SurfaceInterface;
-class KWAYLANDSERVER_EXPORT SeatInterface : public QObject
+class KWAYLANDSERVER_EXPORT SeatInterface : public Global
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
@@ -48,10 +49,6 @@ class KWAYLANDSERVER_EXPORT SeatInterface : public QObject
public:
virtual ~SeatInterface();
- void create();
- void destroy();
- bool isValid() const;
-
QString name() const;
bool hasPointer() const;
bool hasKeyboard() const;
@@ -77,7 +74,7 @@ private:
explicit SeatInterface(Display *display, QObject *parent);
class Private;
- QScopedPointer d;
+ Private *d_func() const;
};
class KWAYLANDSERVER_EXPORT PointerInterface : public QObject
diff --git a/src/wayland/server/global.cpp b/src/wayland/server/global.cpp
new file mode 100644
index 0000000000..8d1b85da57
--- /dev/null
+++ b/src/wayland/server/global.cpp
@@ -0,0 +1,83 @@
+/********************************************************************
+Copyright 2014 Martin Gräßlin
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library. If not, see .
+*********************************************************************/
+#include "global.h"
+#include "global_p.h"
+// wayland
+#include
+
+namespace KWayland
+{
+namespace Server
+{
+
+Global::Private::Private(Display *d)
+ : display(d)
+{
+}
+
+Global::Private::~Private() = default;
+
+Global::Global(Global::Private *d, QObject *parent)
+ : QObject(parent)
+ , d(d)
+{
+}
+
+Global::~Global()
+{
+ destroy();
+}
+
+void Global::create()
+{
+ d->create();
+}
+
+void Global::destroy()
+{
+ if (!d->global) {
+ return;
+ }
+ wl_global_destroy(d->global);
+ d->global = nullptr;
+}
+
+bool Global::isValid() const
+{
+ return d->global != nullptr;
+}
+
+Global::operator wl_global*() const
+{
+ return d->global;
+}
+
+Global::operator wl_global*()
+{
+ return d->global;
+}
+
+Display *Global::display()
+{
+ return d->display;
+}
+
+}
+}
diff --git a/src/wayland/server/global.h b/src/wayland/server/global.h
new file mode 100644
index 0000000000..35a02acae0
--- /dev/null
+++ b/src/wayland/server/global.h
@@ -0,0 +1,58 @@
+/********************************************************************
+Copyright 2014 Martin Gräßlin
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library. If not, see .
+*********************************************************************/
+#ifndef WAYLAND_SERVER_GLOBAL_H
+#define WAYLAND_SERVER_GLOBAL_H
+
+#include
+
+#include
+
+struct wl_global;
+
+namespace KWayland
+{
+namespace Server
+{
+class Display;
+
+class KWAYLANDSERVER_EXPORT Global : public QObject
+{
+ Q_OBJECT
+public:
+ virtual ~Global();
+ void create();
+ void destroy();
+ bool isValid() const;
+
+ Display *display();
+
+ operator wl_global*();
+ operator wl_global*() const;
+
+protected:
+ class Private;
+ explicit Global(Private *d, QObject *parent = nullptr);
+ QScopedPointer d;
+};
+
+}
+}
+
+#endif
diff --git a/src/wayland/server/global_p.h b/src/wayland/server/global_p.h
new file mode 100644
index 0000000000..778c8223df
--- /dev/null
+++ b/src/wayland/server/global_p.h
@@ -0,0 +1,46 @@
+/********************************************************************
+Copyright 2014 Martin Gräßlin
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library. If not, see .
+*********************************************************************/
+#ifndef WAYLAND_SERVER_GLOBAL_P_H
+#define WAYLAND_SERVER_GLOBAL_P_H
+
+#include "global.h"
+
+namespace KWayland
+{
+namespace Server
+{
+
+class Global::Private
+{
+public:
+ virtual ~Private();
+ virtual void create() = 0;
+
+ Display *display = nullptr;
+ wl_global *global = nullptr;
+
+protected:
+ Private(Display *d);
+};
+
+}
+}
+
+#endif
diff --git a/src/wayland/server/shell_interface.cpp b/src/wayland/server/shell_interface.cpp
index cab9c76e37..0e538fabdb 100644
--- a/src/wayland/server/shell_interface.cpp
+++ b/src/wayland/server/shell_interface.cpp
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see .
*********************************************************************/
#include "shell_interface.h"
+#include "global_p.h"
#include "display.h"
#include "surface_interface.h"
@@ -32,14 +33,12 @@ namespace Server
static const quint32 s_version = 1;
-class ShellInterface::Private
+class ShellInterface::Private : public Global::Private
{
public:
Private(ShellInterface *q, Display *d);
- void create();
+ void create() override;
- Display *display;
- wl_global *shell = nullptr;
QList surfaces;
private:
@@ -53,15 +52,15 @@ private:
};
ShellInterface::Private::Private(ShellInterface *q, Display *d)
- : display(d)
+ : Global::Private(d)
, q(q)
{
}
void ShellInterface::Private::create()
{
- Q_ASSERT(!shell);
- shell = wl_global_create(*display, &wl_shell_interface, s_version, this, &bind);
+ Q_ASSERT(!global);
+ global = wl_global_create(*display, &wl_shell_interface, s_version, this, &bind);
}
const struct wl_shell_interface ShellInterface::Private::s_interface = {
@@ -124,29 +123,11 @@ private:
};
ShellInterface::ShellInterface(Display *display, QObject *parent)
- : QObject(parent)
- , d(new Private(this, display))
+ : Global(new Private(this, display), parent)
{
}
-ShellInterface::~ShellInterface()
-{
- destroy();
-}
-
-void ShellInterface::create()
-{
- d->create();
-}
-
-void ShellInterface::destroy()
-{
- if (!d->shell) {
- return;
- }
- wl_global_destroy(d->shell);
- d->shell = nullptr;
-}
+ShellInterface::~ShellInterface() = default;
void ShellInterface::Private::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
{
@@ -191,16 +172,6 @@ void ShellInterface::Private::createSurface(wl_client *client, uint32_t version,
emit q->surfaceCreated(shellSurface);
}
-bool ShellInterface::isValid() const
-{
- return d->shell != nullptr;
-}
-
-Display *ShellInterface::display() const
-{
- return d->display;
-}
-
/*********************************
* ShellSurfaceInterface
*********************************/
diff --git a/src/wayland/server/shell_interface.h b/src/wayland/server/shell_interface.h
index 683c90ba76..2e98ffef02 100644
--- a/src/wayland/server/shell_interface.h
+++ b/src/wayland/server/shell_interface.h
@@ -24,6 +24,8 @@ License along with this library. If not, see .
#include
+#include "global.h"
+
class QSize;
struct wl_resource;
@@ -36,19 +38,12 @@ class Display;
class SurfaceInterface;
class ShellSurfaceInterface;
-class KWAYLANDSERVER_EXPORT ShellInterface : public QObject
+class KWAYLANDSERVER_EXPORT ShellInterface : public Global
{
Q_OBJECT
public:
virtual ~ShellInterface();
- void create();
- void destroy();
-
- bool isValid() const;
-
- Display *display() const;
-
Q_SIGNALS:
void surfaceCreated(KWayland::Server::ShellSurfaceInterface*);
@@ -56,7 +51,6 @@ private:
friend class Display;
explicit ShellInterface(Display *display, QObject *parent);
class Private;
- QScopedPointer d;
};
class KWAYLANDSERVER_EXPORT ShellSurfaceInterface : public QObject
diff --git a/src/wayland/subcompositor_interface.cpp b/src/wayland/subcompositor_interface.cpp
index af1801879b..afdd530e96 100644
--- a/src/wayland/subcompositor_interface.cpp
+++ b/src/wayland/subcompositor_interface.cpp
@@ -19,6 +19,7 @@ License along with this library. If not, see .
*********************************************************************/
#include "subcompositor_interface.h"
#include "subsurface_interface_p.h"
+#include "global_p.h"
#include "display.h"
#include "surface_interface_p.h"
// Wayland
@@ -31,14 +32,11 @@ namespace Server
static const quint32 s_version = 1;
-class SubCompositorInterface::Private
+class SubCompositorInterface::Private : public Global::Private
{
public:
Private(SubCompositorInterface *q, Display *d);
- void create();
-
- Display *display;
- wl_global *compositor;
+ void create() override;
private:
void bind(wl_client *client, uint32_t version, uint32_t id);
@@ -63,16 +61,15 @@ const struct wl_subcompositor_interface SubCompositorInterface::Private::s_inter
};
SubCompositorInterface::Private::Private(SubCompositorInterface *q, Display *d)
- : display(d)
- , compositor(nullptr)
+ : Global::Private(d)
, q(q)
{
}
void SubCompositorInterface::Private::create()
{
- Q_ASSERT(!compositor);
- compositor = wl_global_create(*display, &wl_subcompositor_interface, s_version, this, bind);
+ 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)
@@ -132,34 +129,11 @@ void SubCompositorInterface::Private::subsurface(wl_client *client, wl_resource
}
SubCompositorInterface::SubCompositorInterface(Display *display, QObject *parent)
- : QObject(parent)
- , d(new Private(this, display))
+ : Global(new Private(this, display), parent)
{
}
-SubCompositorInterface::~SubCompositorInterface()
-{
- destroy();
-}
-
-void SubCompositorInterface::destroy()
-{
- if (!d->compositor) {
- return;
- }
- wl_global_destroy(d->compositor);
- d->compositor = nullptr;
-}
-
-void SubCompositorInterface::create()
-{
- d->create();
-}
-
-bool SubCompositorInterface::isValid() const
-{
- return d->compositor != nullptr;
-}
+SubCompositorInterface::~SubCompositorInterface() = default;
const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface = {
destroyCallback,
diff --git a/src/wayland/subcompositor_interface.h b/src/wayland/subcompositor_interface.h
index e6f4690ad0..dbe43b9ac4 100644
--- a/src/wayland/subcompositor_interface.h
+++ b/src/wayland/subcompositor_interface.h
@@ -25,6 +25,8 @@ License along with this library. If not, see .
#include
+#include "global.h"
+
struct wl_resource;
namespace KWayland
@@ -36,16 +38,12 @@ class Display;
class SurfaceInterface;
class SubSurfaceInterface;
-class KWAYLANDSERVER_EXPORT SubCompositorInterface : public QObject
+class KWAYLANDSERVER_EXPORT SubCompositorInterface : public Global
{
Q_OBJECT
public:
virtual ~SubCompositorInterface();
- void create();
- void destroy();
- bool isValid() const;
-
Q_SIGNALS:
void subSurfaceCreated(KWayland::Server::SubSurfaceInterface*);
@@ -53,7 +51,6 @@ private:
explicit SubCompositorInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
- QScopedPointer d;
};
class KWAYLANDSERVER_EXPORT SubSurfaceInterface : public QObject