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
qwlqttouch.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 "qwlqttouch_p.h"
5#include "qwaylandview.h"
6#include <QPointingDevice>
7#include <QTouchEvent>
8#include <QWindow>
9
11
12namespace QtWayland {
13
14static const int maxRawPos = 24;
15
18 , QtWaylandServer::qt_touch_extension(compositor->display(), 1)
19 , m_compositor(compositor)
20 , m_posData(maxRawPos * 2)
21{
22}
23
27
28static inline int toFixed(qreal f)
29{
30 return int(f * 10000);
31}
32
34{
35 const QList<QTouchEvent::TouchPoint> points = event->points();
36 const int pointCount = points.size();
37 if (!pointCount)
38 return false;
39
40 wl_client *surfaceClient = surface->client()->client();
41 uint32_t time = m_compositor->currentTimeMsecs();
42 const int rescount = m_resources.size();
43
44 for (int res = 0; res < rescount; ++res) {
45 Resource *target = m_resources.at(res);
46 if (target->client() != surfaceClient)
47 continue;
48
49 // We will use no touch_frame type of event, to reduce the number of
50 // events flowing through the wire. Instead, the number of points sent is
51 // included in the touch point events.
52 int sentPointCount = 0;
53 for (int i = 0; i < pointCount; ++i) {
54 if (points.at(i).state() != QEventPoint::Stationary)
55 ++sentPointCount;
56 }
57
58 for (int i = 0; i < pointCount; ++i) {
59 const QTouchEvent::TouchPoint &tp(points.at(i));
60 // Stationary points are never sent. They are cached on client side.
62 continue;
63
64 uint32_t id = tp.id();
65 uint32_t state = (tp.state() & 0xFFFF) | (sentPointCount << 16);
66 uint32_t flags = (int(event->pointingDevice()->capabilities()) << 16);
67
68 int x = toFixed(tp.position().x());
69 int y = toFixed(tp.position().y());
70 int nx = toFixed(tp.normalizedPosition().x());
71 int ny = toFixed(tp.normalizedPosition().y());
72 int w = toFixed(tp.ellipseDiameters().width());
73 int h = toFixed(tp.ellipseDiameters().height());
74 int vx = toFixed(tp.velocity().x());
75 int vy = toFixed(tp.velocity().y());
76 uint32_t pressure = uint32_t(tp.pressure() * 255);
77
78 QByteArray rawData;
79 send_touch(target->handle,
80 time, id, state,
81 x, y, nx, ny, w, h,
82 pressure, vx, vy,
83 flags, rawData);
84 }
85
86 return true;
87 }
88
89 return false;
90}
91
93{
94 if (m_flags == flags)
95 return;
96
97 m_flags = flags;
99}
100
102{
103 m_resources.append(resource);
104 send_configure(resource->handle, m_flags);
105}
106
108{
109 m_resources.removeOne(resource);
110}
111
112}
113
115
116#include "moc_qwlqttouch_p.cpp"
\inmodule QtCore
Definition qbytearray.h:57
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
qreal pressure
the pressure of this point.
Definition qeventpoint.h:31
QPointF normalizedPosition() const
Returns the normalized position of this point.
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
QSizeF ellipseDiameters
the width and height of the bounding ellipse of the touch point.
Definition qeventpoint.h:33
QPointF position
the position of this point.
Definition qeventpoint.h:35
QVector2D velocity
a velocity vector, in units of pixels per second, in the coordinate.
Definition qeventpoint.h:34
qsizetype size() const noexcept
Definition qlist.h:397
bool removeOne(const AT &t)
Definition qlist.h:598
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void append(parameter_type t)
Definition qlist.h:458
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:502
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:501
wl_client * client() const
Returns the Wayland client of this QWaylandClient.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
QWaylandClient * client
\qmlproperty WaylandClient QtWayland.Compositor::WaylandSurface::client
TouchExtensionGlobal(QWaylandCompositor *compositor)
void setBehviorFlags(BehaviorFlags flags)
void touch_extension_bind_resource(Resource *resource) override
void touch_extension_destroy_resource(Resource *resource) override
bool postTouchEvent(QTouchEvent *event, QWaylandSurface *surface)
else opt state
[0]
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
static int toFixed(qreal f)
static const int maxRawPos
static QOpenGLCompositor * compositor
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat f
GLenum target
GLbitfield flags
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
GLbyte nx
GLuint res
GLfixed ny
double qreal
Definition qtypes.h:187