KWaylandServer

touch_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3  SPDX-FileCopyrightText: 2020 Adrien Faveraux <[email protected]>
4  SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 #include "touch_interface.h"
9 #include "clientconnection.h"
10 #include "display.h"
11 #include "seat_interface.h"
12 #include "surface_interface.h"
13 #include "touch_interface_p.h"
14 
15 namespace KWaylandServer
16 {
17 TouchInterfacePrivate *TouchInterfacePrivate::get(TouchInterface *touch)
18 {
19  return touch->d.data();
20 }
21 
22 TouchInterfacePrivate::TouchInterfacePrivate(TouchInterface *q, SeatInterface *seat)
23  : q(q)
24  , seat(seat)
25 {
26 }
27 
28 void TouchInterfacePrivate::touch_release(Resource *resource)
29 {
30  wl_resource_destroy(resource->handle);
31 }
32 
33 QList<TouchInterfacePrivate::Resource *> TouchInterfacePrivate::touchesForClient(ClientConnection *client) const
34 {
35  return resourceMap().values(client->client());
36 }
37 
38 TouchInterface::TouchInterface(SeatInterface *seat)
39  : d(new TouchInterfacePrivate(this, seat))
40 {
41 }
42 
43 TouchInterface::~TouchInterface()
44 {
45 }
46 
47 SurfaceInterface *TouchInterface::focusedSurface() const
48 {
49  return d->focusedSurface;
50 }
51 
52 void TouchInterface::setFocusedSurface(SurfaceInterface *surface)
53 {
54  d->focusedSurface = surface;
55 }
56 
57 void TouchInterface::sendCancel()
58 {
59  if (!d->focusedSurface) {
60  return;
61  }
62 
63  const auto touchResources = d->touchesForClient(d->focusedSurface->client());
64  for (TouchInterfacePrivate::Resource *resource : touchResources) {
65  d->send_cancel(resource->handle);
66  }
67 }
68 
69 void TouchInterface::sendFrame()
70 {
71  if (!d->focusedSurface) {
72  return;
73  }
74 
75  const auto touchResources = d->touchesForClient(d->focusedSurface->client());
76  for (TouchInterfacePrivate::Resource *resource : touchResources) {
77  d->send_frame(resource->handle);
78  }
79 }
80 
81 void TouchInterface::sendMotion(qint32 id, const QPointF &localPos)
82 {
83  if (!d->focusedSurface) {
84  return;
85  }
86 
87  const auto touchResources = d->touchesForClient(d->focusedSurface->client());
88  for (TouchInterfacePrivate::Resource *resource : touchResources) {
89  d->send_motion(resource->handle, d->seat->timestamp(), id, wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y()));
90  }
91 }
92 
93 void TouchInterface::sendUp(qint32 id, quint32 serial)
94 {
95  if (!d->focusedSurface) {
96  return;
97  }
98 
99  const auto touchResources = d->touchesForClient(d->focusedSurface->client());
100  for (TouchInterfacePrivate::Resource *resource : touchResources) {
101  d->send_up(resource->handle, serial, d->seat->timestamp(), id);
102  }
103 }
104 
105 void TouchInterface::sendDown(qint32 id, quint32 serial, const QPointF &localPos)
106 {
107  if (!d->focusedSurface) {
108  return;
109  }
110 
111  const auto touchResources = d->touchesForClient(d->focusedSurface->client());
112  for (TouchInterfacePrivate::Resource *resource : touchResources) {
113  d->send_down(resource->handle,
114  serial,
115  d->seat->timestamp(),
116  d->focusedSurface->resource(),
117  id,
118  wl_fixed_from_double(localPos.x()),
119  wl_fixed_from_double(localPos.y()));
120  }
121 }
122 
123 } // namespace KWaylandServer
qreal x() const const
qreal y() const const
QPointer< SurfaceInterface > surface() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 23:08:29 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.