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; | ||
56 | }; | 62 | }; | ||
57 | 63 | | |||
58 | class FakeInputDevice::Private | 64 | class FakeInputDevice::Private | ||
59 | { | 65 | { | ||
60 | public: | 66 | public: | ||
61 | Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q); | 67 | Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q); | ||
62 | wl_resource *resource; | 68 | wl_resource *resource; | ||
63 | FakeInputInterface *interface; | 69 | FakeInputInterface *interface; | ||
64 | bool authenticated = false; | 70 | bool authenticated = false; | ||
65 | 71 | | |||
66 | private: | 72 | private: | ||
67 | FakeInputDevice *q; | 73 | FakeInputDevice *q; | ||
68 | }; | 74 | }; | ||
69 | 75 | | |||
70 | const quint32 FakeInputInterface::Private::s_version = 1; | 76 | const quint32 FakeInputInterface::Private::s_version = 2; | ||
71 | 77 | | |||
72 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | 78 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | ||
73 | const struct org_kde_kwin_fake_input_interface FakeInputInterface::Private::s_interface = { | 79 | const struct org_kde_kwin_fake_input_interface FakeInputInterface::Private::s_interface = { | ||
74 | authenticateCallback, | 80 | authenticateCallback, | ||
75 | pointerMotionCallback, | 81 | pointerMotionCallback, | ||
76 | buttonCallback, | 82 | buttonCallback, | ||
77 | axisCallback | 83 | axisCallback, | ||
84 | touchDownCallback, | ||||
85 | touchMotionCallback, | ||||
86 | touchUpCallback, | ||||
87 | touchCancelCallback, | ||||
88 | touchFrameCallback | ||||
78 | }; | 89 | }; | ||
79 | #endif | 90 | #endif | ||
80 | 91 | | |||
81 | FakeInputInterface::Private::Private(FakeInputInterface *q, Display *d) | 92 | FakeInputInterface::Private::Private(FakeInputInterface *q, Display *d) | ||
82 | : Global::Private(d, &org_kde_kwin_fake_input_interface, s_version) | 93 | : Global::Private(d, &org_kde_kwin_fake_input_interface, s_version) | ||
83 | , q(q) | 94 | , q(q) | ||
84 | { | 95 | { | ||
85 | } | 96 | } | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 183 | case WL_POINTER_BUTTON_STATE_RELEASED: | |||
173 | emit d->pointerButtonReleaseRequested(button); | 184 | emit d->pointerButtonReleaseRequested(button); | ||
174 | break; | 185 | break; | ||
175 | default: | 186 | default: | ||
176 | // nothing | 187 | // nothing | ||
177 | break; | 188 | break; | ||
178 | } | 189 | } | ||
179 | } | 190 | } | ||
180 | 191 | | |||
192 | void FakeInputInterface::Private::touchDownCallback(wl_client *client, wl_resource *resource, quint32 id, wl_fixed_t x, wl_fixed_t y) | ||||
193 | { | ||||
194 | Q_UNUSED(client) | ||||
graesslin: nitpick: empty line | |||||
195 | FakeInputDevice *d = device(resource); | ||||
196 | 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… | |||||
197 | return; | ||||
198 | } | ||||
199 | emit d->touchDownRequested(id, QPointF(wl_fixed_to_double(x), wl_fixed_to_double(y))); | ||||
200 | } | ||||
graesslin: please watch coding style - same in all other areas you just adjusted. | |||||
201 | | ||||
202 | void FakeInputInterface::Private::touchMotionCallback(wl_client *client, wl_resource *resource, quint32 id, wl_fixed_t x, wl_fixed_t y) | ||||
203 | { | ||||
204 | Q_UNUSED(client) | ||||
205 | FakeInputDevice *d = device(resource); | ||||
206 | if (!d || !d->isAuthenticated()) { | ||||
207 | return; | ||||
208 | } | ||||
209 | emit d->touchMotionRequested(id, QPointF(wl_fixed_to_double(x), wl_fixed_to_double(y))); | ||||
210 | } | ||||
211 | | ||||
212 | void FakeInputInterface::Private::touchUpCallback(wl_client *client, wl_resource *resource, quint32 id) | ||||
213 | { | ||||
214 | Q_UNUSED(client) | ||||
215 | FakeInputDevice *d = device(resource); | ||||
216 | if (!d || !d->isAuthenticated()) { | ||||
217 | return; | ||||
218 | } | ||||
219 | emit d->touchUpRequested(id); | ||||
220 | } | ||||
221 | | ||||
222 | void FakeInputInterface::Private::touchCancelCallback(wl_client *client, wl_resource *resource) | ||||
223 | { | ||||
224 | Q_UNUSED(client) | ||||
225 | FakeInputDevice *d = device(resource); | ||||
226 | if (!d || !d->isAuthenticated()) { | ||||
227 | return; | ||||
228 | } | ||||
229 | emit d->touchCancelRequested(); | ||||
230 | } | ||||
231 | | ||||
232 | void FakeInputInterface::Private::touchFrameCallback(wl_client *client, wl_resource *resource) | ||||
233 | { | ||||
234 | Q_UNUSED(client) | ||||
235 | FakeInputDevice *d = device(resource); | ||||
236 | if (!d || !d->isAuthenticated()) { | ||||
237 | return; | ||||
238 | } | ||||
239 | emit d->touchFrameRequested(); | ||||
240 | } | ||||
241 | | ||||
181 | FakeInputInterface::FakeInputInterface(Display *display, QObject *parent) | 242 | FakeInputInterface::FakeInputInterface(Display *display, QObject *parent) | ||
182 | : Global(new Private(this, display), parent) | 243 | : Global(new Private(this, display), parent) | ||
183 | { | 244 | { | ||
184 | } | 245 | } | ||
185 | 246 | | |||
186 | FakeInputInterface::~FakeInputInterface() = default; | 247 | FakeInputInterface::~FakeInputInterface() = default; | ||
187 | 248 | | |||
188 | FakeInputDevice::Private::Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q) | 249 | FakeInputDevice::Private::Private(wl_resource *resource, FakeInputInterface *interface, FakeInputDevice *q) | ||
Show All 31 Lines |
nitpick: empty line