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,
44  LockedPointerInterface *q,
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 
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 
100 {
101  Q_D();
102  return d->region;
103 }
104 
106 {
107  Q_D();
108  return d->hint;
109 }
110 
112 {
113  Q_D();
114  return d->locked;
115 }
116 
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();
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,
137  ConfinedPointerInterface *q,
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 
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 
189 {
190  Q_D();
191  return d->region;
192 }
193 
195 {
196  Q_D();
197  return d->confined;
198 }
199 
201 {
202  Q_D();
203  if (confined == d->confined) {
204  return;
205  }
206  d->confined = confined;
207  d->updateConfined();
209 }
210 
211 ConfinedPointerInterface::Private *ConfinedPointerInterface::d_func() const
212 {
213  return reinterpret_cast<Private *>(d.data());
214 }
215 
216 }
217 }
QRegion region() const
The intersection of this region and the input region of the SurfaceInterface is used to determine whe...
Q_EMITQ_EMIT
void setLocked(bool locked)
Activates or deactivates the lock.
void confinedChanged()
Emitted whenever the isConfined state changes.
PointerConstraintsInterfaceVersion interfaceVersion() const
QPointF cursorPositionHint() const
Indicates where the mouse cursor should be positioned after it has been unlocked again.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void unbound()
This signal is emitted when the client unbound this Resource.
T * data() const const
void setConfined(bool confined)
Activates or deactivates the confinement.
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
PointerConstraintsInterfaceVersion
Enum describing the interface versions the PointerConstraintsInterface can support.
unsigned int version()
void lockedChanged()
Emitted whenever the isLocked state changes.
bool isConfined() const
Whether the Compositor set this pointer confinement to be active.
QRegion region() const
The intersection of this region and the input region of the SurfaceInterface is used to determine whe...
bool isLocked() const
Whether the Compositor set this pointer lock to be active.
PointerConstraintsInterfaceVersion interfaceVersion() const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.