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

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.
parent dd501481
......@@ -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
......
......@@ -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))
{
}
CompositorInterface::~CompositorInterface()
{
destroy();
}
void CompositorInterface::create()
: Global(new Private(this, display), parent)
{
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;
}
}
}
......@@ -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;
};
}
......
......@@ -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))
{
}
DataDeviceManagerInterface::~DataDeviceManagerInterface()
{
destroy();
}
void DataDeviceManagerInterface::create()
: Global(new Private(this, display), parent)
{
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;
}
}
......@@ -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;
};
}
......
......@@ -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*()
{
return d->output;
}
OutputInterface::operator wl_global*() const
OutputInterface::Private *OutputInterface::d_func() const
{
return d->output;
return reinterpret_cast<Private*>(d.data());
}
}
......
......@@ -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;
};
}
......
......@@ -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;
}
...