Changeset View
Changeset View
Standalone View
Standalone View
src/server/xdgshell_interface.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | XdgShellInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellInterface *q, Display *d, const wl_interface *interface, quint32 version) | 27 | XdgShellInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellInterface *q, Display *d, const wl_interface *interface, quint32 version) | ||
28 | : Global::Private(d, interface, version) | 28 | : Global::Private(d, interface, version) | ||
29 | , interfaceVersion(interfaceVersion) | 29 | , interfaceVersion(interfaceVersion) | ||
30 | , q(q) | 30 | , q(q) | ||
31 | { | 31 | { | ||
32 | } | 32 | } | ||
33 | 33 | | |||
34 | void XdgShellInterface::Private::setupTimer(quint32 serial) | ||||
35 | { | ||||
36 | QTimer *pingTimer = new QTimer(); | ||||
37 | pingTimer->setSingleShot(false); | ||||
38 | pingTimer->setInterval(1000); | ||||
39 | int attempt = 0; | ||||
40 | connect(pingTimer, &QTimer::timeout, q, [this, serial, attempt]() mutable { | ||||
graesslin: what's the idea behind a mutable lambda? | |||||
the captured "attempt" variable is modified inside the lambda davidedmundson: the captured "attempt" variable is modified inside the lambda | |||||
needs to tack the state as needs to track that only a couple of attempts are made mart: needs to tack the state as needs to track that only a couple of attempts are made | |||||
41 | ++attempt; | ||||
42 | if (attempt == 1) { | ||||
43 | emit q->pingDelayed(serial); | ||||
44 | } else { | ||||
45 | emit q->pingTimeout(serial); | ||||
46 | auto timerIt = pingTimers.find(serial); | ||||
47 | if (timerIt != pingTimers.end()) { | ||||
48 | delete timerIt.value(); | ||||
49 | pingTimers.erase(timerIt); | ||||
50 | } | ||||
51 | } | ||||
52 | }); | ||||
53 | | ||||
54 | pingTimers.insert(serial, pingTimer); | ||||
55 | pingTimer->start(); | ||||
56 | } | ||||
57 | | ||||
34 | XdgShellInterface::XdgShellInterface(Private *d, QObject *parent) | 58 | XdgShellInterface::XdgShellInterface(Private *d, QObject *parent) | ||
35 | : Global(d, parent) | 59 | : Global(d, parent) | ||
36 | { | 60 | { | ||
37 | } | 61 | } | ||
38 | 62 | | |||
39 | XdgShellInterface::~XdgShellInterface() = default; | 63 | XdgShellInterface::~XdgShellInterface() = default; | ||
40 | 64 | | |||
41 | XdgShellSurfaceInterface *XdgShellInterface::getSurface(wl_resource *native) | 65 | XdgShellSurfaceInterface *XdgShellInterface::getSurface(wl_resource *native) | ||
42 | { | 66 | { | ||
43 | Q_UNUSED(native) | 67 | Q_UNUSED(native) | ||
44 | return nullptr; | 68 | return nullptr; | ||
45 | } | 69 | } | ||
46 | 70 | | |||
47 | XdgShellInterfaceVersion XdgShellInterface::interfaceVersion() const | 71 | XdgShellInterfaceVersion XdgShellInterface::interfaceVersion() const | ||
48 | { | 72 | { | ||
49 | Q_D(); | 73 | Q_D(); | ||
50 | return d->interfaceVersion; | 74 | return d->interfaceVersion; | ||
51 | } | 75 | } | ||
52 | 76 | | |||
77 | quint32 XdgShellInterface::ping() | ||||
78 | { | ||||
79 | return d_func()->ping(); | ||||
80 | } | ||||
81 | | ||||
53 | XdgShellInterface::Private *XdgShellInterface::d_func() const | 82 | XdgShellInterface::Private *XdgShellInterface::d_func() const | ||
54 | { | 83 | { | ||
55 | return reinterpret_cast<Private*>(d.data()); | 84 | return reinterpret_cast<Private*>(d.data()); | ||
56 | } | 85 | } | ||
57 | 86 | | |||
58 | XdgShellSurfaceInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellSurfaceInterface *q, XdgShellInterface *c, SurfaceInterface *surface, wl_resource *parentResource, const wl_interface *interface, const void *implementation) | 87 | XdgShellSurfaceInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellSurfaceInterface *q, Global *c, SurfaceInterface *surface, wl_resource *parentResource, const wl_interface *interface, const void *implementation) | ||
59 | : Resource::Private(q, c, parentResource, interface, implementation) | 88 | : Resource::Private(q, c, parentResource, interface, implementation) | ||
60 | , GenericShellSurface<XdgShellSurfaceInterface>(q, surface) | 89 | , GenericShellSurface<XdgShellSurfaceInterface>(q, surface) | ||
61 | , interfaceVersion(interfaceVersion) | 90 | , interfaceVersion(interfaceVersion) | ||
62 | { | 91 | { | ||
63 | } | 92 | } | ||
64 | 93 | | |||
65 | XdgShellSurfaceInterface::Private::~Private() = default; | 94 | XdgShellSurfaceInterface::Private::~Private() = default; | ||
66 | 95 | | |||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
153 | } | 182 | } | ||
154 | 183 | | |||
155 | QPointer<SurfaceInterface> XdgShellPopupInterface::transientFor() const | 184 | QPointer<SurfaceInterface> XdgShellPopupInterface::transientFor() const | ||
156 | { | 185 | { | ||
157 | Q_D(); | 186 | Q_D(); | ||
158 | return d->parent; | 187 | return d->parent; | ||
159 | } | 188 | } | ||
160 | 189 | | |||
190 | QSize XdgShellPopupInterface::initialSize() const | ||||
191 | { | ||||
192 | Q_D(); | ||||
193 | return d->initialSize; | ||||
194 | } | ||||
195 | | ||||
161 | QPoint XdgShellPopupInterface::transientOffset() const | 196 | QPoint XdgShellPopupInterface::transientOffset() const | ||
162 | { | 197 | { | ||
198 | QRect rect = anchorRect(); | ||||
199 | const QPoint center = rect.isEmpty() ? rect.topLeft() : rect.center(); | ||||
200 | rect = rect.adjusted(0,0,1,1); //compensate for the stupid QRect::right +1 fiasco | ||||
201 | | ||||
202 | switch(anchorEdge()) { | ||||
203 | case Qt::TopEdge | Qt::LeftEdge: | ||||
204 | return rect.topLeft(); | ||||
205 | case Qt::TopEdge: | ||||
206 | return QPoint(center.x(), rect.y()); | ||||
207 | case Qt::TopEdge | Qt::RightEdge: | ||||
208 | return rect.topRight(); | ||||
209 | case Qt::RightEdge: | ||||
210 | return QPoint(rect.right(), center.y()); | ||||
211 | case Qt::BottomEdge | Qt::RightEdge: | ||||
212 | return rect.bottomRight(); | ||||
213 | case Qt::BottomEdge: | ||||
214 | return QPoint(center.x(), rect.bottom()); | ||||
215 | case Qt::BottomEdge | Qt::LeftEdge: | ||||
216 | return rect.bottomLeft(); | ||||
217 | case Qt::LeftEdge: | ||||
218 | return QPoint(rect.left(), center.y()); | ||||
219 | default: | ||||
220 | return center; | ||||
221 | } | ||||
222 | Q_UNREACHABLE(); | ||||
223 | } | ||||
224 | | ||||
225 | QRect XdgShellPopupInterface::anchorRect() const | ||||
226 | { | ||||
227 | Q_D(); | ||||
228 | return d->anchorRect; | ||||
229 | } | ||||
230 | | ||||
231 | Qt::Edges XdgShellPopupInterface::anchorEdge() const | ||||
232 | { | ||||
233 | Q_D(); | ||||
234 | return d->anchorEdge; | ||||
235 | } | ||||
236 | | ||||
237 | Qt::Edges XdgShellPopupInterface::gravity() const | ||||
238 | { | ||||
163 | Q_D(); | 239 | Q_D(); | ||
164 | return d->transientOffset; | 240 | return d->gravity; | ||
241 | } | ||||
242 | | ||||
243 | QPoint XdgShellPopupInterface::anchorOffset() const | ||||
244 | { | ||||
245 | Q_D(); | ||||
246 | return d->anchorOffset; | ||||
247 | } | ||||
248 | | ||||
249 | PositionerConstraints XdgShellPopupInterface::constraintAdjustments() const | ||||
250 | { | ||||
251 | Q_D(); | ||||
252 | return d->constraintAdjustments; | ||||
165 | } | 253 | } | ||
166 | 254 | | |||
167 | void XdgShellPopupInterface::popupDone() | 255 | void XdgShellPopupInterface::popupDone() | ||
168 | { | 256 | { | ||
169 | Q_D(); | 257 | Q_D(); | ||
170 | return d->popupDone(); | 258 | return d->popupDone(); | ||
171 | } | 259 | } | ||
172 | 260 | | |||
261 | quint32 XdgShellPopupInterface::configure(const QRect &rect) | ||||
262 | { | ||||
263 | Q_D(); | ||||
264 | return d->configure(rect); | ||||
265 | } | ||||
266 | | ||||
173 | XdgShellPopupInterface::Private *XdgShellPopupInterface::d_func() const | 267 | XdgShellPopupInterface::Private *XdgShellPopupInterface::d_func() const | ||
174 | { | 268 | { | ||
175 | return reinterpret_cast<Private*>(d.data()); | 269 | return reinterpret_cast<Private*>(d.data()); | ||
176 | } | 270 | } | ||
177 | 271 | | |||
178 | } | 272 | } | ||
179 | } | 273 | } |
what's the idea behind a mutable lambda?