1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2017 David Edmundson <kde@davidedmundson.co.uk> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #include "appmenu.h" |
7 | #include "event_queue.h" |
8 | #include "surface.h" |
9 | #include "wayland_pointer_p.h" |
10 | |
11 | #include <wayland-appmenu-client-protocol.h> |
12 | |
13 | namespace KWayland |
14 | { |
15 | namespace Client |
16 | { |
17 | class AppMenuManager::Private |
18 | { |
19 | public: |
20 | Private() = default; |
21 | |
22 | void setup(org_kde_kwin_appmenu_manager *arg); |
23 | |
24 | WaylandPointer<org_kde_kwin_appmenu_manager, org_kde_kwin_appmenu_manager_destroy> appmenumanager; |
25 | EventQueue *queue = nullptr; |
26 | }; |
27 | |
28 | AppMenuManager::AppMenuManager(QObject *parent) |
29 | : QObject(parent) |
30 | , d(new Private) |
31 | { |
32 | } |
33 | |
34 | void AppMenuManager::Private::setup(org_kde_kwin_appmenu_manager *arg) |
35 | { |
36 | Q_ASSERT(arg); |
37 | Q_ASSERT(!appmenumanager); |
38 | appmenumanager.setup(pointer: arg); |
39 | } |
40 | |
41 | AppMenuManager::~AppMenuManager() |
42 | { |
43 | release(); |
44 | } |
45 | |
46 | void AppMenuManager::setup(org_kde_kwin_appmenu_manager *appmenumanager) |
47 | { |
48 | d->setup(appmenumanager); |
49 | } |
50 | |
51 | void AppMenuManager::release() |
52 | { |
53 | d->appmenumanager.release(); |
54 | } |
55 | |
56 | void AppMenuManager::destroy() |
57 | { |
58 | d->appmenumanager.destroy(); |
59 | } |
60 | |
61 | AppMenuManager::operator org_kde_kwin_appmenu_manager *() |
62 | { |
63 | return d->appmenumanager; |
64 | } |
65 | |
66 | AppMenuManager::operator org_kde_kwin_appmenu_manager *() const |
67 | { |
68 | return d->appmenumanager; |
69 | } |
70 | |
71 | bool AppMenuManager::isValid() const |
72 | { |
73 | return d->appmenumanager.isValid(); |
74 | } |
75 | |
76 | void AppMenuManager::setEventQueue(EventQueue *queue) |
77 | { |
78 | d->queue = queue; |
79 | } |
80 | |
81 | EventQueue *AppMenuManager::eventQueue() |
82 | { |
83 | return d->queue; |
84 | } |
85 | |
86 | AppMenu *AppMenuManager::create(Surface *surface, QObject *parent) |
87 | { |
88 | Q_ASSERT(isValid()); |
89 | auto p = new AppMenu(parent); |
90 | auto w = org_kde_kwin_appmenu_manager_create(org_kde_kwin_appmenu_manager: d->appmenumanager, surface: *surface); |
91 | if (d->queue) { |
92 | d->queue->addProxy(proxy: w); |
93 | } |
94 | p->setup(w); |
95 | return p; |
96 | } |
97 | |
98 | class AppMenu::Private |
99 | { |
100 | public: |
101 | void setup(org_kde_kwin_appmenu *arg); |
102 | |
103 | WaylandPointer<org_kde_kwin_appmenu, org_kde_kwin_appmenu_release> appmenu; |
104 | }; |
105 | |
106 | AppMenu::AppMenu(QObject *parent) |
107 | : QObject(parent) |
108 | , d(new Private) |
109 | { |
110 | } |
111 | |
112 | void AppMenu::Private::setup(org_kde_kwin_appmenu *arg) |
113 | { |
114 | Q_ASSERT(arg); |
115 | Q_ASSERT(!appmenu); |
116 | appmenu.setup(pointer: arg); |
117 | } |
118 | |
119 | AppMenu::~AppMenu() |
120 | { |
121 | release(); |
122 | } |
123 | |
124 | void AppMenu::setup(org_kde_kwin_appmenu *appmenu) |
125 | { |
126 | d->setup(appmenu); |
127 | } |
128 | |
129 | void AppMenu::release() |
130 | { |
131 | d->appmenu.release(); |
132 | } |
133 | |
134 | void AppMenu::destroy() |
135 | { |
136 | d->appmenu.destroy(); |
137 | } |
138 | |
139 | AppMenu::operator org_kde_kwin_appmenu *() |
140 | { |
141 | return d->appmenu; |
142 | } |
143 | |
144 | AppMenu::operator org_kde_kwin_appmenu *() const |
145 | { |
146 | return d->appmenu; |
147 | } |
148 | |
149 | bool AppMenu::isValid() const |
150 | { |
151 | return d->appmenu.isValid(); |
152 | } |
153 | |
154 | void AppMenu::setAddress(const QString &serviceName, const QString &objectPath) |
155 | { |
156 | Q_ASSERT(isValid()); |
157 | org_kde_kwin_appmenu_set_address(org_kde_kwin_appmenu: d->appmenu, service_name: serviceName.toLatin1(), object_path: objectPath.toLatin1()); |
158 | } |
159 | |
160 | } |
161 | } |
162 | |
163 | #include "moc_appmenu.cpp" |
164 |