KWayland

pointerconstraints.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 "pointerconstraints.h"
7 #include "event_queue.h"
8 #include "pointer.h"
9 #include "region.h"
10 #include "surface.h"
11 #include "wayland_pointer_p.h"
12 
13 #include <wayland-pointer-constraints-unstable-v1-client-protocol.h>
14 
15 namespace KWayland
16 {
17 namespace Client
18 {
19 
20 class Q_DECL_HIDDEN PointerConstraints::Private
21 {
22 public:
23  Private() = default;
24 
25  void setup(zwp_pointer_constraints_v1 *arg);
26 
27  WaylandPointer<zwp_pointer_constraints_v1, zwp_pointer_constraints_v1_destroy> pointerconstraints;
28  EventQueue *queue = nullptr;
29 };
30 
32  : QObject(parent)
33  , d(new Private)
34 {
35 }
36 
37 void PointerConstraints::Private::setup(zwp_pointer_constraints_v1 *arg)
38 {
39  Q_ASSERT(arg);
40  Q_ASSERT(!pointerconstraints);
41  pointerconstraints.setup(arg);
42 }
43 
44 PointerConstraints::~PointerConstraints()
45 {
46  release();
47 }
48 
49 void PointerConstraints::setup(zwp_pointer_constraints_v1 *pointerconstraints)
50 {
51  d->setup(pointerconstraints);
52 }
53 
55 {
56  d->pointerconstraints.release();
57 }
58 
60 {
61  d->pointerconstraints.destroy();
62 }
63 
64 PointerConstraints::operator zwp_pointer_constraints_v1*() {
65  return d->pointerconstraints;
66 }
67 
68 PointerConstraints::operator zwp_pointer_constraints_v1*() const {
69  return d->pointerconstraints;
70 }
71 
73 {
74  return d->pointerconstraints.isValid();
75 }
76 
78 {
79  d->queue = queue;
80 }
81 
83 {
84  return d->queue;
85 }
86 
88 {
89  Q_ASSERT(isValid());
90  auto p = new LockedPointer(parent);
91  zwp_pointer_constraints_v1_lifetime lf;
92  switch (lifetime) {
93  case LifeTime::OneShot:
94  lf = ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT;
95  break;
97  lf = ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT;
98  break;
99  default:
100  Q_UNREACHABLE();
101  break;
102  }
103  wl_region *wr = nullptr;
104  if (region) {
105  wr = *region;
106  }
107  auto w = zwp_pointer_constraints_v1_lock_pointer(d->pointerconstraints, *surface, *pointer, wr, lf);
108  if (d->queue) {
109  d->queue->addProxy(w);
110  }
111  p->setup(w);
112  return p;
113 }
114 
116 {
117  Q_ASSERT(isValid());
118  auto p = new ConfinedPointer(parent);
119  zwp_pointer_constraints_v1_lifetime lf;
120  switch (lifetime) {
121  case LifeTime::OneShot:
122  lf = ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT;
123  break;
125  lf = ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT;
126  break;
127  default:
128  Q_UNREACHABLE();
129  break;
130  }
131  wl_region *wr = nullptr;
132  if (region) {
133  wr = *region;
134  }
135  auto w = zwp_pointer_constraints_v1_confine_pointer(d->pointerconstraints, *surface, *pointer, wr, lf);
136  if (d->queue) {
137  d->queue->addProxy(w);
138  }
139  p->setup(w);
140  return p;
141 }
142 
143 class Q_DECL_HIDDEN LockedPointer::Private
144 {
145 public:
146  Private(LockedPointer *q);
147 
148  void setup(zwp_locked_pointer_v1 *arg);
149 
150  WaylandPointer<zwp_locked_pointer_v1, zwp_locked_pointer_v1_destroy> lockedpointer;
151 
152 private:
153  LockedPointer *q;
154 
155 private:
156  static void lockedCallback(void *data, zwp_locked_pointer_v1 *zwp_locked_pointer_v1);
157  static void unlockedCallback(void *data, zwp_locked_pointer_v1 *zwp_locked_pointer_v1);
158 
159  static const zwp_locked_pointer_v1_listener s_listener;
160 };
161 
162 const zwp_locked_pointer_v1_listener LockedPointer::Private::s_listener = {
163  lockedCallback,
164  unlockedCallback
165 };
166 
167 void LockedPointer::Private::lockedCallback(void *data, zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
168 {
169  auto p = reinterpret_cast<LockedPointer::Private*>(data);
170  Q_ASSERT(p->lockedpointer == zwp_locked_pointer_v1);
171  emit p->q->locked();
172 }
173 
174 void LockedPointer::Private::unlockedCallback(void *data, zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
175 {
176  auto p = reinterpret_cast<LockedPointer::Private*>(data);
177  Q_ASSERT(p->lockedpointer == zwp_locked_pointer_v1);
178  emit p->q->unlocked();
179 }
180 
181 LockedPointer::Private::Private(LockedPointer *q)
182  : q(q)
183 {
184 }
185 
186 LockedPointer::LockedPointer(QObject *parent)
187  : QObject(parent)
188  , d(new Private(this))
189 {
190 }
191 
192 void LockedPointer::Private::setup(zwp_locked_pointer_v1 *arg)
193 {
194  Q_ASSERT(arg);
195  Q_ASSERT(!lockedpointer);
196  lockedpointer.setup(arg);
197  zwp_locked_pointer_v1_add_listener(lockedpointer, &s_listener, this);
198 }
199 
200 LockedPointer::~LockedPointer()
201 {
202  release();
203 }
204 
205 void LockedPointer::setup(zwp_locked_pointer_v1 *lockedpointer)
206 {
207  d->setup(lockedpointer);
208 }
209 
211 {
212  d->lockedpointer.release();
213 }
214 
216 {
217  d->lockedpointer.destroy();
218 }
219 
220 LockedPointer::operator zwp_locked_pointer_v1*() {
221  return d->lockedpointer;
222 }
223 
224 LockedPointer::operator zwp_locked_pointer_v1*() const {
225  return d->lockedpointer;
226 }
227 
229 {
230  return d->lockedpointer.isValid();
231 }
232 
234 {
235  Q_ASSERT(isValid());
236  zwp_locked_pointer_v1_set_cursor_position_hint(d->lockedpointer, wl_fixed_from_double(surfaceLocal.x()), wl_fixed_from_double(surfaceLocal.y()));
237 }
238 
240 {
241  Q_ASSERT(isValid());
242  wl_region *wr = nullptr;
243  if (region) {
244  wr = *region;
245  }
246  zwp_locked_pointer_v1_set_region(d->lockedpointer, wr);
247 }
248 
249 class Q_DECL_HIDDEN ConfinedPointer::Private
250 {
251 public:
252  Private(ConfinedPointer *q);
253 
254  void setup(zwp_confined_pointer_v1 *arg);
255 
256  WaylandPointer<zwp_confined_pointer_v1, zwp_confined_pointer_v1_destroy> confinedpointer;
257 
258 private:
259  ConfinedPointer *q;
260 
261 private:
262  static void confinedCallback(void *data, zwp_confined_pointer_v1 *zwp_confined_pointer_v1);
263  static void unconfinedCallback(void *data, zwp_confined_pointer_v1 *zwp_confined_pointer_v1);
264 
265  static const zwp_confined_pointer_v1_listener s_listener;
266 };
267 
268 const zwp_confined_pointer_v1_listener ConfinedPointer::Private::s_listener = {
269  confinedCallback,
270  unconfinedCallback
271 };
272 
273 void ConfinedPointer::Private::confinedCallback(void *data, zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
274 {
275  auto p = reinterpret_cast<ConfinedPointer::Private*>(data);
276  Q_ASSERT(p->confinedpointer == zwp_confined_pointer_v1);
277  emit p->q->confined();
278 }
279 
280 void ConfinedPointer::Private::unconfinedCallback(void *data, zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
281 {
282  auto p = reinterpret_cast<ConfinedPointer::Private*>(data);
283  Q_ASSERT(p->confinedpointer == zwp_confined_pointer_v1);
284  emit p->q->unconfined();
285 }
286 
287 ConfinedPointer::Private::Private(ConfinedPointer *q)
288  : q(q)
289 {
290 }
291 
292 ConfinedPointer::ConfinedPointer(QObject *parent)
293  : QObject(parent)
294  , d(new Private(this))
295 {
296 }
297 
298 void ConfinedPointer::Private::setup(zwp_confined_pointer_v1 *arg)
299 {
300  Q_ASSERT(arg);
301  Q_ASSERT(!confinedpointer);
302  confinedpointer.setup(arg);
303  zwp_confined_pointer_v1_add_listener(confinedpointer, &s_listener, this);
304 }
305 
306 ConfinedPointer::~ConfinedPointer()
307 {
308  release();
309 }
310 
311 void ConfinedPointer::setup(zwp_confined_pointer_v1 *confinedpointer)
312 {
313  d->setup(confinedpointer);
314 }
315 
317 {
318  d->confinedpointer.release();
319 }
320 
322 {
323  d->confinedpointer.destroy();
324 }
325 
326 ConfinedPointer::operator zwp_confined_pointer_v1*() {
327  return d->confinedpointer;
328 }
329 
330 ConfinedPointer::operator zwp_confined_pointer_v1*() const {
331  return d->confinedpointer;
332 }
333 
335 {
336  return d->confinedpointer.isValid();
337 }
338 
340 {
341  Q_ASSERT(isValid());
342  wl_region *wr = nullptr;
343  if (region) {
344  wr = *region;
345  }
346  zwp_confined_pointer_v1_set_region(d->confinedpointer, wr);
347 }
348 
349 }
350 }
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this PointerConstraints.
PointerConstraints(QObject *parent=nullptr)
Creates a new PointerConstraints.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
ConfinedPointer * confinePointer(Surface *surface, Pointer *pointer, Region *region, LifeTime lifetime, QObject *parent=nullptr)
This factory method creates a ConfinedPointer.
void setCursorPositionHint(const QPointF &surfaceLocal)
Set the cursor position hint relative to the top left corner of the Surface.
void release()
Releases the zwp_pointer_constraints_v1 interface.
A OneShot pointer constraint will never reactivate once it has been deactivated.
qreal x() const const
qreal y() const const
void setup(zwp_confined_pointer_v1 *confinedpointer)
Setup this ConfinedPointer to manage the confinedpointer.
Wrapper for the wl_surface interface.
Definition: surface.h:44
void release()
Releases the zwp_confined_pointer_v1 interface.
void destroy()
Destroys the data held by this PointerConstraints.
Wrapper for the wl_pointer interface.
Definition: pointer.h:32
Wrapper for zwp_confined_pointer_v1 protocol The confine pointer interface represents a confined poin...
void destroy()
Destroys the data held by this ConfinedPointer.
QObject(QObject *parent)
void setup(zwp_locked_pointer_v1 *lockedpointer)
Setup this LockedPointer to manage the lockedpointer.
void destroy()
Destroys the data held by this LockedPointer.
void setRegion(Region *region)
Set a new region used to lock the pointer.
LifeTime
These values represent different lifetime semantics.
A persistent pointer constraint may again reactivate once it has been deactivated.
void setup(zwp_pointer_constraints_v1 *pointerconstraints)
Setup this PointerConstraints to manage the pointerconstraints.
QObject * parent() const const
LockedPointer * lockPointer(Surface *surface, Pointer *pointer, Region *region, LifeTime lifetime, QObject *parent=nullptr)
This factory method creates a LockedPointer.
Wrapper for the wl_region interface.
Definition: region.h:32
Wrapper for the zwp_locked_pointer_v1 interface.
void release()
Releases the zwp_locked_pointer_v1 interface.
void setRegion(Region *region)
Set a new region used to confine the pointer.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 13 2020 22:50:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.