Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwaylandtouch.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:critical reason:network-protocol
4
5
#
include
"qwaylandtouch.h"
6
#
include
"qwaylandtouch_p.h"
7
8
#
include
<
QtWaylandCompositor
/
QWaylandCompositor
>
9
#
include
<
QtWaylandCompositor
/
QWaylandSeat
>
10
#
include
<
QtWaylandCompositor
/
QWaylandView
>
11
#
include
<
QtWaylandCompositor
/
QWaylandClient
>
12
13
QT_BEGIN_NAMESPACE
14
15
QWaylandTouchPrivate::QWaylandTouchPrivate(QWaylandTouch *touch, QWaylandSeat *seat)
16
: seat(seat)
17
{
18
Q_UNUSED(touch);
19
}
20
21
void
QWaylandTouchPrivate::touch_release(Resource *resource)
22
{
23
wl_resource_destroy(resource->handle);
24
}
25
26
uint QWaylandTouchPrivate::sendDown(QWaylandSurface *surface, uint32_t time,
int
touch_id,
const
QPointF &position)
27
{
28
Q_Q(QWaylandTouch);
29
auto
focusResource = resourceMap().value(surface->client()->client());
30
if
(!focusResource)
31
return
0;
32
33
uint32_t serial = q->compositor()->nextSerial();
34
35
wl_touch_send_down(focusResource->handle, serial, time, surface->resource(), touch_id,
36
wl_fixed_from_double(position.x()), wl_fixed_from_double(position.y()));
37
return
serial;
38
}
39
40
uint QWaylandTouchPrivate::sendUp(QWaylandClient *client, uint32_t time,
int
touch_id)
41
{
42
auto
focusResource = resourceMap().value(client->client());
43
44
if
(!focusResource)
45
return
0;
46
47
uint32_t serial = compositor()->nextSerial();
48
49
wl_touch_send_up(focusResource->handle, serial, time, touch_id);
50
return
serial;
51
}
52
53
void
QWaylandTouchPrivate::sendMotion(QWaylandClient *client, uint32_t time,
int
touch_id,
const
QPointF &position)
54
{
55
auto
focusResource = resourceMap().value(client->client());
56
57
if
(!focusResource)
58
return
;
59
60
wl_touch_send_motion(focusResource->handle, time, touch_id,
61
wl_fixed_from_double(position.x()), wl_fixed_from_double(position.y()));
62
}
63
64
int
QWaylandTouchPrivate::toSequentialWaylandId(
int
touchId)
65
{
66
const
int
waylandId = ids.indexOf(touchId);
67
if
(waylandId != -1)
68
return
waylandId;
69
const
int
availableId = ids.indexOf(-1);
70
if
(availableId != -1) {
71
ids[availableId] = touchId;
72
return
availableId;
73
}
74
ids.append(touchId);
75
return
ids.size() - 1;
76
}
77
78
/*!
79
* \class QWaylandTouch
80
* \inmodule QtWaylandCompositor
81
* \since 5.8
82
* \brief The QWaylandTouch class provides access to a touch device.
83
*
84
* This class provides access to the touch device in a QWaylandSeat. It corresponds to
85
* the Wayland interface wl_touch.
86
*/
87
88
/*!
89
* Constructs a QWaylandTouch for the \a seat and with the given \a parent.
90
*/
91
QWaylandTouch::QWaylandTouch(QWaylandSeat *seat, QObject *parent)
92
: QWaylandObject(*
new
QWaylandTouchPrivate(
this
, seat), parent)
93
{
94
}
95
96
/*!
97
* Returns the input device for this QWaylandTouch.
98
*/
99
QWaylandSeat *QWaylandTouch::seat()
const
100
{
101
Q_D(
const
QWaylandTouch);
102
return
d->seat;
103
}
104
105
/*!
106
* Returns the compositor for this QWaylandTouch.
107
*/
108
QWaylandCompositor *QWaylandTouch::compositor()
const
109
{
110
Q_D(
const
QWaylandTouch);
111
return
d->compositor();
112
}
113
114
/*!
115
* Sends a touch point event to the touch device of \a surface with the given \a id,
116
* \a position, and \a state.
117
*
118
* Returns the serial of the down or up event if sent, otherwise 0.
119
*/
120
uint QWaylandTouch::sendTouchPointEvent(QWaylandSurface *surface,
int
id,
const
QPointF &position, Qt::TouchPointState state)
121
{
122
Q_D(QWaylandTouch);
123
uint32_t time = compositor()->currentTimeMsecs();
124
uint serial = 0;
125
switch
(state) {
126
case
Qt::TouchPointPressed:
127
serial = d->sendDown(surface, time, id, position);
128
break
;
129
case
Qt::TouchPointMoved:
130
d->sendMotion(surface->client(), time, id, position);
131
break
;
132
case
Qt::TouchPointReleased:
133
serial = d->sendUp(surface->client(), time, id);
134
break
;
135
case
Qt::TouchPointStationary:
136
// stationary points are not sent through wayland, the client must cache them
137
break
;
138
case
Qt::TouchPointUnknownState:
139
// Ignored
140
break
;
141
}
142
143
return
serial;
144
}
145
146
/*!
147
* Sends a touch frame event to the touch device of a \a client. This indicates the end of a
148
* contact point list.
149
*/
150
void
QWaylandTouch::sendFrameEvent(QWaylandClient *client)
151
{
152
Q_D(QWaylandTouch);
153
auto
focusResource = d->resourceMap().value(client->client());
154
if
(focusResource)
155
d->send_frame(focusResource->handle);
156
}
157
158
/*!
159
* Sends a touch cancel event to the touch device of a \a client.
160
*/
161
void
QWaylandTouch::sendCancelEvent(QWaylandClient *client)
162
{
163
Q_D(QWaylandTouch);
164
auto
focusResource = d->resourceMap().value(client->client());
165
if
(focusResource)
166
d->send_cancel(focusResource->handle);
167
}
168
169
/*!
170
* Sends all touch points in \a event to the specified \a surface,
171
* followed by a touch frame event.
172
*
173
* \sa sendTouchPointEvent(), sendFrameEvent()
174
*/
175
void
QWaylandTouch::sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *event)
176
{
177
Q_D(QWaylandTouch);
178
if
(event->type() == QEvent::TouchCancel) {
179
sendCancelEvent(surface->client());
180
return
;
181
}
182
183
const
QList<QTouchEvent::TouchPoint> points = event->points();
184
if
(points.isEmpty())
185
return
;
186
187
const
int
pointCount = points.size();
188
for
(
int
i = 0; i < pointCount; ++i) {
189
const
QTouchEvent::TouchPoint &tp(points.at(i));
190
// Convert the local pos in the compositor window to surface-relative.
191
const
int
id = d->toSequentialWaylandId(tp.id());
192
sendTouchPointEvent(surface, id, tp.position(), Qt::TouchPointState(tp.state()));
193
if
(tp.state() == QEventPoint::Released)
194
d->ids[id] = -1;
195
}
196
sendFrameEvent(surface->client());
197
}
198
199
/*!
200
* \internal
201
*/
202
void
QWaylandTouch::addClient(QWaylandClient *client, uint32_t id, uint32_t version)
203
{
204
Q_D(QWaylandTouch);
205
d->add(client->client(), id, qMin<uint32_t>(QtWaylandServer::wl_touch::interfaceVersion(), version));
206
}
207
208
QT_END_NAMESPACE
209
210
#
include
"moc_qwaylandtouch.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtwayland
src
compositor
compositor_api
qwaylandtouch.cpp
Generated on
for Qt by
1.18.0