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

KDE's Doxygen guidelines are available online.