Commit 56278245 authored by Adrien Faveraux's avatar Adrien Faveraux
Browse files

migrate Plasma Desktop interface to the new approach

parent a669b861
......@@ -121,8 +121,6 @@ void TestVirtualDesktop::init()
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_plasmaVirtualDesktopManagementInterface = m_display->createPlasmaVirtualDesktopManagement(m_display);
m_plasmaVirtualDesktopManagementInterface->create();
QVERIFY(m_plasmaVirtualDesktopManagementInterface->isValid());
QVERIFY(plasmaVirtualDesktopManagementSpy.wait());
m_plasmaVirtualDesktopManagement = registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(), plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(), this);
......
......@@ -103,8 +103,6 @@ void PlasmaWindowModelTest::init()
m_pwInterface = m_display->createPlasmaWindowManagement();
m_pwInterface->create();
m_plasmaVirtualDesktopManagementInterface = m_display->createPlasmaVirtualDesktopManagement(m_display);
m_plasmaVirtualDesktopManagementInterface->create();
QVERIFY(m_plasmaVirtualDesktopManagementInterface->isValid());
m_plasmaVirtualDesktopManagementInterface->createDesktop("desktop1");
m_plasmaVirtualDesktopManagementInterface->createDesktop("desktop2");
m_pwInterface->setPlasmaVirtualDesktopManagementInterface(m_plasmaVirtualDesktopManagementInterface);
......
......@@ -97,9 +97,9 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME plasma-shell
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/plasma-virtual-desktop.xml
BASENAME plasma-virtual-desktop
BASENAME org-kde-plasma-virtual-desktop
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
......
......@@ -5,200 +5,144 @@
*/
#include "plasmavirtualdesktop_interface.h"
#include "display.h"
#include "global_p.h"
#include "resource_p.h"
#include <QDebug>
#include <QTimer>
#include <wayland-server.h>
#include <wayland-plasma-virtual-desktop-server-protocol.h>
#include <qwayland-server-org-kde-plasma-virtual-desktop.h>
namespace KWaylandServer
{
class Q_DECL_HIDDEN PlasmaVirtualDesktopInterface::Private
class PlasmaVirtualDesktopInterfacePrivate : public QtWaylandServer::org_kde_plasma_virtual_desktop
{
public:
Private(PlasmaVirtualDesktopInterface *q, PlasmaVirtualDesktopManagementInterface *c);
~Private();
void createResource(wl_resource *parent, quint32 serial);
PlasmaVirtualDesktopInterfacePrivate(PlasmaVirtualDesktopInterface *q, PlasmaVirtualDesktopManagementInterface *c);
~PlasmaVirtualDesktopInterfacePrivate();
PlasmaVirtualDesktopInterface *q;
PlasmaVirtualDesktopManagementInterface *vdm;
QVector<wl_resource*> resources;
QString id;
QString name;
bool active = false;
private:
static void unbind(wl_resource *resource);
static void requestActivateCallback(wl_client *client, wl_resource *resource);
static Private *cast(wl_resource *resource) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
}
static const struct org_kde_plasma_virtual_desktop_interface s_interface;
protected:
void org_kde_plasma_virtual_desktop_bind_resource(Resource *resource) override;
void org_kde_plasma_virtual_desktop_request_activate(Resource *resource) override;
};
class Q_DECL_HIDDEN PlasmaVirtualDesktopManagementInterface::Private : public Global::Private
class PlasmaVirtualDesktopManagementInterfacePrivate : public QtWaylandServer::org_kde_plasma_virtual_desktop_management
{
public:
Private(PlasmaVirtualDesktopManagementInterface *q, Display *d);
PlasmaVirtualDesktopManagementInterfacePrivate(PlasmaVirtualDesktopManagementInterface *_q, Display *display);
QVector<wl_resource*> resources;
QList<PlasmaVirtualDesktopInterface*> desktops;
quint32 rows = 0;
quint32 columns = 0;
PlasmaVirtualDesktopManagementInterface *q;
static const quint32 s_version;
inline QList<PlasmaVirtualDesktopInterface*>::const_iterator constFindDesktop(const QString &id);
inline QList<PlasmaVirtualDesktopInterface*>::iterator findDesktop(const QString &id);
private:
void bind(wl_client *client, uint32_t version, uint32_t id) override;
static void unbind(wl_resource *resource);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
static void getVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *id);
static void requestCreateVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *name, uint32_t position);
static void requestRemoveVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *id);
protected:
PlasmaVirtualDesktopManagementInterface *q;
static const struct org_kde_plasma_virtual_desktop_management_interface s_interface;
static const quint32 s_version;
void org_kde_plasma_virtual_desktop_management_get_virtual_desktop(Resource *resource, uint32_t id, const QString &desktop_id) override;
void org_kde_plasma_virtual_desktop_management_request_create_virtual_desktop(Resource *resource, const QString &name, uint32_t position) override;
void org_kde_plasma_virtual_desktop_management_request_remove_virtual_desktop(Resource *resource, const QString &desktop_id) override;
void org_kde_plasma_virtual_desktop_management_bind_resource(Resource *resource) override;
};
const quint32 PlasmaVirtualDesktopManagementInterface::Private::s_version = 2;
const quint32 PlasmaVirtualDesktopManagementInterfacePrivate::s_version = 2;
#ifndef K_DOXYGEN
const struct org_kde_plasma_virtual_desktop_management_interface PlasmaVirtualDesktopManagementInterface::Private::s_interface = {
getVirtualDesktopCallback,
requestCreateVirtualDesktopCallback,
requestRemoveVirtualDesktopCallback
};
#endif
inline QList<PlasmaVirtualDesktopInterface*>::const_iterator PlasmaVirtualDesktopManagementInterface::Private::constFindDesktop(const QString &id)
inline QList<PlasmaVirtualDesktopInterface*>::const_iterator PlasmaVirtualDesktopManagementInterfacePrivate::constFindDesktop(const QString &id)
{
return std::find_if( desktops.constBegin(),
desktops.constEnd(),
[id]( const PlasmaVirtualDesktopInterface *desk ){ return desk->id() == id; } );
}
inline QList<PlasmaVirtualDesktopInterface*>::iterator PlasmaVirtualDesktopManagementInterface::Private::findDesktop(const QString &id)
inline QList<PlasmaVirtualDesktopInterface*>::iterator PlasmaVirtualDesktopManagementInterfacePrivate::findDesktop(const QString &id)
{
return std::find_if( desktops.begin(),
desktops.end(),
[id]( const PlasmaVirtualDesktopInterface *desk ){ return desk->id() == id; } );
}
void PlasmaVirtualDesktopManagementInterface::Private::getVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *id)
void PlasmaVirtualDesktopManagementInterfacePrivate::org_kde_plasma_virtual_desktop_management_get_virtual_desktop(Resource *resource, uint32_t id, const QString &desktop_id)
{
Q_UNUSED(client)
auto s = cast(resource);
auto i = s->constFindDesktop(QString::fromUtf8(id));
if (i == s->desktops.constEnd()) {
auto i = constFindDesktop(desktop_id);
if (i == desktops.constEnd()) {
return;
}
(*i)->d->createResource(resource, serial);
(*i)->d->add(resource->client(), id, resource->version());
}
void PlasmaVirtualDesktopManagementInterface::Private::requestCreateVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *name, uint32_t position)
void PlasmaVirtualDesktopManagementInterfacePrivate::org_kde_plasma_virtual_desktop_management_request_create_virtual_desktop(Resource *resource, const QString &name, uint32_t position)
{
Q_UNUSED(client)
auto s = cast(resource);
emit s->q->desktopCreateRequested(QString::fromUtf8(name), qBound<quint32>(0, position, (quint32)s->desktops.count()));
emit q->desktopCreateRequested(name, qBound<quint32>(0, position, (quint32)desktops.count()));
}
void PlasmaVirtualDesktopManagementInterface::Private::requestRemoveVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *id)
void PlasmaVirtualDesktopManagementInterfacePrivate::org_kde_plasma_virtual_desktop_management_request_remove_virtual_desktop(Resource *resource, const QString &desktop_id)
{
Q_UNUSED(client)
auto s = cast(resource);
emit s->q->desktopRemoveRequested(QString::fromUtf8(id));
emit q->desktopRemoveRequested(desktop_id);
}
PlasmaVirtualDesktopManagementInterface::Private::Private(PlasmaVirtualDesktopManagementInterface *q, Display *d)
: Global::Private(d, &org_kde_plasma_virtual_desktop_management_interface, s_version)
, q(q)
PlasmaVirtualDesktopManagementInterfacePrivate::PlasmaVirtualDesktopManagementInterfacePrivate(PlasmaVirtualDesktopManagementInterface *_q, Display *display)
: QtWaylandServer::org_kde_plasma_virtual_desktop_management(*display, s_version)
, q(_q)
{
}
void PlasmaVirtualDesktopManagementInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
void PlasmaVirtualDesktopManagementInterfacePrivate::org_kde_plasma_virtual_desktop_management_bind_resource(Resource *resource)
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&org_kde_plasma_virtual_desktop_management_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
resources << resource;
wl_resource_set_implementation(resource, &s_interface, this, unbind);
quint32 i = 0;
for (auto it = desktops.constBegin(); it != desktops.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_management_send_desktop_created(resource, (*it)->id().toUtf8().constData(), i++);
send_desktop_created(resource->handle, (*it)->id(), i++);
}
if (wl_resource_get_version(resource) >= ORG_KDE_PLASMA_VIRTUAL_DESKTOP_MANAGEMENT_ROWS_SINCE_VERSION) {
org_kde_plasma_virtual_desktop_management_send_rows(resource, rows);
if (resource->version() >= ORG_KDE_PLASMA_VIRTUAL_DESKTOP_MANAGEMENT_ROWS_SINCE_VERSION) {
send_rows(resource->handle, rows);
}
org_kde_plasma_virtual_desktop_management_send_done(resource);
}
void PlasmaVirtualDesktopManagementInterface::Private::unbind(wl_resource *resource)
{
auto dm = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
dm->resources.removeAll(resource);
send_done(resource->handle);
}
PlasmaVirtualDesktopManagementInterface::PlasmaVirtualDesktopManagementInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
: QObject(parent)
, d(new PlasmaVirtualDesktopManagementInterfacePrivate(this, display))
{
}
PlasmaVirtualDesktopManagementInterface::~PlasmaVirtualDesktopManagementInterface()
{
Q_D();
qDeleteAll(d->desktops);
}
PlasmaVirtualDesktopManagementInterface::Private *PlasmaVirtualDesktopManagementInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
void PlasmaVirtualDesktopManagementInterface::setRows(quint32 rows)
{
Q_D();
if (rows == 0 || d->rows == rows) {
return;
}
d->rows = rows;
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
if (wl_resource_get_version(*it) < ORG_KDE_PLASMA_VIRTUAL_DESKTOP_MANAGEMENT_ROWS_SINCE_VERSION) {
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
if (resource->version() < ORG_KDE_PLASMA_VIRTUAL_DESKTOP_MANAGEMENT_ROWS_SINCE_VERSION) {
continue;
}
org_kde_plasma_virtual_desktop_management_send_rows(*it, rows);
d->send_rows(resource->handle, rows);
}
}
PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::desktop(const QString &id)
{
Q_D();
auto i = d->constFindDesktop(id);
if (i != d->desktops.constEnd()) {
return *i;
......@@ -208,7 +152,6 @@ PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::desktop(
PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::createDesktop(const QString &id, quint32 position)
{
Q_D();
auto i = d->constFindDesktop(id);
if (i != d->desktops.constEnd()) {
return *i;
......@@ -216,10 +159,12 @@ PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::createDe
const quint32 actualPosition = qMin(position, (quint32)d->desktops.count());
PlasmaVirtualDesktopInterface *desktop = new PlasmaVirtualDesktopInterface(this);
auto desktop = new PlasmaVirtualDesktopInterface(this);
desktop->d->id = id;
for (auto it = desktop->d->resources.constBegin(); it != desktop->d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_send_desktop_id(*it, id.toUtf8().constData());
const auto desktopClientResources = desktop->d->resourceMap();
for (auto resource : desktopClientResources) {
desktop->d->send_desktop_id(resource->handle, id);
}
//activate the first desktop TODO: to be done here?
......@@ -229,8 +174,9 @@ PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::createDe
d->desktops.insert(actualPosition, desktop);
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_management_send_desktop_created(*it, id.toUtf8().constData(), actualPosition);
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
d->send_desktop_created(resource->handle, id, actualPosition);
}
return desktop;
......@@ -238,18 +184,19 @@ PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::createDe
void PlasmaVirtualDesktopManagementInterface::removeDesktop(const QString &id)
{
Q_D();
auto deskIt = d->findDesktop(id);
if (deskIt == d->desktops.end()) {
return;
}
for (auto it = (*deskIt)->d->resources.constBegin(); it != (*deskIt)->d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_send_removed(*it);
const auto desktopClientResources = (*deskIt)->d->resourceMap();
for (auto resource : desktopClientResources) {
(*deskIt)->d->send_removed(resource->handle);
}
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_management_send_desktop_removed(*it, id.toUtf8().constData());
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
d->send_desktop_removed(resource->handle, id);
}
(*deskIt)->deleteLater();
......@@ -258,82 +205,56 @@ void PlasmaVirtualDesktopManagementInterface::removeDesktop(const QString &id)
QList <PlasmaVirtualDesktopInterface *> PlasmaVirtualDesktopManagementInterface::desktops() const
{
Q_D();
return d->desktops;
}
void PlasmaVirtualDesktopManagementInterface::sendDone()
{
Q_D();
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_management_send_done(*it);
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
d->send_done(resource->handle);
}
}
//// PlasmaVirtualDesktopInterface
#ifndef K_DOXYGEN
const struct org_kde_plasma_virtual_desktop_interface PlasmaVirtualDesktopInterface::Private::s_interface = {
requestActivateCallback
};
#endif
void PlasmaVirtualDesktopInterface::Private::requestActivateCallback(wl_client *client, wl_resource *resource)
void PlasmaVirtualDesktopInterfacePrivate::org_kde_plasma_virtual_desktop_request_activate(Resource *resource)
{
Q_UNUSED(client)
auto s = cast(resource);
emit s->q->activateRequested();
emit q->activateRequested();
}
PlasmaVirtualDesktopInterface::Private::Private(PlasmaVirtualDesktopInterface *q, PlasmaVirtualDesktopManagementInterface *c)
: q(q),
vdm(c)
PlasmaVirtualDesktopInterfacePrivate::PlasmaVirtualDesktopInterfacePrivate(PlasmaVirtualDesktopInterface *q, PlasmaVirtualDesktopManagementInterface *c)
: QtWaylandServer::org_kde_plasma_virtual_desktop()
, q(q)
, vdm(c)
{
}
PlasmaVirtualDesktopInterface::Private::~Private()
PlasmaVirtualDesktopInterfacePrivate::~PlasmaVirtualDesktopInterfacePrivate()
{
// need to copy, as destroy goes through the destroy listener and modifies the list as we iterate
const auto c = resources;
for (const auto &r : c) {
auto client = wl_resource_get_client(r);
org_kde_plasma_virtual_desktop_send_removed(r);
wl_resource_destroy(r);
wl_client_flush(client);
const auto clientResources = resourceMap();
for (Resource *resource : clientResources) {
send_removed(resource->handle);
wl_resource_destroy(resource->handle);
}
}
void PlasmaVirtualDesktopInterface::Private::unbind(wl_resource *resource)
void PlasmaVirtualDesktopInterfacePrivate::org_kde_plasma_virtual_desktop_bind_resource(Resource *resource)
{
Private *p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
p->resources.removeAll(resource);
}
send_desktop_id(resource->handle, id);
void PlasmaVirtualDesktopInterface::Private::createResource(wl_resource *parent, quint32 serial)
{
ClientConnection *c = vdm->display()->getConnection(wl_resource_get_client(parent));
wl_resource *resource = c->createResource(&org_kde_plasma_virtual_desktop_interface, wl_resource_get_version(parent), serial);
if (!resource) {
return;
}
wl_resource_set_implementation(resource, &s_interface, this, unbind);
resources << resource;
org_kde_plasma_virtual_desktop_send_desktop_id(resource, id.toUtf8().constData());
if (!name.isEmpty()) {
org_kde_plasma_virtual_desktop_send_name(resource, name.toUtf8().constData());
send_name(resource->handle, name);
}
if (active) {
org_kde_plasma_virtual_desktop_send_activated(resource);
send_activated(resource->handle);
}
c->flush();
}
PlasmaVirtualDesktopInterface::PlasmaVirtualDesktopInterface(PlasmaVirtualDesktopManagementInterface *parent)
: QObject(parent),
d(new Private(this, parent))
: QObject(),
d(new PlasmaVirtualDesktopInterfacePrivate(this, parent))
{
}
......@@ -354,8 +275,10 @@ void PlasmaVirtualDesktopInterface::setName(const QString &name)
}
d->name = name;
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_send_name(*it, name.toUtf8().constData());
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
d->send_name(resource->handle, name);
}
}
......@@ -371,13 +294,15 @@ void PlasmaVirtualDesktopInterface::setActive(bool active)
}
d->active = active;
const auto clientResources = d->resourceMap();
if (active) {
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_send_activated(*it);
for (auto resource : clientResources) {
d->send_activated(resource->handle);
}
} else {
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_send_deactivated(*it);
for (auto resource : clientResources) {
d->send_deactivated(resource->handle);
}
}
}
......@@ -389,8 +314,9 @@ bool PlasmaVirtualDesktopInterface::isActive() const
void PlasmaVirtualDesktopInterface::sendDone()
{
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_send_done(*it);
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
d->send_done(resource->handle);
}
}
......
......@@ -6,8 +6,7 @@
#ifndef KWAYLAND_SERVER_PLASMAVIRTUALDESKTOP_H
#define KWAYLAND_SERVER_PLASMAVIRTUALDESKTOP_H
#include "global.h"
#include "resource.h"
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
......@@ -16,6 +15,8 @@ namespace KWaylandServer
class Display;
class PlasmaVirtualDesktopInterface;
class PlasmaVirtualDesktopInterfacePrivate;
class PlasmaVirtualDesktopManagementInterfacePrivate;
/**
* @short Wrapper for the org_kde_plasma_virtual_desktop_management interface.
......@@ -23,11 +24,11 @@ class PlasmaVirtualDesktopInterface;
* This class provides a convenient wrapper for the org_kde_plasma_virtual_desktop_management interface.
* @since 5.52
*/
class KWAYLANDSERVER_EXPORT PlasmaVirtualDesktopManagementInterface : public Global
class KWAYLANDSERVER_EXPORT PlasmaVirtualDesktopManagementInterface : public QObject
{
Q_OBJECT
public:
virtual ~PlasmaVirtualDesktopManagementInterface();
~PlasmaVirtualDesktopManagementInterface() override;
/**
* Sets how many rows the virtual desktops should be laid into
......@@ -91,15 +92,14 @@ Q_SIGNALS:
private:
explicit PlasmaVirtualDesktopManagementInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
Private *d_func() const;
QScopedPointer<PlasmaVirtualDesktopManagementInterfacePrivate> d;
};
class KWAYLANDSERVER_EXPORT PlasmaVirtualDesktopInterface : public QObject
{
Q_OBJECT
public:
virtual ~PlasmaVirtualDesktopInterface();
~PlasmaVirtualDesktopInterface() override;
/**
* @returns the unique id for this desktop.
......@@ -145,9 +145,9 @@ Q_SIGNALS:
private:
explicit PlasmaVirtualDesktopInterface(PlasmaVirtualDesktopManagementInterface *parent);
friend class PlasmaVirtualDesktopManagementInterface;
friend class PlasmaVirtualDesktopManagementInterfacePrivate;
class Private;
const QScopedPointer<Private> d;
QScopedPointer<PlasmaVirtualDesktopInterfacePrivate> d;
};
}
......
Markdown is supported
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