GCC Code Coverage Report


Directory: ./
File: src/client/plasmashell.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 163 180 90.6%
Branches: 46 70 65.7%

Line Branch Exec Source
1 /********************************************************************
2 Copyright 2015 Martin Gräßlin <mgraesslin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #include "plasmashell.h"
21 #include "event_queue.h"
22 #include "output.h"
23 #include "surface.h"
24 #include "wayland_pointer_p.h"
25 // Wayland
26 #include <wayland-plasma-shell-client-protocol.h>
27
28 namespace Wrapland
29 {
30 namespace Client
31 {
32
33 20 class Q_DECL_HIDDEN PlasmaShell::Private
34 {
35 public:
36 WaylandPointer<org_kde_plasma_shell, org_kde_plasma_shell_destroy> shell;
37 20 EventQueue* queue = nullptr;
38 };
39
40 class Q_DECL_HIDDEN PlasmaShellSurface::Private
41 {
42 public:
43 Private(PlasmaShellSurface* q);
44 ~Private();
45 void setup(org_kde_plasma_surface* surface);
46
47 WaylandPointer<org_kde_plasma_surface, org_kde_plasma_surface_destroy> surface;
48 QSize size;
49 QPointer<Surface> parentSurface;
50 PlasmaShellSurface::Role role;
51
52 static PlasmaShellSurface* get(Surface* surface);
53
54 private:
55 static void autoHidingPanelHiddenCallback(void* data,
56 org_kde_plasma_surface* org_kde_plasma_surface);
57 static void autoHidingPanelShownCallback(void* data,
58 org_kde_plasma_surface* org_kde_plasma_surface);
59
60 PlasmaShellSurface* q;
61 static QVector<Private*> s_surfaces;
62 static const org_kde_plasma_surface_listener s_listener;
63 };
64
65 QVector<PlasmaShellSurface::Private*> PlasmaShellSurface::Private::s_surfaces;
66
67 20 PlasmaShell::PlasmaShell(QObject* parent)
68 20 : QObject(parent)
69
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 , d(new Private)
70 20 {
71 20 }
72
73 40 PlasmaShell::~PlasmaShell()
74 40 {
75
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 release();
76 40 }
77
78 22 void PlasmaShell::release()
79 {
80
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 if (!d->shell) {
81 2 return;
82 }
83 20 Q_EMIT interfaceAboutToBeReleased();
84 20 d->shell.release();
85 22 }
86
87 20 void PlasmaShell::setup(org_kde_plasma_shell* shell)
88 {
89
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 Q_ASSERT(!d->shell);
90
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 Q_ASSERT(shell);
91 20 d->shell.setup(shell);
92 20 }
93
94 20 void PlasmaShell::setEventQueue(EventQueue* queue)
95 {
96 20 d->queue = queue;
97 20 }
98
99 EventQueue* PlasmaShell::eventQueue()
100 {
101 return d->queue;
102 }
103
104 127 PlasmaShellSurface* PlasmaShell::createSurface(wl_surface* surface, QObject* parent)
105 {
106
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 Q_ASSERT(isValid());
107 127 auto kwS = Surface::get(surface);
108
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 125 times.
127 if (kwS) {
109
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 118 times.
125 if (auto s = PlasmaShellSurface::Private::get(kwS)) {
110 7 return s;
111 }
112 118 }
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 PlasmaShellSurface* s = new PlasmaShellSurface(parent);
114 120 connect(this, &PlasmaShell::interfaceAboutToBeReleased, s, &PlasmaShellSurface::release);
115 120 auto w = org_kde_plasma_shell_get_surface(d->shell, surface);
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 if (d->queue) {
117 120 d->queue->addProxy(w);
118 120 }
119 120 s->setup(w);
120 120 s->d->parentSurface = QPointer<Surface>(kwS);
121 120 return s;
122 127 }
123
124 125 PlasmaShellSurface* PlasmaShell::createSurface(Surface* surface, QObject* parent)
125 {
126 125 return createSurface(*surface, parent);
127 }
128
129 127 bool PlasmaShell::isValid() const
130 {
131 127 return d->shell.isValid();
132 }
133
134 PlasmaShell::operator org_kde_plasma_shell*()
135 {
136 return d->shell;
137 }
138
139 PlasmaShell::operator org_kde_plasma_shell*() const
140 {
141 return d->shell;
142 }
143
144 120 PlasmaShellSurface::Private::Private(PlasmaShellSurface* q)
145 120 : role(PlasmaShellSurface::Role::Normal)
146 120 , q(q)
147 {
148
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 s_surfaces << this;
149 120 }
150
151 120 PlasmaShellSurface::Private::~Private()
152 {
153
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 s_surfaces.removeAll(this);
154 120 }
155
156 139 PlasmaShellSurface* PlasmaShellSurface::Private::get(Surface* surface)
157 {
158
1/2
✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
139 if (!surface) {
159 return nullptr;
160 }
161
2/2
✓ Branch 0 taken 5064 times.
✓ Branch 1 taken 125 times.
5189 for (auto it = s_surfaces.constBegin(); it != s_surfaces.constEnd(); ++it) {
162
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 5050 times.
5064 if ((*it)->parentSurface == surface) {
163 14 return (*it)->q;
164 }
165 5050 }
166 125 return nullptr;
167 139 }
168
169 120 void PlasmaShellSurface::Private::setup(org_kde_plasma_surface* s)
170 {
171
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 Q_ASSERT(s);
172
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 Q_ASSERT(!surface);
173 120 surface.setup(s);
174 120 org_kde_plasma_surface_add_listener(surface, &s_listener, this);
175 120 }
176
177 const org_kde_plasma_surface_listener PlasmaShellSurface::Private::s_listener = {
178 autoHidingPanelHiddenCallback,
179 autoHidingPanelShownCallback,
180 };
181
182 1 void PlasmaShellSurface::Private::autoHidingPanelHiddenCallback(
183 void* data,
184 org_kde_plasma_surface* org_kde_plasma_surface)
185 {
186 1 auto p = reinterpret_cast<PlasmaShellSurface::Private*>(data);
187
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Q_ASSERT(p->surface == org_kde_plasma_surface);
188 1 Q_EMIT p->q->autoHidePanelHidden();
189 1 }
190
191 1 void PlasmaShellSurface::Private::autoHidingPanelShownCallback(
192 void* data,
193 org_kde_plasma_surface* org_kde_plasma_surface)
194 {
195 1 auto p = reinterpret_cast<PlasmaShellSurface::Private*>(data);
196
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Q_ASSERT(p->surface == org_kde_plasma_surface);
197 1 Q_EMIT p->q->autoHidePanelShown();
198 1 }
199
200 120 PlasmaShellSurface::PlasmaShellSurface(QObject* parent)
201 120 : QObject(parent)
202
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
120 , d(new Private(this))
203 120 {
204 120 }
205
206 240 PlasmaShellSurface::~PlasmaShellSurface()
207 240 {
208
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 release();
209 240 }
210
211 223 void PlasmaShellSurface::release()
212 {
213 223 d->surface.release();
214 223 }
215
216 120 void PlasmaShellSurface::setup(org_kde_plasma_surface* surface)
217 {
218 120 d->setup(surface);
219 120 }
220
221 14 PlasmaShellSurface* PlasmaShellSurface::get(Surface* surface)
222 {
223
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 if (auto s = PlasmaShellSurface::Private::get(surface)) {
224 7 return s;
225 }
226
227 7 return nullptr;
228 14 }
229
230 40 bool PlasmaShellSurface::isValid() const
231 {
232 40 return d->surface.isValid();
233 }
234
235 PlasmaShellSurface::operator org_kde_plasma_surface*()
236 {
237 return d->surface;
238 }
239
240 PlasmaShellSurface::operator org_kde_plasma_surface*() const
241 {
242 return d->surface;
243 }
244
245 3 void PlasmaShellSurface::setPosition(QPoint const& point)
246 {
247
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(isValid());
248 3 org_kde_plasma_surface_set_position(d->surface, point.x(), point.y());
249 3 }
250
251 26 void PlasmaShellSurface::setRole(PlasmaShellSurface::Role role)
252 {
253
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 Q_ASSERT(isValid());
254 26 uint32_t wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL;
255
8/9
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 2 times.
26 switch (role) {
256 case Role::Normal:
257 7 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL;
258 7 break;
259 case Role::Desktop:
260 2 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_DESKTOP;
261 2 break;
262 case Role::Panel:
263 7 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_PANEL;
264 7 break;
265 case Role::OnScreenDisplay:
266 2 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_ONSCREENDISPLAY;
267 2 break;
268 case Role::Notification:
269 2 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION;
270 2 break;
271 case Role::ToolTip:
272 2 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_TOOLTIP;
273 2 break;
274 case Role::CriticalNotification:
275
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
4 if (wl_proxy_get_version(d->surface)
276 2 < ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION_SINCE_VERSION) {
277 // Fall back to generic notification type if not supported
278 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION;
279 } else {
280 2 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION;
281 }
282 2 break;
283 case Role::AppletPopup:
284 2 wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_APPLETPOPUP;
285 2 break;
286 default:
287 Q_UNREACHABLE();
288 break;
289 }
290 26 org_kde_plasma_surface_set_role(d->surface, wlRole);
291 26 d->role = role;
292 26 }
293
294 21 PlasmaShellSurface::Role PlasmaShellSurface::role() const
295 {
296 21 return d->role;
297 }
298
299 11 void PlasmaShellSurface::setPanelBehavior(PlasmaShellSurface::PanelBehavior behavior)
300 {
301
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 Q_ASSERT(isValid());
302 11 uint32_t wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE;
303
4/5
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
11 switch (behavior) {
304 case PanelBehavior::AlwaysVisible:
305 4 wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE;
306 4 break;
307 case PanelBehavior::AutoHide:
308 3 wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_AUTO_HIDE;
309 3 break;
310 case PanelBehavior::WindowsCanCover:
311 2 wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_CAN_COVER;
312 2 break;
313 case PanelBehavior::WindowsGoBelow:
314 2 wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_GO_BELOW;
315 2 break;
316 default:
317 Q_UNREACHABLE();
318 break;
319 }
320 11 org_kde_plasma_surface_set_panel_behavior(d->surface, wlRole);
321 11 }
322
323 3 void PlasmaShellSurface::setSkipTaskbar(bool skip)
324 {
325 3 org_kde_plasma_surface_set_skip_taskbar(d->surface, skip);
326 3 }
327
328 3 void PlasmaShellSurface::setSkipSwitcher(bool skip)
329 {
330 3 org_kde_plasma_surface_set_skip_switcher(d->surface, skip);
331 3 }
332
333 2 void PlasmaShellSurface::requestHideAutoHidingPanel()
334 {
335 2 org_kde_plasma_surface_panel_auto_hide_hide(d->surface);
336 2 }
337
338 1 void PlasmaShellSurface::requestShowAutoHidingPanel()
339 {
340 1 org_kde_plasma_surface_panel_auto_hide_show(d->surface);
341 1 }
342
343 2 void PlasmaShellSurface::setPanelTakesFocus(bool takesFocus)
344 {
345 2 org_kde_plasma_surface_set_panel_takes_focus(d->surface, takesFocus);
346 2 }
347
348 1 void PlasmaShellSurface::request_open_under_cursor()
349 {
350 1 org_kde_plasma_surface_open_under_cursor(d->surface);
351 1 }
352
353 }
354 }
355