Add a base class for all server interfaces of a wl_global

New base class KWayland::Server::Global which all Interface classes
for a wl_global inherit. Furthermore there is a shared base class
for all the Private classes of that type.
This commit is contained in:
Martin Gräßlin 2014-11-13 15:07:31 +01:00
parent dd50148187
commit 22197da94b
16 changed files with 299 additions and 259 deletions

View file

@ -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

View file

@ -19,6 +19,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "compositor_interface.h"
#include "display.h"
#include "global_p.h"
#include "surface_interface.h"
// Wayland
#include <wayland-server.h>
@ -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;
}
}
}

View file

@ -20,6 +20,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#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<Private> d;
};
}

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#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;
}
}

View file

@ -23,6 +23,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <KWayland/Server/kwaylandserver_export.h>
#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<Private> d;
};
}

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "output_interface.h"
#include "global_p.h"
#include "display.h"
#include <wayland-server.h>
@ -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<Private*>(d.data());
}
}

View file

@ -25,6 +25,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <QSize>
#include <KWayland/Server/kwaylandserver_export.h>
#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<Private> d;
Private *d_func() const;
};
}

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#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<wl_resource*> 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<Private*>(d.data());
}
/****************************************
* PointerInterface
***************************************/

View file

@ -24,6 +24,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <QPoint>
#include <KWayland/Server/kwaylandserver_export.h>
#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<Private> d;
Private *d_func() const;
};
class KWAYLANDSERVER_EXPORT PointerInterface : public QObject

View file

@ -0,0 +1,83 @@
/********************************************************************
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "global.h"
#include "global_p.h"
// wayland
#include <wayland-server.h>
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;
}
}
}

View file

@ -0,0 +1,58 @@
/********************************************************************
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef WAYLAND_SERVER_GLOBAL_H
#define WAYLAND_SERVER_GLOBAL_H
#include <QObject>
#include <KWayland/Server/kwaylandserver_export.h>
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<Private> d;
};
}
}
#endif

View file

@ -0,0 +1,46 @@
/********************************************************************
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#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

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#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<ShellSurfaceInterface*> 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
*********************************/

View file

@ -24,6 +24,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Server/kwaylandserver_export.h>
#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<Private> d;
};
class KWAYLANDSERVER_EXPORT ShellSurfaceInterface : public QObject

View file

@ -19,6 +19,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#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,

View file

@ -25,6 +25,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Server/kwaylandserver_export.h>
#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<Private> d;
};
class KWAYLANDSERVER_EXPORT SubSurfaceInterface : public QObject