Changeset View
Changeset View
Standalone View
Standalone View
src/server/fakeinput_interface.cpp
Show All 16 Lines | |||||
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "fakeinput_interface.h" | 20 | #include "fakeinput_interface.h" | ||
21 | #include "display.h" | 21 | #include "display.h" | ||
22 | #include "global_p.h" | 22 | #include "global_p.h" | ||
23 | 23 | | |||
24 | #include <QSizeF> | 24 | #include <QSizeF> | ||
25 | #include <QPointF> | ||||
25 | 26 | | |||
26 | #include <wayland-server.h> | 27 | #include <wayland-server.h> | ||
27 | #include <wayland-fake-input-server-protocol.h> | 28 | #include <wayland-fake-input-server-protocol.h> | ||
28 | 29 | | |||
29 | namespace KWayland | 30 | namespace KWayland | ||
30 | { | 31 | { | ||
31 | namespace Server | 32 | namespace Server | ||
32 | { | 33 | { | ||
33 | 34 | | |||
34 | class FakeInputInterface::Private : public Global::Private | 35 | class FakeInputInterface::Private : public Global::Private | ||
35 | { | 36 | { | ||
36 | public: | 37 | public: | ||
37 | Private(FakeInputInterface *q, Display *d); | 38 | Private(FakeInputInterface *q, Display *d); | ||
38 | QList<FakeInputDevice*> devices; | 39 | QList<FakeInputDevice*> devices; | ||
39 | 40 | | |||
40 | private: | 41 | private: | ||
41 | void bind(wl_client *client, uint32_t version, uint32_t id) override; | 42 | void bind(wl_client *client, uint32_t version, uint32_t id) override; | ||
42 | static void authenticateCallback(wl_client *client, wl_resource *resource, const char *application, const char *reason); | 43 | static void authenticateCallback(wl_client *client, wl_resource *resource, const char *application, const char *reason); | ||
43 | static void pointerMotionCallback(wl_client *client, wl_resource *resource, wl_fixed_t delta_x, wl_fixed_t delta_y); | 44 | static void pointerMotionCallback(wl_client *client, wl_resource *resource, wl_fixed_t delta_x, wl_fixed_t delta_y); | ||
44 | static void buttonCallback(wl_client *client, wl_resource *resource, uint32_t button, uint32_t state); | 45 | static void buttonCallback(wl_client *client, wl_resource *resource, uint32_t button, uint32_t state); | ||
45 | static void axisCallback(wl_client *client, wl_resource *resource, uint32_t axis, wl_fixed_t value); | 46 | static void axisCallback(wl_client *client, wl_resource *resource, uint32_t axis, wl_fixed_t value); | ||
47 | static void touchDownCallback(wl_client *client, wl_resource *resource, quint32 id, wl_fixed_t x, wl_fixed_t y); | ||||
48 | static void touchMotionCallback(wl_client *client, wl_resource *resource, quint32 id, wl_fixed_t x, wl_fixed_t y); | ||||
49 | static void touchUpCallback(wl_client *client, wl_resource *resource, quint32 id); | ||||
50 | static void touchCancelCallback(wl_client *client, wl_resource *resource); | ||||
51 | static void touchFrameCallback(wl_client *client, wl_resource *resource); | ||||
46 | 52 | | |||
47 | static void unbind(wl_resource *resource); | 53 | static void unbind(wl_resource *resource); | ||
48 | static Private *cast(wl_resource *r) { | 54 | static Private *cast(wl_resource *r) { | ||
49 | return reinterpret_cast<Private*>(wl_resource_get_user_data(r)); | 55 | return reinterpret_cast<Private*>(wl_resource_get_user_data(r)); | ||
50 | } | 56 | } | ||
51 | static FakeInputDevice *device(wl_resource *r); | 57 | static FakeInputDevice *device(wl_resource *r); | ||
52 | 58 | | |||
53 | FakeInputInterface *q; | 59 | FakeInputInterface *q; | ||
54 | static const struct org_kde_kwin_fake_input_interface s_interface; | 60 | static const struct org_kde_kwin_fake_input_interface s_interface; | ||
55 | static const quint32 s_version; | 61 | static const quint32 s_version; | ||
62 | static QList<quint32> touchIds; | ||||
56 | }; | 63 | }; | ||
57 | 64 | | |||
58 | class FakeInputDevice::Private | 65 | class FakeInputDevice::Private | ||
59 | { | 66 | { | ||
60 | public: | 67 | public: | ||
61 | Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q); | 68 | Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q); | ||
62 | wl_resource *resource; | 69 | wl_resource *resource; | ||
63 | FakeInputInterface *interface; | 70 | FakeInputInterface *interface; | ||
64 | bool authenticated = false; | 71 | bool authenticated = false; | ||
65 | 72 | | |||
66 | private: | 73 | private: | ||
67 | FakeInputDevice *q; | 74 | FakeInputDevice *q; | ||
68 | }; | 75 | }; | ||
69 | 76 | | |||
70 | const quint32 FakeInputInterface::Private::s_version = 1; | 77 | const quint32 FakeInputInterface::Private::s_version = 2; | ||
78 | QList<quint32> FakeInputInterface::Private::touchIds = QList<quint32>(); | ||||
71 | 79 | | |||
72 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | 80 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | ||
73 | const struct org_kde_kwin_fake_input_interface FakeInputInterface::Private::s_interface = { | 81 | const struct org_kde_kwin_fake_input_interface FakeInputInterface::Private::s_interface = { | ||
74 | authenticateCallback, | 82 | authenticateCallback, | ||
75 | pointerMotionCallback, | 83 | pointerMotionCallback, | ||
76 | buttonCallback, | 84 | buttonCallback, | ||
77 | axisCallback | 85 | axisCallback, | ||
86 | touchDownCallback, | ||||
87 | touchMotionCallback, | ||||
88 | touchUpCallback, | ||||
89 | touchCancelCallback, | ||||
90 | touchFrameCallback | ||||
78 | }; | 91 | }; | ||
79 | #endif | 92 | #endif | ||
80 | 93 | | |||
81 | FakeInputInterface::Private::Private(FakeInputInterface *q, Display *d) | 94 | FakeInputInterface::Private::Private(FakeInputInterface *q, Display *d) | ||
82 | : Global::Private(d, &org_kde_kwin_fake_input_interface, s_version) | 95 | : Global::Private(d, &org_kde_kwin_fake_input_interface, s_version) | ||
83 | , q(q) | 96 | , q(q) | ||
84 | { | 97 | { | ||
85 | } | 98 | } | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 185 | case WL_POINTER_BUTTON_STATE_RELEASED: | |||
173 | emit d->pointerButtonReleaseRequested(button); | 186 | emit d->pointerButtonReleaseRequested(button); | ||
174 | break; | 187 | break; | ||
175 | default: | 188 | default: | ||
176 | // nothing | 189 | // nothing | ||
177 | break; | 190 | break; | ||
178 | } | 191 | } | ||
179 | } | 192 | } | ||
180 | 193 | | |||
194 | void FakeInputInterface::Private::touchDownCallback(wl_client *client, wl_resource *resource, quint32 id, wl_fixed_t x, wl_fixed_t y) | ||||
195 | { | ||||
196 | Q_UNUSED(client) | ||||
graesslin: nitpick: empty line | |||||
197 | FakeInputDevice *d = device(resource); | ||||
198 | if (!d || !d->isAuthenticated()) { | ||||
The isAuthenticated check is not verified in the autotest. That's the same with the other new methods. graesslin: The isAuthenticated check is not verified in the autotest. That's the same with the other new… | |||||
199 | return; | ||||
200 | } | ||||
201 | if (touchIds.contains(id)) { | ||||
202 | return; | ||||
graesslin: please watch coding style - same in all other areas you just adjusted. | |||||
203 | } | ||||
204 | touchIds << id; | ||||
205 | emit d->touchDownRequested(id, QPointF(wl_fixed_to_double(x), wl_fixed_to_double(y))); | ||||
206 | } | ||||
207 | | ||||
208 | void FakeInputInterface::Private::touchMotionCallback(wl_client *client, wl_resource *resource, quint32 id, wl_fixed_t x, wl_fixed_t y) | ||||
209 | { | ||||
210 | Q_UNUSED(client) | ||||
211 | FakeInputDevice *d = device(resource); | ||||
212 | if (!d || !d->isAuthenticated()) { | ||||
213 | return; | ||||
214 | } | ||||
215 | if (!touchIds.contains(id)) { | ||||
216 | return; | ||||
217 | } | ||||
218 | emit d->touchMotionRequested(id, QPointF(wl_fixed_to_double(x), wl_fixed_to_double(y))); | ||||
219 | } | ||||
220 | | ||||
221 | void FakeInputInterface::Private::touchUpCallback(wl_client *client, wl_resource *resource, quint32 id) | ||||
222 | { | ||||
223 | Q_UNUSED(client) | ||||
224 | FakeInputDevice *d = device(resource); | ||||
225 | if (!d || !d->isAuthenticated()) { | ||||
226 | return; | ||||
227 | } | ||||
228 | if (!touchIds.contains(id)) { | ||||
229 | return; | ||||
230 | } | ||||
231 | touchIds.removeOne(id); | ||||
232 | emit d->touchUpRequested(id); | ||||
233 | } | ||||
234 | | ||||
235 | void FakeInputInterface::Private::touchCancelCallback(wl_client *client, wl_resource *resource) | ||||
236 | { | ||||
237 | Q_UNUSED(client) | ||||
238 | FakeInputDevice *d = device(resource); | ||||
239 | if (!d || !d->isAuthenticated()) { | ||||
240 | return; | ||||
241 | } | ||||
242 | touchIds.clear(); | ||||
243 | emit d->touchCancelRequested(); | ||||
244 | } | ||||
245 | | ||||
246 | void FakeInputInterface::Private::touchFrameCallback(wl_client *client, wl_resource *resource) | ||||
247 | { | ||||
248 | Q_UNUSED(client) | ||||
249 | FakeInputDevice *d = device(resource); | ||||
250 | if (!d || !d->isAuthenticated()) { | ||||
251 | return; | ||||
252 | } | ||||
253 | emit d->touchFrameRequested(); | ||||
254 | } | ||||
255 | | ||||
181 | FakeInputInterface::FakeInputInterface(Display *display, QObject *parent) | 256 | FakeInputInterface::FakeInputInterface(Display *display, QObject *parent) | ||
182 | : Global(new Private(this, display), parent) | 257 | : Global(new Private(this, display), parent) | ||
183 | { | 258 | { | ||
184 | } | 259 | } | ||
185 | 260 | | |||
186 | FakeInputInterface::~FakeInputInterface() = default; | 261 | FakeInputInterface::~FakeInputInterface() = default; | ||
187 | 262 | | |||
188 | FakeInputDevice::Private::Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q) | 263 | FakeInputDevice::Private::Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q) | ||
Show All 31 Lines |
nitpick: empty line