KWayland

pointerconstraints_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 "pointerconstraints_interface_p.h"
7 
8 #include <functional>
9 
10 namespace KWayland
11 {
12 namespace Server
13 {
14 PointerConstraintsInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion,
15  PointerConstraintsInterface *q,
16  Display *d,
17  const wl_interface *interface,
18  quint32 version)
19  : Global::Private(d, interface, version)
20  , interfaceVersion(interfaceVersion)
21  , q(q)
22 {
23 }
24 
25 PointerConstraintsInterface::PointerConstraintsInterface(Private *d, QObject *parent)
26  : Global(d, parent)
27 {
28 }
29 
30 PointerConstraintsInterface::~PointerConstraintsInterface() = default;
31 
32 PointerConstraintsInterfaceVersion PointerConstraintsInterface::interfaceVersion() const
33 {
34  Q_D();
35  return d->interfaceVersion;
36 }
37 
38 PointerConstraintsInterface::Private *PointerConstraintsInterface::d_func() const
39 {
40  return reinterpret_cast<Private *>(d.data());
41 }
42 
43 LockedPointerInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion,
45  Global *c,
46  wl_resource *parentResource,
47  const wl_interface *interface,
48  const void *implementation)
49  : Resource::Private(q, c, parentResource, interface, implementation)
50  , interfaceVersion(interfaceVersion)
51 {
52 }
53 
54 LockedPointerInterface::Private::~Private()
55 {
56  if (resource) {
57  wl_resource_destroy(resource);
58  resource = nullptr;
59  }
60 }
61 
62 void LockedPointerInterface::Private::commit()
63 {
64  if (regionIsSet) {
65  region = pendingRegion;
66  pendingRegion = QRegion();
67  regionIsSet = false;
68  Q_EMIT q_func()->regionChanged();
69  }
70  if (hintIsSet) {
71  hint = pendingHint;
72  hintIsSet = false;
73  Q_EMIT q_func()->cursorPositionHintChanged();
74  }
75 }
76 
77 LockedPointerInterface::LockedPointerInterface(Private *p, QObject *parent)
78  : Resource(p, parent)
79 {
80  connect(this, &LockedPointerInterface::unbound, this, [this]() {
81  setLocked(false);
82  });
83 }
84 
85 LockedPointerInterface::~LockedPointerInterface() = default;
86 
87 PointerConstraintsInterfaceVersion LockedPointerInterface::interfaceVersion() const
88 {
89  Q_D();
90  return d->interfaceVersion;
91 }
92 
93 LockedPointerInterface::LifeTime LockedPointerInterface::lifeTime() const
94 {
95  Q_D();
96  return d->lifeTime;
97 }
98 
99 QRegion LockedPointerInterface::region() const
100 {
101  Q_D();
102  return d->region;
103 }
104 
105 QPointF LockedPointerInterface::cursorPositionHint() const
106 {
107  Q_D();
108  return d->hint;
109 }
110 
111 bool LockedPointerInterface::isLocked() const
112 {
113  Q_D();
114  return d->locked;
115 }
116 
117 void LockedPointerInterface::setLocked(bool locked)
118 {
119  Q_D();
120  if (locked == d->locked) {
121  return;
122  }
123  if (!locked) {
124  d->hint = QPointF(-1., -1.);
125  }
126  d->locked = locked;
127  d->updateLocked();
128  Q_EMIT lockedChanged();
129 }
130 
131 LockedPointerInterface::Private *LockedPointerInterface::d_func() const
132 {
133  return reinterpret_cast<Private *>(d.data());
134 }
135 
136 ConfinedPointerInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion,
138  Global *c,
139  wl_resource *parentResource,
140  const wl_interface *interface,
141  const void *implementation)
142  : Resource::Private(q, c, parentResource, interface, implementation)
143  , interfaceVersion(interfaceVersion)
144 {
145 }
146 
147 ConfinedPointerInterface::Private::~Private()
148 {
149  if (resource) {
150  wl_resource_destroy(resource);
151  resource = nullptr;
152  }
153 }
154 
155 void ConfinedPointerInterface::Private::commit()
156 {
157  if (!regionIsSet) {
158  return;
159  }
160  region = pendingRegion;
161  pendingRegion = QRegion();
162  regionIsSet = false;
163  Q_EMIT q_func()->regionChanged();
164 }
165 
166 ConfinedPointerInterface::ConfinedPointerInterface(Private *p, QObject *parent)
167  : Resource(p, parent)
168 {
169  connect(this, &ConfinedPointerInterface::unbound, this, [this]() {
170  setConfined(false);
171  });
172 }
173 
174 ConfinedPointerInterface::~ConfinedPointerInterface() = default;
175 
176 PointerConstraintsInterfaceVersion ConfinedPointerInterface::interfaceVersion() const
177 {
178  Q_D();
179  return d->interfaceVersion;
180 }
181 
182 ConfinedPointerInterface::LifeTime ConfinedPointerInterface::lifeTime() const
183 {
184  Q_D();
185  return d->lifeTime;
186 }
187 
188 QRegion ConfinedPointerInterface::region() const
189 {
190  Q_D();
191  return d->region;
192 }
193 
194 bool ConfinedPointerInterface::isConfined() const
195 {
196  Q_D();
197  return d->confined;
198 }
199 
200 void ConfinedPointerInterface::setConfined(bool confined)
201 {
202  Q_D();
203  if (confined == d->confined) {
204  return;
205  }
206  d->confined = confined;
207  d->updateConfined();
208  Q_EMIT confinedChanged();
209 }
210 
211 ConfinedPointerInterface::Private *ConfinedPointerInterface::d_func() const
212 {
213  return reinterpret_cast<Private *>(d.data());
214 }
215 
216 }
217 }
PointerConstraintsInterfaceVersion
Enum describing the interface versions the PointerConstraintsInterface can support.
The LockedPointerInterface lets the client request to disable movements of the virtual pointer (i...
void confined()
Notification that the pointer confinement of the seat&#39;s pointer is activated.
T * data() const const
Base class for all Globals.
Definition: global.h:46
Represents a bound Resource.
Definition: resource.h:31
The ConfinedPointerInterface gets installed on a SurfaceInterface.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Sep 26 2021 22:51:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.