KWin
Loading...
Searching...
No Matches
touch.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
3 SPDX-FileCopyrightText: 2020 Adrien Faveraux <ad1rie3@hotmail.fr>
4 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8#include "touch.h"
9#include "clientconnection.h"
10#include "display.h"
11#include "seat.h"
12#include "surface.h"
13#include "touch_p.h"
14
15namespace KWin
16{
18{
19 return touch->d.get();
20}
21
27
29{
30 wl_resource_destroy(resource->handle);
31}
32
33QList<TouchInterfacePrivate::Resource *> TouchInterfacePrivate::touchesForClient(ClientConnection *client) const
34{
35 return resourceMap().values(client->client());
36}
37
39{
40 return resourceMap().contains(client->client());
41}
42
43TouchInterface::TouchInterface(SeatInterface *seat)
44 : d(new TouchInterfacePrivate(this, seat))
45{
46}
47
51
53{
54 return d->focusedSurface;
55}
56
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
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
81void TouchInterface::sendMotion(qint32 id, const QPointF &localPos)
82{
83 if (!d->focusedSurface) {
84 return;
85 }
86
87 QPointF pos = d->focusedSurface->toSurfaceLocal(localPos);
88
89 const auto touchResources = d->touchesForClient(d->focusedSurface->client());
90 for (TouchInterfacePrivate::Resource *resource : touchResources) {
91 d->send_motion(resource->handle, d->seat->timestamp().count(), id, wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
92 }
93}
94
95void TouchInterface::sendUp(qint32 id, quint32 serial)
96{
97 if (!d->focusedSurface) {
98 return;
99 }
100
101 const auto touchResources = d->touchesForClient(d->focusedSurface->client());
102 for (TouchInterfacePrivate::Resource *resource : touchResources) {
103 d->send_up(resource->handle, serial, d->seat->timestamp().count(), id);
104 }
105}
106
107void TouchInterface::sendDown(qint32 id, quint32 serial, const QPointF &localPos, SurfaceInterface *surface)
108{
109 if (!surface) {
110 return;
111 }
112
113 d->focusedSurface = surface;
114
115 QPointF pos = d->focusedSurface->toSurfaceLocal(localPos);
116
117 const auto touchResources = d->touchesForClient(d->focusedSurface->client());
118 for (TouchInterfacePrivate::Resource *resource : touchResources) {
119 d->send_down(resource->handle,
120 serial,
121 d->seat->timestamp().count(),
122 d->focusedSurface->resource(),
123 id,
124 wl_fixed_from_double(pos.x()),
125 wl_fixed_from_double(pos.y()));
126 }
127}
128
129} // namespace KWin
130
131#include "moc_touch.cpp"
Convenient Class which represents a wl_client.
wl_client * client() const
Represents a Seat on the Wayland Display.
Definition seat.h:134
Resource representing a wl_surface.
Definition surface.h:80
void sendMotion(qint32 id, const QPointF &localPos)
Definition touch.cpp:81
void sendUp(qint32 id, quint32 serial)
Definition touch.cpp:95
SurfaceInterface * focusedSurface() const
Definition touch.cpp:52
void sendDown(qint32 id, quint32 serial, const QPointF &localPos, SurfaceInterface *surface)
Definition touch.cpp:107
~TouchInterface() override
Definition touch.cpp:48
QList< Resource * > touchesForClient(ClientConnection *client) const
Definition touch.cpp:33
static TouchInterfacePrivate * get(TouchInterface *touch)
Definition touch.cpp:17
TouchInterfacePrivate(TouchInterface *q, SeatInterface *seat)
Definition touch.cpp:22
bool hasTouchesForClient(ClientConnection *client) const
Definition touch.cpp:38
void touch_release(Resource *resource) override
Definition touch.cpp:28