KWayland

xdgshell_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "xdgshell_interface_p.h"
7 
8 namespace KWayland
9 {
10 namespace Server
11 {
12 XdgShellInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellInterface *q, Display *d, const wl_interface *interface, quint32 version)
13  : Global::Private(d, interface, version)
14  , interfaceVersion(interfaceVersion)
15  , q(q)
16 {
17 }
18 
19 void XdgShellInterface::Private::setupTimer(quint32 serial)
20 {
21  QTimer *pingTimer = new QTimer();
22  pingTimer->setSingleShot(false);
23  pingTimer->setInterval(1000);
24  int attempt = 0;
25  connect(pingTimer, &QTimer::timeout, q, [this, serial, attempt]() mutable {
26  ++attempt;
27  if (attempt == 1) {
28  Q_EMIT q->pingDelayed(serial);
29  } else {
30  Q_EMIT q->pingTimeout(serial);
31  auto timerIt = pingTimers.find(serial);
32  if (timerIt != pingTimers.end()) {
33  delete timerIt.value();
34  pingTimers.erase(timerIt);
35  }
36  }
37  });
38 
39  pingTimers.insert(serial, pingTimer);
40  pingTimer->start();
41 }
42 
43 XdgShellInterface::XdgShellInterface(Private *d, QObject *parent)
44  : Global(d, parent)
45 {
46 }
47 
48 XdgShellInterface::~XdgShellInterface() = default;
49 
50 XdgShellSurfaceInterface *XdgShellInterface::getSurface(wl_resource *native)
51 {
52  Q_UNUSED(native)
53  return nullptr;
54 }
55 
56 XdgShellInterfaceVersion XdgShellInterface::interfaceVersion() const
57 {
58  Q_D();
59  return d->interfaceVersion;
60 }
61 
62 quint32 XdgShellInterface::ping(XdgShellSurfaceInterface *surface)
63 {
64  return d_func()->ping(surface);
65 }
66 
67 XdgShellInterface::Private *XdgShellInterface::d_func() const
68 {
69  return reinterpret_cast<Private *>(d.data());
70 }
71 
72 XdgShellSurfaceInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion,
73  XdgShellSurfaceInterface *q,
74  Global *c,
75  SurfaceInterface *surface,
76  wl_resource *parentResource,
77  const wl_interface *interface,
78  const void *implementation)
79  : Resource::Private(q, c, parentResource, interface, implementation)
80  , GenericShellSurface<XdgShellSurfaceInterface>(q, surface)
81  , interfaceVersion(interfaceVersion)
82 {
83 }
84 
85 XdgShellSurfaceInterface::Private::~Private() = default;
86 
87 XdgShellSurfaceInterface::XdgShellSurfaceInterface(Private *p)
88  : Resource(p)
89 {
90 }
91 
92 XdgShellSurfaceInterface::~XdgShellSurfaceInterface() = default;
93 
95 {
96  Q_D();
97  return d->interfaceVersion;
98 }
99 
101 {
102  Q_D();
103  return d->configure(states, size);
104 }
105 
107 {
108  Q_D();
109  return !d->configureSerials.isEmpty();
110 }
111 
113 {
114  Q_D();
115  return d->surface;
116 }
117 
119 {
120  Q_D();
121  return d->title;
122 }
123 
124 QByteArray XdgShellSurfaceInterface::windowClass() const
125 {
126  Q_D();
127  return d->windowClass;
128 }
129 
131 {
132  Q_D();
133  return !d->parent.isNull();
134 }
135 
137 {
138  Q_D();
139  return d->parent;
140 }
141 
143 {
144  Q_D();
145  d->close();
146 }
147 
149 {
150  Q_D();
151  return d->windowGeometry();
152 }
153 
155 {
156  Q_D();
157  return d->minimumSize();
158 }
159 
161 {
162  Q_D();
163  return d->maximumSize();
164 }
165 
166 XdgShellSurfaceInterface::Private *XdgShellSurfaceInterface::d_func() const
167 {
168  return reinterpret_cast<Private *>(d.data());
169 }
170 
171 XdgShellPopupInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion,
172  XdgShellPopupInterface *q,
173  XdgShellInterface *c,
174  SurfaceInterface *surface,
175  wl_resource *parentResource,
176  const wl_interface *interface,
177  const void *implementation)
178  : Resource::Private(q, c, parentResource, interface, implementation)
179  , GenericShellSurface<XdgShellPopupInterface>(q, surface)
180  , interfaceVersion(interfaceVersion)
181 {
182 }
183 
184 XdgShellPopupInterface::Private::~Private() = default;
185 
186 XdgShellPopupInterface::XdgShellPopupInterface(Private *p)
187  : Resource(p)
188 {
189 }
190 
191 XdgShellPopupInterface::~XdgShellPopupInterface() = default;
192 
194 {
195  Q_D();
196  return d->surface;
197 }
198 
200 {
201  Q_D();
202  return d->parent;
203 }
204 
206 {
207  Q_D();
208  return d->initialSize;
209 }
210 
212 {
213  QRect rect = anchorRect();
214  const QPoint center = rect.isEmpty() ? rect.topLeft() : rect.center();
215  rect = rect.adjusted(0, 0, 1, 1); // compensate for the stupid QRect::right +1 fiasco
216 
217  switch (anchorEdge()) {
218  case Qt::TopEdge | Qt::LeftEdge:
219  return rect.topLeft();
220  case Qt::TopEdge:
221  return QPoint(center.x(), rect.y());
222  case Qt::TopEdge | Qt::RightEdge:
223  return rect.topRight();
224  case Qt::RightEdge:
225  return QPoint(rect.right(), center.y());
227  return rect.bottomRight();
228  case Qt::BottomEdge:
229  return QPoint(center.x(), rect.bottom());
231  return rect.bottomLeft();
232  case Qt::LeftEdge:
233  return QPoint(rect.left(), center.y());
234  default:
235  return center;
236  }
237  Q_UNREACHABLE();
238 }
239 
241 {
242  Q_D();
243  return d->anchorRect;
244 }
245 
247 {
248  Q_D();
249  return d->anchorEdge;
250 }
251 
253 {
254  Q_D();
255  return d->gravity;
256 }
257 
259 {
260  Q_D();
261  return d->anchorOffset;
262 }
263 
265 {
266  Q_D();
267  return d->constraintAdjustments;
268 }
269 
271 {
272  Q_D();
273  return d->windowGeometry();
274 }
275 
277 {
278  Q_D();
279  return d->popupDone();
280 }
281 
282 quint32 XdgShellPopupInterface::configure(const QRect &rect)
283 {
284  Q_D();
285  return d->configure(rect);
286 }
287 
288 XdgShellPopupInterface::Private *XdgShellPopupInterface::d_func() const
289 {
290  return reinterpret_cast<Private *>(d.data());
291 }
292 
293 }
294 }
XdgShellInterfaceVersion interfaceVersion() const
Qt::Edges anchorEdge() const
Which edge of the anchor should the popup be positioned around.
QPointer< XdgShellSurfaceInterface > transientFor() const
XdgShellInterfaceVersion
Enum describing the different InterfaceVersion encapsulated in this implementation.
QPoint topLeft() const const
QRect windowGeometry() const
windowGeometryChanged
int right() const const
void setSingleShot(bool singleShot)
QRect windowGeometry() const
windowGeometry The geometry of the window within the buffer
int y() const const
QPoint bottomRight() const const
quint32 configure(States states, const QSize &size=QSize(0, 0))
Sends a configure event to the Surface.
void close()
Request the client to close the window.
int left() const const
QRect anchorRect() const
The area this popup should be positioned around.
T * data() const const
int bottom() const const
void start(int msec)
PositionerConstraints constraintAdjustments() const
Specifies how the compositor should position the popup if it does not fit in the requested position.
QSize initialSize() const
The size of the surface that is to be positioned.
QPoint transientOffset() const
The offset of the Surface in the coordinate system of the SurfaceInterface this surface is a transien...
void timeout()
QPoint center() const const
QPoint bottomLeft() const const
bool isNull() const const
bool isEmpty() const const
unsigned int version()
QPoint topRight() const const
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const const
QPointer< SurfaceInterface > transientFor() const
void setInterval(int msec)
Resource representing a wl_surface.
Q_D(Todo)
QPoint anchorOffset() const
An additional offset that should be applied to the popup from the anchor rect.
Qt::Edges gravity() const
Specifies in what direction the popup should be positioned around the anchor i.e if the gravity is "b...
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Feb 8 2023 03:59:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.