KWaylandServer

appmenu_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "appmenu_interface.h"
7 #include "display.h"
8 #include "surface_interface.h"
9 
10 #include <QtGlobal>
11 
12 #include "qwayland-server-appmenu.h"
13 
14 namespace KWaylandServer
15 {
16 static const quint32 s_version = 1;
17 
18 class AppMenuManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_appmenu_manager
19 {
20 public:
21  AppMenuManagerInterfacePrivate(AppMenuManagerInterface *q, Display *d);
22 
24  AppMenuManagerInterface *q;
25 
26 protected:
27  void org_kde_kwin_appmenu_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
28 };
29 
30 void AppMenuManagerInterfacePrivate::org_kde_kwin_appmenu_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
31 {
32  SurfaceInterface *s = SurfaceInterface::get(surface);
33  if (!s) {
34  wl_resource_post_error(resource->handle, 0, "Invalid surface");
35  return;
36  }
37  wl_resource *appmenu_resource = wl_resource_create(resource->client(), &org_kde_kwin_appmenu_interface, resource->version(), id);
38  if (!appmenu_resource) {
39  wl_client_post_no_memory(resource->client());
40  return;
41  }
42  auto appmenu = new AppMenuInterface(s, appmenu_resource);
43 
44  appmenus.append(appmenu);
45  QObject::connect(appmenu, &QObject::destroyed, q, [=]() {
46  appmenus.removeOne(appmenu);
47  });
48  Q_EMIT q->appMenuCreated(appmenu);
49 }
50 
51 AppMenuManagerInterfacePrivate::AppMenuManagerInterfacePrivate(AppMenuManagerInterface *_q, Display *d)
52  : QtWaylandServer::org_kde_kwin_appmenu_manager(*d, s_version)
53  , q(_q)
54 {
55 }
56 
57 class AppMenuInterfacePrivate : public QtWaylandServer::org_kde_kwin_appmenu
58 {
59 public:
60  AppMenuInterfacePrivate(AppMenuInterface *q, SurfaceInterface *surface, wl_resource *resource);
61 
62  AppMenuInterface *q;
64  AppMenuInterface::InterfaceAddress address;
65 
66 protected:
67  void org_kde_kwin_appmenu_destroy_resource(Resource *resource) override;
68  void org_kde_kwin_appmenu_set_address(Resource *resource, const QString &service_name, const QString &object_path) override;
69  void org_kde_kwin_appmenu_release(Resource *resource) override;
70 };
71 
72 AppMenuInterfacePrivate::AppMenuInterfacePrivate(AppMenuInterface *_q, SurfaceInterface *s, wl_resource *resource)
73  : QtWaylandServer::org_kde_kwin_appmenu(resource)
74  , q(_q)
75  , surface(s)
76 {
77 }
78 
79 void AppMenuInterfacePrivate::org_kde_kwin_appmenu_destroy_resource(QtWaylandServer::org_kde_kwin_appmenu::Resource *resource)
80 {
81  Q_UNUSED(resource)
82  delete q;
83 }
84 
85 void AppMenuInterfacePrivate::org_kde_kwin_appmenu_set_address(Resource *resource, const QString &service_name, const QString &object_path)
86 {
87  Q_UNUSED(resource)
88  if (address.serviceName == service_name && address.objectPath == object_path) {
89  return;
90  }
91 
92  address.serviceName = service_name;
93  address.objectPath = object_path;
94  Q_EMIT q->addressChanged(address);
95 }
96 
97 void AppMenuInterfacePrivate::org_kde_kwin_appmenu_release(QtWaylandServer::org_kde_kwin_appmenu::Resource *resource)
98 {
99  wl_resource_destroy(resource->handle);
100 }
101 
102 AppMenuManagerInterface::AppMenuManagerInterface(Display *display, QObject *parent)
103  : QObject(parent)
104  , d(new AppMenuManagerInterfacePrivate(this, display))
105 {
106 }
107 
108 AppMenuManagerInterface::~AppMenuManagerInterface()
109 {
110 }
111 
113 {
114  for (AppMenuInterface *menu : d->appmenus) {
115  if (menu->surface() == surface) {
116  return menu;
117  }
118  }
119  return nullptr;
120 }
121 
122 AppMenuInterface::AppMenuInterface(SurfaceInterface *surface, wl_resource *resource)
123  : QObject()
124  , d(new AppMenuInterfacePrivate(this, surface, resource))
125 {
126 }
127 
128 AppMenuInterface::~AppMenuInterface()
129 {
130 }
131 
133 {
134  return d->address;
135 }
136 
138 {
139  return d->surface.data();
140 }
141 
142 } // namespace
Structure containing DBus service name and path.
PostalAddress address(const QVariant &location)
static SurfaceInterface * get(wl_resource *native)
AppMenuInterface * appMenuForSurface(SurfaceInterface *)
Returns any existing appMenu for a given surface This returns a null pointer if no AppMenuInterface e...
SurfaceInterface * surface() const
Provides the DBus service name and object path to a AppMenu DBus interface.
QObject(QObject *parent)
Resource representing a wl_surface.
InterfaceAddress address() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void destroyed(QObject *obj)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 23:10:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.