Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qwaylandtouch.h"
5#include "qwaylandtouch_p.h"
6
7#include <QtWaylandCompositor/QWaylandCompositor>
8#include <QtWaylandCompositor/QWaylandSeat>
9#include <QtWaylandCompositor/QWaylandView>
10#include <QtWaylandCompositor/QWaylandClient>
11
12#include <QtWaylandCompositor/private/qwlqttouch_p.h>
13
15
17 : seat(seat)
18{
19 Q_UNUSED(touch);
20}
21
23{
24 wl_resource_destroy(resource->handle);
25}
26
28{
29 Q_Q(QWaylandTouch);
30 auto focusResource = resourceMap().value(surface->client()->client());
31 if (!focusResource)
32 return 0;
33
34 uint32_t serial = q->compositor()->nextSerial();
35
36 wl_touch_send_down(focusResource->handle, serial, time, surface->resource(), touch_id,
37 wl_fixed_from_double(position.x()), wl_fixed_from_double(position.y()));
38 return serial;
39}
40
41uint QWaylandTouchPrivate::sendUp(QWaylandClient *client, uint32_t time, int touch_id)
42{
43 auto focusResource = resourceMap().value(client->client());
44
45 if (!focusResource)
46 return 0;
47
48 uint32_t serial = compositor()->nextSerial();
49
50 wl_touch_send_up(focusResource->handle, serial, time, touch_id);
51 return serial;
52}
53
54void QWaylandTouchPrivate::sendMotion(QWaylandClient *client, uint32_t time, int touch_id, const QPointF &position)
55{
56 auto focusResource = resourceMap().value(client->client());
57
58 if (!focusResource)
59 return;
60
61 wl_touch_send_motion(focusResource->handle, time, touch_id,
62 wl_fixed_from_double(position.x()), wl_fixed_from_double(position.y()));
63}
64
65int QWaylandTouchPrivate::toSequentialWaylandId(int touchId)
66{
67 const int waylandId = ids.indexOf(touchId);
68 if (waylandId != -1)
69 return waylandId;
70 const int availableId = ids.indexOf(-1);
71 if (availableId != -1) {
72 ids[availableId] = touchId;
73 return availableId;
74 }
75 ids.append(touchId);
76 return ids.size() - 1;
77}
78
96
101{
102 Q_D(const QWaylandTouch);
103 return d->seat;
104}
105
110{
111 Q_D(const QWaylandTouch);
112 return d->compositor();
113}
114
122{
123 Q_D(QWaylandTouch);
124 uint32_t time = compositor()->currentTimeMsecs();
125 uint serial = 0;
126 switch (state) {
128 serial = d->sendDown(surface, time, id, position);
129 break;
131 d->sendMotion(surface->client(), time, id, position);
132 break;
134 serial = d->sendUp(surface->client(), time, id);
135 break;
137 // stationary points are not sent through wayland, the client must cache them
138 break;
140 // Ignored
141 break;
142 }
143
144 return serial;
145}
146
152{
153 Q_D(QWaylandTouch);
154 auto focusResource = d->resourceMap().value(client->client());
155 if (focusResource)
156 d->send_frame(focusResource->handle);
157}
158
163{
164 Q_D(QWaylandTouch);
165 auto focusResource = d->resourceMap().value(client->client());
166 if (focusResource)
167 d->send_cancel(focusResource->handle);
168}
169
177{
178 Q_D(QWaylandTouch);
179 if (event->type() == QEvent::TouchCancel) {
180 sendCancelEvent(surface->client());
181 return;
182 }
183
185 if (ext && ext->postTouchEvent(event, surface))
186 return;
187
188 const QList<QTouchEvent::TouchPoint> points = event->points();
189 if (points.isEmpty())
190 return;
191
192 const int pointCount = points.size();
193 for (int i = 0; i < pointCount; ++i) {
194 const QTouchEvent::TouchPoint &tp(points.at(i));
195 // Convert the local pos in the compositor window to surface-relative.
196 const int id = d->toSequentialWaylandId(tp.id());
197 sendTouchPointEvent(surface, id, tp.position(), Qt::TouchPointState(tp.state()));
198 if (tp.state() == QEventPoint::Released)
199 d->ids[id] = -1;
200 }
201 sendFrameEvent(surface->client());
202}
203
207void QWaylandTouch::addClient(QWaylandClient *client, uint32_t id, uint32_t version)
208{
209 Q_D(QWaylandTouch);
210 d->add(client->client(), id, qMin<uint32_t>(QtWaylandServer::wl_touch::interfaceVersion(), version));
211}
212
214
215#include "moc_qwaylandtouch.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
int id
the ID number of this event point.
Definition qeventpoint.h:24
State state
the current state of the event point.
Definition qeventpoint.h:26
QPointF position
the position of this point.
Definition qeventpoint.h:35
@ TouchCancel
Definition qcoreevent.h:264
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
\qmltype WaylandClient \instantiates QWaylandClient \inqmlmodule QtWayland.Compositor
wl_client * client() const
Returns the Wayland client of this QWaylandClient.
static TouchExtensionGlobal * findIn(QWaylandObject *container)
If any instance of the interface has been registered with container, this is returned.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
\inmodule QtWaylandCompositor
\qmltype WaylandSeat \instantiates QWaylandSeat \inqmlmodule QtWayland.Compositor
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
struct wl_resource * resource() const
Returns the Wayland resource corresponding to this QWaylandSurface.
QWaylandClient * client
\qmlproperty WaylandClient QtWayland.Compositor::WaylandSurface::client
void touch_release(Resource *resource) override
QWaylandCompositor * compositor() const
QWaylandTouchPrivate(QWaylandTouch *touch, QWaylandSeat *seat)
uint sendDown(QWaylandSurface *surface, uint32_t time, int touch_id, const QPointF &position)
void sendMotion(QWaylandClient *client, uint32_t time, int touch_id, const QPointF &position)
uint sendUp(QWaylandClient *client, uint32_t time, int touch_id)
\inmodule QtWaylandCompositor
virtual void sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *event)
Sends all touch points in event to the specified surface, followed by a touch frame event.
virtual uint sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &position, Qt::TouchPointState state)
Sends a touch point event to the touch device of surface with the given id, position,...
virtual void sendFrameEvent(QWaylandClient *client)
Sends a touch frame event to the touch device of a client.
QWaylandSeat * seat() const
Returns the input device for this QWaylandTouch.
virtual void sendCancelEvent(QWaylandClient *client)
Sends a touch cancel event to the touch device of a client.
virtual void addClient(QWaylandClient *client, uint32_t id, uint32_t version)
QWaylandTouch(QWaylandSeat *seat, QObject *parent=nullptr)
Constructs a QWaylandTouch for the seat and with the given parent.
QWaylandCompositor * compositor() const
Returns the compositor for this QWaylandTouch.
bool postTouchEvent(QTouchEvent *event, QWaylandSurface *surface)
#define this
Definition dialogs.cpp:9
else opt state
[0]
Combined button and popup list for selecting options.
TouchPointState
@ TouchPointReleased
@ TouchPointStationary
@ TouchPointPressed
@ TouchPointMoved
@ TouchPointUnknownState
GLenum GLenum GLsizei const GLuint * ids
GLenum GLuint id
[7]
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34