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 
15 PointerConstraintsInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion, PointerConstraintsInterface *q, Display *d, const wl_interface *interface, quint32 version)
16  : Global::Private(d, interface, version)
17  , interfaceVersion(interfaceVersion)
18  , q(q)
19 {
20 }
21 
22 PointerConstraintsInterface::PointerConstraintsInterface(Private *d, QObject *parent)
23  : Global(d, parent)
24 {
25 }
26 
27 PointerConstraintsInterface::~PointerConstraintsInterface() = default;
28 
29 PointerConstraintsInterfaceVersion PointerConstraintsInterface::interfaceVersion() const
30 {
31  Q_D();
32  return d->interfaceVersion;
33 }
34 
35 PointerConstraintsInterface::Private *PointerConstraintsInterface::d_func() const
36 {
37  return reinterpret_cast<Private*>(d.data());
38 }
39 
40 LockedPointerInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion, LockedPointerInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
41  : Resource::Private(q, c, parentResource, interface, implementation)
42  , interfaceVersion(interfaceVersion)
43 {
44 }
45 
46 LockedPointerInterface::Private::~Private()
47 {
48  if (resource) {
49  wl_resource_destroy(resource);
50  resource = nullptr;
51  }
52 }
53 
54 void LockedPointerInterface::Private::commit()
55 {
56  if (regionIsSet) {
57  region = pendingRegion;
58  pendingRegion = QRegion();
59  regionIsSet = false;
60  emit q_func()->regionChanged();
61  }
62  if (hintIsSet) {
63  hint = pendingHint;
64  hintIsSet = false;
65  emit q_func()->cursorPositionHintChanged();
66  }
67 }
68 
69 LockedPointerInterface::LockedPointerInterface(Private *p, QObject *parent)
70  : Resource(p, parent)
71 {
72  connect(this, &LockedPointerInterface::unbound, this, [this]() { setLocked(false); });
73 }
74 
75 LockedPointerInterface::~LockedPointerInterface() = default;
76 
77 PointerConstraintsInterfaceVersion LockedPointerInterface::interfaceVersion() const
78 {
79  Q_D();
80  return d->interfaceVersion;
81 }
82 
83 LockedPointerInterface::LifeTime LockedPointerInterface::lifeTime() const
84 {
85  Q_D();
86  return d->lifeTime;
87 }
88 
89 QRegion LockedPointerInterface::region() const
90 {
91  Q_D();
92  return d->region;
93 }
94 
95 QPointF LockedPointerInterface::cursorPositionHint() const
96 {
97  Q_D();
98  return d->hint;
99 }
100 
101 bool LockedPointerInterface::isLocked() const
102 {
103  Q_D();
104  return d->locked;
105 }
106 
107 void LockedPointerInterface::setLocked(bool locked)
108 {
109  Q_D();
110  if (locked == d->locked) {
111  return;
112  }
113  if (!locked) {
114  d->hint = QPointF(-1., -1.);
115  }
116  d->locked = locked;
117  d->updateLocked();
118  emit lockedChanged();
119 }
120 
121 LockedPointerInterface::Private *LockedPointerInterface::d_func() const
122 {
123  return reinterpret_cast<Private*>(d.data());
124 }
125 
126 ConfinedPointerInterface::Private::Private(PointerConstraintsInterfaceVersion interfaceVersion, ConfinedPointerInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
127  : Resource::Private(q, c, parentResource, interface, implementation)
128  , interfaceVersion(interfaceVersion)
129 {
130 }
131 
132 ConfinedPointerInterface::Private::~Private()
133 {
134  if (resource) {
135  wl_resource_destroy(resource);
136  resource = nullptr;
137  }
138 }
139 
140 void ConfinedPointerInterface::Private::commit()
141 {
142  if (!regionIsSet) {
143  return;
144  }
145  region = pendingRegion;
146  pendingRegion = QRegion();
147  regionIsSet = false;
148  emit q_func()->regionChanged();
149 }
150 
151 ConfinedPointerInterface::ConfinedPointerInterface(Private *p, QObject *parent)
152  : Resource(p, parent)
153 {
154  connect(this, &ConfinedPointerInterface::unbound, this, [this]() { setConfined(false); });
155 }
156 
157 ConfinedPointerInterface::~ConfinedPointerInterface() = default;
158 
159 PointerConstraintsInterfaceVersion ConfinedPointerInterface::interfaceVersion() const
160 {
161  Q_D();
162  return d->interfaceVersion;
163 }
164 
165 ConfinedPointerInterface::LifeTime ConfinedPointerInterface::lifeTime() const
166 {
167  Q_D();
168  return d->lifeTime;
169 }
170 
171 QRegion ConfinedPointerInterface::region() const
172 {
173  Q_D();
174  return d->region;
175 }
176 
177 bool ConfinedPointerInterface::isConfined() const
178 {
179  Q_D();
180  return d->confined;
181 }
182 
183 void ConfinedPointerInterface::setConfined(bool confined)
184 {
185  Q_D();
186  if (confined == d->confined) {
187  return;
188  }
189  d->confined = confined;
190  d->updateConfined();
191  emit confinedChanged();
192 }
193 
194 ConfinedPointerInterface::Private *ConfinedPointerInterface::d_func() const
195 {
196  return reinterpret_cast<Private*>(d.data());
197 }
198 
199 }
200 }
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:32
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 22:53:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.