Commit b3534e7c authored by David Edmundson's avatar David Edmundson Committed by Vlad Zahorodnii
Browse files

Port AppMenu Interface to use autogenerated classes

Public API is identical except the now uneeded explit create on the
global.
parent c82b0db0
......@@ -108,8 +108,6 @@ void TestAppmenu::init()
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_appmenuManagerInterface = m_display->createAppMenuManagerInterface(m_display);
m_appmenuManagerInterface->create();
QVERIFY(m_appmenuManagerInterface->isValid());
QVERIFY(appmenuSpy.wait());
m_appmenuManager = registry.createAppMenuManager(appmenuSpy.first().first().value<quint32>(), appmenuSpy.first().last().value<quint32>(), this);
......
......@@ -183,7 +183,7 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME idle-inhibit-unstable-v1
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/appmenu.xml
BASENAME appmenu
)
......
......@@ -6,149 +6,104 @@
#include "appmenu_interface.h"
#include "display.h"
#include "surface_interface.h"
#include "global_p.h"
#include "resource_p.h"
#include "logging.h"
#include <QtGlobal>
#include <wayland-appmenu-server-protocol.h>
#include "qwayland-server-appmenu.h"
namespace KWaylandServer
{
class AppMenuManagerInterface::Private : public Global::Private
class AppMenuManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_appmenu_manager
{
public:
Private(AppMenuManagerInterface *q, Display *d);
AppMenuManagerInterfacePrivate(AppMenuManagerInterface *q, Display *d);
QVector<AppMenuInterface*> appmenus;
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 createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface);
AppMenuManagerInterface *q;
static const struct org_kde_kwin_appmenu_manager_interface s_interface;
static const quint32 s_version;
};
const quint32 AppMenuManagerInterface::Private::s_version = 1;
#ifndef K_DOXYGEN
const struct org_kde_kwin_appmenu_manager_interface AppMenuManagerInterface::Private::s_interface = {
createCallback
protected:
void org_kde_kwin_appmenu_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
};
#endif
void AppMenuManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
{
auto p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
Q_ASSERT(p);
const quint32 AppMenuManagerInterfacePrivate::s_version = 1;
void AppMenuManagerInterfacePrivate::org_kde_kwin_appmenu_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
{
SurfaceInterface *s = SurfaceInterface::get(surface);
if (!s) {
// TODO: send error?
qCWarning(KWAYLAND_SERVER) << "ServerSideDecorationInterface requested for non existing SurfaceInterface";
wl_resource_post_error(resource->handle, 0, "Invalid surface");
return;
}
auto appmenu = new AppMenuInterface(p->q, s, resource);
appmenu->create(p->display->getConnection(client), wl_resource_get_version(resource), id);
if (!appmenu->resource()) {
wl_resource_post_no_memory(resource);
delete appmenu;
wl_resource *appmenu_resource = wl_resource_create(resource->client(), &org_kde_kwin_appmenu_interface, resource->version(), id);
if (!appmenu_resource) {
wl_client_post_no_memory(resource->client());
return;
}
p->appmenus.append(appmenu);
QObject::connect(appmenu, &QObject::destroyed, p->q, [=]() {
p->appmenus.removeOne(appmenu);
auto appmenu = new AppMenuInterface(s, appmenu_resource);
appmenus.append(appmenu);
QObject::connect(appmenu, &QObject::destroyed, q, [=]() {
appmenus.removeOne(appmenu);
});
emit p->q->appMenuCreated(appmenu);
emit q->appMenuCreated(appmenu);
}
AppMenuManagerInterface::Private::Private(AppMenuManagerInterface *q, Display *d)
: Global::Private(d, &org_kde_kwin_appmenu_manager_interface, s_version)
, q(q)
AppMenuManagerInterfacePrivate::AppMenuManagerInterfacePrivate(AppMenuManagerInterface *_q, Display *d)
: QtWaylandServer::org_kde_kwin_appmenu_manager(*d, s_version)
, q(_q)
{
}
void AppMenuManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
class AppMenuInterfacePrivate : public QtWaylandServer::org_kde_kwin_appmenu
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&org_kde_kwin_appmenu_manager_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &s_interface, this, unbind);
}
public:
AppMenuInterfacePrivate(AppMenuInterface *q, SurfaceInterface *surface, wl_resource *resource);
AppMenuInterface *q;
QPointer<SurfaceInterface> surface;
AppMenuInterface::InterfaceAddress address;
protected:
void org_kde_kwin_appmenu_destroy_resource(Resource *resource) override;
void org_kde_kwin_appmenu_set_address(Resource *resource, const QString &service_name, const QString &object_path) override;
void org_kde_kwin_appmenu_release(Resource *resource) override;
};
void AppMenuManagerInterface::Private::unbind(wl_resource *resource)
AppMenuInterfacePrivate::AppMenuInterfacePrivate(AppMenuInterface *_q, SurfaceInterface *s, wl_resource *resource)
: QtWaylandServer::org_kde_kwin_appmenu(resource)
, q(_q)
, surface(s)
{
Q_UNUSED(resource)
}
class AppMenuInterface::Private : public Resource::Private
void AppMenuInterfacePrivate::org_kde_kwin_appmenu_destroy_resource(QtWaylandServer::org_kde_kwin_appmenu::Resource *resource)
{
public:
Private(AppMenuInterface *q, AppMenuManagerInterface *c, SurfaceInterface *surface, wl_resource *parentResource);
~Private();
SurfaceInterface *surface;
InterfaceAddress address;
private:
static void setAddressCallback(wl_client *client, wl_resource *resource, const char * service_name, const char * object_path);
AppMenuInterface *q_func() {
return reinterpret_cast<AppMenuInterface *>(q);
}
static AppMenuInterface *get(SurfaceInterface *s);
static const struct org_kde_kwin_appmenu_interface s_interface;
};
#ifndef K_DOXYGEN
const struct org_kde_kwin_appmenu_interface AppMenuInterface::Private::s_interface = {
setAddressCallback,
resourceDestroyedCallback
};
#endif
Q_UNUSED(resource)
delete q;
}
void AppMenuInterface::Private::setAddressCallback(wl_client *client, wl_resource *resource, const char * service_name, const char * object_path)
void AppMenuInterfacePrivate::org_kde_kwin_appmenu_set_address(Resource *resource, const QString &service_name, const QString &object_path)
{
Q_UNUSED(client);
auto p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
Q_ASSERT(p);
if (p->address.serviceName == QLatin1String(service_name) &&
p->address.objectPath == QLatin1String(object_path)) {
Q_UNUSED(resource)
if (address.serviceName == service_name &&
address.objectPath == object_path) {
return;
}
p->address.serviceName = QString::fromLatin1(service_name);
p->address.objectPath = QString::fromLatin1(object_path);
emit p->q_func()->addressChanged(p->address);
}
AppMenuInterface::Private::Private(AppMenuInterface *q, AppMenuManagerInterface *c, SurfaceInterface *s, wl_resource *parentResource)
: Resource::Private(q, c, parentResource, &org_kde_kwin_appmenu_interface, &s_interface),
surface(s)
{
address.serviceName = service_name;
address.objectPath = object_path;
emit q->addressChanged(address);
}
AppMenuInterface::Private::~Private()
void AppMenuInterfacePrivate::org_kde_kwin_appmenu_release(QtWaylandServer::org_kde_kwin_appmenu::Resource *resource)
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
}
wl_resource_destroy(resource->handle);
}
AppMenuManagerInterface::AppMenuManagerInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
: QObject(parent)
, d(new AppMenuManagerInterfacePrivate(this, display))
{
}
......@@ -156,14 +111,8 @@ AppMenuManagerInterface::~AppMenuManagerInterface()
{
}
AppMenuManagerInterface::Private *AppMenuManagerInterface::d_func() const
{
return reinterpret_cast<AppMenuManagerInterface::Private*>(d.data());
}
AppMenuInterface* AppMenuManagerInterface::appMenuForSurface(SurfaceInterface *surface)
{
Q_D();
for (AppMenuInterface* menu: d->appmenus) {
if (menu->surface() == surface) {
return menu;
......@@ -172,27 +121,21 @@ AppMenuInterface* AppMenuManagerInterface::appMenuForSurface(SurfaceInterface *s
return nullptr;
}
AppMenuInterface::AppMenuInterface(AppMenuManagerInterface *parent, SurfaceInterface *s, wl_resource *parentResource):
Resource(new Private(this, parent, s, parentResource))
{
}
AppMenuInterface::Private *AppMenuInterface::d_func() const
AppMenuInterface::AppMenuInterface(SurfaceInterface *surface, wl_resource *resource)
: QObject()
, d(new AppMenuInterfacePrivate(this, surface, resource))
{
return reinterpret_cast<AppMenuInterface::Private*>(d.data());
}
AppMenuInterface::~AppMenuInterface()
{}
AppMenuInterface::InterfaceAddress AppMenuInterface::address() const {
Q_D();
return d->address;
}
SurfaceInterface* AppMenuInterface::surface() const {
Q_D();
return d->surface;
return d->surface.data();
}
}//namespace
......@@ -6,10 +6,10 @@
#ifndef KWAYLAND_SERVER_APPMENU_INTERFACE_H
#define KWAYLAND_SERVER_APPMENU_INTERFACE_H
#include "global.h"
#include "resource.h"
#include <KWaylandServer/kwaylandserver_export.h>
#include <QObject>
struct wl_resource;
namespace KWaylandServer
{
......@@ -18,6 +18,9 @@ class Display;
class SurfaceInterface;
class AppMenuInterface;
class AppMenuManagerInterfacePrivate;
class AppMenuInterfacePrivate;
/**
* Provides the DBus service name and object path to a AppMenu DBus interface.
*
......@@ -25,11 +28,11 @@ class AppMenuInterface;
* and notifies when a new one is created
* @since 5.42
*/
class KWAYLANDSERVER_EXPORT AppMenuManagerInterface : public Global
class KWAYLANDSERVER_EXPORT AppMenuManagerInterface : public QObject
{
Q_OBJECT
public:
virtual ~AppMenuManagerInterface();
~AppMenuManagerInterface() override;
/**
* Returns any existing appMenu for a given surface
* This returns a null pointer if no AppMenuInterface exists.
......@@ -45,8 +48,7 @@ Q_SIGNALS:
private:
explicit AppMenuManagerInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
Private *d_func() const;
QScopedPointer<AppMenuManagerInterfacePrivate> d;
};
/**
......@@ -55,7 +57,7 @@ private:
* the AppMenu DBus interface is registered.
* @since 5.42
*/
class KWAYLANDSERVER_EXPORT AppMenuInterface : public Resource
class KWAYLANDSERVER_EXPORT AppMenuInterface : public QObject
{
Q_OBJECT
public:
......@@ -68,7 +70,7 @@ public:
/** Object path of the AppMenu interface*/
QString objectPath;
};
virtual ~AppMenuInterface();
~AppMenuInterface() override;
/**
* @returns the service name and object path or empty strings if unset
......@@ -87,11 +89,11 @@ Q_SIGNALS:
void addressChanged(KWaylandServer::AppMenuInterface::InterfaceAddress);
private:
explicit AppMenuInterface(AppMenuManagerInterface *parent, SurfaceInterface *s, wl_resource *parentResource);
friend class AppMenuManagerInterface;
explicit AppMenuInterface(SurfaceInterface *s, wl_resource *resource);
friend class AppMenuManagerInterfacePrivate;
QScopedPointer<AppMenuInterfacePrivate> d;
class Private;
Private *d_func() const;
};
}
......
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