KWayland

touch_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 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 "touch_interface.h"
7 #include "display.h"
8 #include "resource_p.h"
9 #include "seat_interface.h"
10 #include "surface_interface.h"
11 // Wayland
12 #include <wayland-server.h>
13 
14 namespace KWayland
15 {
16 namespace Server
17 {
18 class TouchInterface::Private : public Resource::Private
19 {
20 public:
21  Private(SeatInterface *parent, wl_resource *parentResource, TouchInterface *q);
22 
23  SeatInterface *seat;
24  QMetaObject::Connection destroyConnection;
25 
26 private:
27  TouchInterface *q_func()
28  {
29  return reinterpret_cast<TouchInterface *>(q);
30  }
31 
32  static const struct wl_touch_interface s_interface;
33 };
34 
35 #ifndef K_DOXYGEN
36 const struct wl_touch_interface TouchInterface::Private::s_interface = {resourceDestroyedCallback};
37 #endif
38 
39 TouchInterface::Private::Private(SeatInterface *parent, wl_resource *parentResource, TouchInterface *q)
40  : Resource::Private(q, parent, parentResource, &wl_touch_interface, &s_interface)
41  , seat(parent)
42 {
43 }
44 
45 TouchInterface::TouchInterface(SeatInterface *parent, wl_resource *parentResource)
46  : Resource(new Private(parent, parentResource, this))
47 {
48 }
49 
50 TouchInterface::~TouchInterface() = default;
51 
52 void TouchInterface::cancel()
53 {
54  Q_D();
55  if (!d->resource) {
56  return;
57  }
58  wl_touch_send_cancel(d->resource);
59  d->client->flush();
60 }
61 
62 void TouchInterface::frame()
63 {
64  Q_D();
65  if (!d->resource) {
66  return;
67  }
68  wl_touch_send_frame(d->resource);
69  d->client->flush();
70 }
71 
72 void TouchInterface::move(qint32 id, const QPointF &localPos)
73 {
74  Q_D();
75  if (!d->resource) {
76  return;
77  }
78  if (d->seat->isDragTouch()) {
79  // handled by DataDevice
80  return;
81  }
82  wl_touch_send_motion(d->resource, d->seat->timestamp(), id, wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y()));
83  d->client->flush();
84 }
85 
86 void TouchInterface::up(qint32 id, quint32 serial)
87 {
88  Q_D();
89  if (!d->resource) {
90  return;
91  }
92  wl_touch_send_up(d->resource, serial, d->seat->timestamp(), id);
93  d->client->flush();
94 }
95 
96 void TouchInterface::down(qint32 id, quint32 serial, const QPointF &localPos)
97 {
98  Q_D();
99  if (!d->resource) {
100  return;
101  }
102  wl_touch_send_down(d->resource,
103  serial,
104  d->seat->timestamp(),
105  d->seat->focusedTouchSurface()->resource(),
106  id,
107  wl_fixed_from_double(localPos.x()),
108  wl_fixed_from_double(localPos.y()));
109  d->client->flush();
110 }
111 
112 TouchInterface::Private *TouchInterface::d_func() const
113 {
114  return reinterpret_cast<Private *>(d.data());
115 }
116 
117 }
118 }
wl_resource * parentResource() const
Definition: resource.cpp:91
qreal x() const const
qreal y() const const
T * data() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Sep 23 2021 22:51:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.