GCC Code Coverage Report


Directory: ./
File: src/client/xdgdecoration.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 88 100 88.0%
Branches: 19 35 54.3%

Line Branch Exec Source
1 /****************************************************************************
2 Copyright 2018 David Edmundson <kde@davidedmundson.co.uk>
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 "xdgdecoration.h"
21
22 #include "event_queue.h"
23 #include "wayland_pointer_p.h"
24 #include "xdg_shell_toplevel.h"
25
26 #include <QDebug>
27
28 #include "wayland-xdg-decoration-unstable-v1-client-protocol.h"
29
30 namespace Wrapland
31 {
32 namespace Client
33 {
34
35 class Q_DECL_HIDDEN XdgDecorationManager::Private
36 {
37 public:
38 10 Private() = default;
39
40 void setup(zxdg_decoration_manager_v1* arg);
41
42 WaylandPointer<zxdg_decoration_manager_v1, zxdg_decoration_manager_v1_destroy>
43 xdgdecorationmanager;
44 5 EventQueue* queue = nullptr;
45 };
46
47 5 XdgDecorationManager::XdgDecorationManager(QObject* parent)
48 5 : QObject(parent)
49
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 , d(new Private)
50 5 {
51 5 }
52
53 5 void XdgDecorationManager::Private::setup(zxdg_decoration_manager_v1* arg)
54 {
55
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Q_ASSERT(arg);
56
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Q_ASSERT(!xdgdecorationmanager);
57 5 xdgdecorationmanager.setup(arg);
58 5 }
59
60 10 XdgDecorationManager::~XdgDecorationManager()
61 10 {
62
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 release();
63 10 }
64
65 5 void XdgDecorationManager::setup(zxdg_decoration_manager_v1* xdgdecorationmanager)
66 {
67 5 d->setup(xdgdecorationmanager);
68 5 }
69
70 5 void XdgDecorationManager::release()
71 {
72 5 d->xdgdecorationmanager.release();
73 5 }
74
75 XdgDecorationManager::operator zxdg_decoration_manager_v1*()
76 {
77 return d->xdgdecorationmanager;
78 }
79
80 XdgDecorationManager::operator zxdg_decoration_manager_v1*() const
81 {
82 return d->xdgdecorationmanager;
83 }
84
85 4 bool XdgDecorationManager::isValid() const
86 {
87 4 return d->xdgdecorationmanager.isValid();
88 }
89
90 5 void XdgDecorationManager::setEventQueue(EventQueue* queue)
91 {
92 5 d->queue = queue;
93 5 }
94
95 EventQueue* XdgDecorationManager::eventQueue()
96 {
97 return d->queue;
98 }
99
100 4 XdgDecoration* XdgDecorationManager::getToplevelDecoration(XdgShellToplevel* toplevel,
101 QObject* parent)
102 {
103
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(isValid());
104 4 xdg_toplevel* toplevel_resource = *toplevel;
105
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto p = new XdgDecoration(parent);
106 8 auto w = zxdg_decoration_manager_v1_get_toplevel_decoration(d->xdgdecorationmanager,
107 4 toplevel_resource);
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (d->queue) {
109 4 d->queue->addProxy(w);
110 4 }
111 4 p->setup(w);
112 4 return p;
113 }
114
115 class Q_DECL_HIDDEN XdgDecoration::Private
116 {
117 public:
118 Private(XdgDecoration* q);
119
120 void setup(zxdg_toplevel_decoration_v1* arg);
121
122 WaylandPointer<zxdg_toplevel_decoration_v1, zxdg_toplevel_decoration_v1_destroy> xdgdecoration;
123
124 4 XdgDecoration::Mode m_mode = XdgDecoration::Mode::ClientSide;
125
126 private:
127 XdgDecoration* q;
128
129 private:
130 static void configureCallback(void* data,
131 zxdg_toplevel_decoration_v1* zxdg_toplevel_decoration_v1,
132 uint32_t mode);
133
134 static const zxdg_toplevel_decoration_v1_listener s_listener;
135 };
136
137 const zxdg_toplevel_decoration_v1_listener XdgDecoration::Private::s_listener = {
138 configureCallback,
139 };
140
141 4 void XdgDecoration::Private::configureCallback(
142 void* data,
143 zxdg_toplevel_decoration_v1* zxdg_toplevel_decoration_v1,
144 uint32_t m)
145 {
146 4 auto p = reinterpret_cast<XdgDecoration::Private*>(data);
147
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->xdgdecoration == zxdg_toplevel_decoration_v1);
148
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
4 switch (m) {
149 case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE:
150 2 p->m_mode = XdgDecoration::Mode::ClientSide;
151 2 break;
152 case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE:
153 2 p->m_mode = XdgDecoration::Mode::ServerSide;
154 2 break;
155 }
156 4 Q_EMIT p->q->modeChanged(p->m_mode);
157 4 }
158
159 4 XdgDecoration::Private::Private(XdgDecoration* q)
160 4 : q(q)
161 {
162 4 }
163
164 4 XdgDecoration::XdgDecoration(QObject* parent)
165 4 : QObject(parent)
166
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 , d(new Private(this))
167 4 {
168 4 }
169
170 4 void XdgDecoration::Private::setup(zxdg_toplevel_decoration_v1* arg)
171 {
172
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(arg);
173
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(!xdgdecoration);
174 4 xdgdecoration.setup(arg);
175 4 zxdg_toplevel_decoration_v1_add_listener(xdgdecoration, &s_listener, this);
176 4 }
177
178 8 XdgDecoration::~XdgDecoration()
179 8 {
180
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 release();
181 8 }
182
183 4 void XdgDecoration::setup(zxdg_toplevel_decoration_v1* xdgdecoration)
184 {
185 4 d->setup(xdgdecoration);
186 4 }
187
188 4 void XdgDecoration::release()
189 {
190 4 d->xdgdecoration.release();
191 4 }
192
193 XdgDecoration::operator zxdg_toplevel_decoration_v1*()
194 {
195 return d->xdgdecoration;
196 }
197
198 XdgDecoration::operator zxdg_toplevel_decoration_v1*() const
199 {
200 return d->xdgdecoration;
201 }
202
203 8 bool XdgDecoration::isValid() const
204 {
205 8 return d->xdgdecoration.isValid();
206 }
207
208 4 void XdgDecoration::setMode(XdgDecoration::Mode mode)
209 {
210
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(isValid());
211 uint32_t mode_raw;
212
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 switch (mode) {
213 case XdgDecoration::Mode::ClientSide:
214 2 mode_raw = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
215 2 break;
216 default:
217 2 mode_raw = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
218 2 break;
219 }
220 4 zxdg_toplevel_decoration_v1_set_mode(d->xdgdecoration, mode_raw);
221 4 }
222
223 4 void XdgDecoration::unsetMode()
224 {
225
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(isValid());
226 4 zxdg_toplevel_decoration_v1_unset_mode(d->xdgdecoration);
227 4 }
228
229 XdgDecoration::Mode XdgDecoration::mode() const
230 {
231 return d->m_mode;
232 }
233
234 }
235 }
236