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 
13 XdgShellInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellInterface *q, Display *d, const wl_interface *interface, quint32 version)
14  : Global::Private(d, interface, version)
15  , interfaceVersion(interfaceVersion)
16  , q(q)
17 {
18 }
19 
20 void XdgShellInterface::Private::setupTimer(quint32 serial)
21 {
22  QTimer *pingTimer = new QTimer();
23  pingTimer->setSingleShot(false);
24  pingTimer->setInterval(1000);
25  int attempt = 0;
26  connect(pingTimer, &QTimer::timeout, q, [this, serial, attempt]() mutable {
27  ++attempt;
28  if (attempt == 1) {
29  emit q->pingDelayed(serial);
30  } else {
31  emit q->pingTimeout(serial);
32  auto timerIt = pingTimers.find(serial);
33  if (timerIt != pingTimers.end()) {
34  delete timerIt.value();
35  pingTimers.erase(timerIt);
36  }
37  }
38  });
39 
40  pingTimers.insert(serial, pingTimer);
41  pingTimer->start();
42 }
43 
44 XdgShellInterface::XdgShellInterface(Private *d, QObject *parent)
45  : Global(d, parent)
46 {
47 }
48 
49 XdgShellInterface::~XdgShellInterface() = default;
50 
51 XdgShellSurfaceInterface *XdgShellInterface::getSurface(wl_resource *native)
52 {
53  Q_UNUSED(native)
54  return nullptr;
55 }
56 
57 XdgShellInterfaceVersion XdgShellInterface::interfaceVersion() const
58 {
59  Q_D();
60  return d->interfaceVersion;
61 }
62 
63 quint32 XdgShellInterface::ping(XdgShellSurfaceInterface * surface)
64 {
65  return d_func()->ping(surface);
66 }
67 
68 XdgShellInterface::Private *XdgShellInterface::d_func() const
69 {
70  return reinterpret_cast<Private*>(d.data());
71 }
72 
73 XdgShellSurfaceInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellSurfaceInterface *q, Global *c, SurfaceInterface *surface, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
74  : Resource::Private(q, c, parentResource, interface, implementation)
75  , GenericShellSurface<XdgShellSurfaceInterface>(q, surface)
76  , interfaceVersion(interfaceVersion)
77 {
78 }
79 
80 XdgShellSurfaceInterface::Private::~Private() = default;
81 
82 XdgShellSurfaceInterface::XdgShellSurfaceInterface(Private *p)
83  : Resource(p)
84 {
85 }
86 
87 XdgShellSurfaceInterface::~XdgShellSurfaceInterface() = default;
88 
89 XdgShellInterfaceVersion XdgShellSurfaceInterface::interfaceVersion() const
90 {
91  Q_D();
92  return d->interfaceVersion;
93 }
94 
95 quint32 XdgShellSurfaceInterface::configure(States states, const QSize &size)
96 {
97  Q_D();
98  return d->configure(states, size);
99 }
100 
101 bool XdgShellSurfaceInterface::isConfigurePending() const
102 {
103  Q_D();
104  return !d->configureSerials.isEmpty();
105 }
106 
107 SurfaceInterface *XdgShellSurfaceInterface::surface() const
108 {
109  Q_D();
110  return d->surface;
111 }
112 
113 QString XdgShellSurfaceInterface::title() const
114 {
115  Q_D();
116  return d->title;
117 }
118 
119 QByteArray XdgShellSurfaceInterface::windowClass() const
120 {
121  Q_D();
122  return d->windowClass;
123 }
124 
125 bool XdgShellSurfaceInterface::isTransient() const
126 {
127  Q_D();
128  return !d->parent.isNull();
129 }
130 
131 QPointer<XdgShellSurfaceInterface> XdgShellSurfaceInterface::transientFor() const
132 {
133  Q_D();
134  return d->parent;
135 }
136 
137 void XdgShellSurfaceInterface::close()
138 {
139  Q_D();
140  d->close();
141 }
142 
143 QRect XdgShellSurfaceInterface::windowGeometry() const
144 {
145  Q_D();
146  return d->windowGeometry();
147 }
148 
149 QSize XdgShellSurfaceInterface::minimumSize() const
150 {
151  Q_D();
152  return d->minimumSize();
153 }
154 
155 QSize XdgShellSurfaceInterface::maximumSize() const
156 {
157  Q_D();
158  return d->maximumSize();
159 }
160 
161 XdgShellSurfaceInterface::Private *XdgShellSurfaceInterface::d_func() const
162 {
163  return reinterpret_cast<Private*>(d.data());
164 }
165 
166 XdgShellPopupInterface::Private::Private(XdgShellInterfaceVersion interfaceVersion, XdgShellPopupInterface *q, XdgShellInterface *c, SurfaceInterface *surface, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
167  : Resource::Private(q, c, parentResource, interface, implementation)
168  , GenericShellSurface<XdgShellPopupInterface>(q, surface)
169  , interfaceVersion(interfaceVersion)
170 {
171 }
172 
173 XdgShellPopupInterface::Private::~Private() = default;
174 
175 XdgShellPopupInterface::XdgShellPopupInterface(Private *p)
176  : Resource(p)
177 {
178 }
179 
180 XdgShellPopupInterface::~XdgShellPopupInterface() = default;
181 
182 SurfaceInterface *XdgShellPopupInterface::surface() const
183 {
184  Q_D();
185  return d->surface;
186 }
187 
188 QPointer<SurfaceInterface> XdgShellPopupInterface::transientFor() const
189 {
190  Q_D();
191  return d->parent;
192 }
193 
194 QSize XdgShellPopupInterface::initialSize() const
195 {
196  Q_D();
197  return d->initialSize;
198 }
199 
200 QPoint XdgShellPopupInterface::transientOffset() const
201 {
202  QRect rect = anchorRect();
203  const QPoint center = rect.isEmpty() ? rect.topLeft() : rect.center();
204  rect = rect.adjusted(0,0,1,1); //compensate for the stupid QRect::right +1 fiasco
205 
206  switch(anchorEdge()) {
207  case Qt::TopEdge | Qt::LeftEdge:
208  return rect.topLeft();
209  case Qt::TopEdge:
210  return QPoint(center.x(), rect.y());
211  case Qt::TopEdge | Qt::RightEdge:
212  return rect.topRight();
213  case Qt::RightEdge:
214  return QPoint(rect.right(), center.y());
216  return rect.bottomRight();
217  case Qt::BottomEdge:
218  return QPoint(center.x(), rect.bottom());
220  return rect.bottomLeft();
221  case Qt::LeftEdge:
222  return QPoint(rect.left(), center.y());
223  default:
224  return center;
225  }
226  Q_UNREACHABLE();
227 }
228 
229 QRect XdgShellPopupInterface::anchorRect() const
230 {
231  Q_D();
232  return d->anchorRect;
233 }
234 
235 Qt::Edges XdgShellPopupInterface::anchorEdge() const
236 {
237  Q_D();
238  return d->anchorEdge;
239 }
240 
241 Qt::Edges XdgShellPopupInterface::gravity() const
242 {
243  Q_D();
244  return d->gravity;
245 }
246 
247 QPoint XdgShellPopupInterface::anchorOffset() const
248 {
249  Q_D();
250  return d->anchorOffset;
251 }
252 
253 PositionerConstraints XdgShellPopupInterface::constraintAdjustments() const
254 {
255  Q_D();
256  return d->constraintAdjustments;
257 }
258 
259 QRect XdgShellPopupInterface::windowGeometry() const
260 {
261  Q_D();
262  return d->windowGeometry();
263 }
264 
265 void XdgShellPopupInterface::popupDone()
266 {
267  Q_D();
268  return d->popupDone();
269 }
270 
271 quint32 XdgShellPopupInterface::configure(const QRect &rect)
272 {
273  Q_D();
274  return d->configure(rect);
275 }
276 
277 XdgShellPopupInterface::Private *XdgShellPopupInterface::d_func() const
278 {
279  return reinterpret_cast<Private*>(d.data());
280 }
281 
282 }
283 }
void setInterval(int msec)
QPoint topRight() const const
int right() const const
QPoint bottomRight() const const
QPoint bottomLeft() const const
int y() const const
int x() const const
int y() const const
void timeout()
int left() const const
Resource representing a wl_surface.
QPoint center() const const
XdgShellInterfaceVersion
Enum describing the different InterfaceVersion encapsulated in this implementation.
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const const
T * data() const const
Base class for all Globals.
Definition: global.h:46
bool isEmpty() const const
bool isNull() const const
Represents a bound Resource.
Definition: resource.h:32
int bottom() const const
QPoint topLeft() const const
void start(int msec)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void setSingleShot(bool singleShot)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.