qevdevtouchhandler.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the plugins module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qevdevtouchhandler_p.h"-
35#include <QStringList>-
36#include <QHash>-
37#include <QSocketNotifier>-
38#include <QGuiApplication>-
39#include <QLoggingCategory>-
40#include <QtCore/private/qcore_unix_p.h>-
41#include <QtGui/private/qhighdpiscaling_p.h>-
42#include <QtGui/private/qguiapplication_p.h>-
43#include <linux/input.h>-
44-
45#if !defined(QT_NO_MTDEV)-
46extern "C" {-
47#include <mtdev.h>-
48}-
49#endif-
50-
51QT_BEGIN_NAMESPACE-
52-
53Q_LOGGING_CATEGORY(qLcEvdevTouch, "qt.qpa.input")
never executed: return category;
0
54-
55/* android (and perhaps some other linux-derived stuff) don't define everything-
56 * in linux/input.h, so we'll need to do that ourselves.-
57 */-
58#ifndef ABS_MT_TOUCH_MAJOR-
59#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */-
60#endif-
61#ifndef ABS_MT_POSITION_X-
62#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */-
63#endif-
64#ifndef ABS_MT_POSITION_Y-
65#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */-
66#endif-
67#ifndef ABS_MT_SLOT-
68#define ABS_MT_SLOT 0x2f-
69#endif-
70#ifndef ABS_CNT-
71#define ABS_CNT (ABS_MAX+1)-
72#endif-
73#ifndef ABS_MT_TRACKING_ID-
74#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */-
75#endif-
76#ifndef SYN_MT_REPORT-
77#define SYN_MT_REPORT 2-
78#endif-
79-
80class QEvdevTouchScreenData-
81{-
82public:-
83 QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, const QStringList &args);-
84-
85 void processInputEvent(input_event *data);-
86 void assignIds();-
87-
88 QEvdevTouchScreenHandler *q;-
89 int m_lastEventType;-
90 QList<QWindowSystemInterface::TouchPoint> m_touchPoints;-
91-
92 struct Contact {-
93 int trackingId;-
94 int x;-
95 int y;-
96 int maj;-
97 int pressure;-
98 Qt::TouchPointState state;-
99 QTouchEvent::TouchPoint::InfoFlags flags;-
100 Contact() : trackingId(-1),-
101 x(0), y(0), maj(-1), pressure(0),-
102 state(Qt::TouchPointPressed), flags(0) { }
never executed: end of block
0
103 };-
104 QHash<int, Contact> m_contacts; // The key is a tracking id for type A, slot number for type B.-
105 QHash<int, Contact> m_lastContacts;-
106 Contact m_currentData;-
107 int m_currentSlot;-
108-
109 int findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist);-
110 void addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates);-
111 void reportPoints();-
112-
113 int hw_range_x_min;-
114 int hw_range_x_max;-
115 int hw_range_y_min;-
116 int hw_range_y_max;-
117 int hw_pressure_min;-
118 int hw_pressure_max;-
119 QString hw_name;-
120 bool m_forceToActiveWindow;-
121 bool m_typeB;-
122 QTransform m_rotate;-
123 bool m_singleTouch;-
124};-
125-
126QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, const QStringList &args)-
127 : q(q_ptr),-
128 m_lastEventType(-1),-
129 m_currentSlot(0),-
130 hw_range_x_min(0), hw_range_x_max(0),-
131 hw_range_y_min(0), hw_range_y_max(0),-
132 hw_pressure_min(0), hw_pressure_max(0),-
133 m_typeB(false), m_singleTouch(false)-
134{-
135 m_forceToActiveWindow = args.contains(QLatin1String("force_window"));-
136}
never executed: end of block
0
137-
138#define LONG_BITS (sizeof(long) << 3)-
139#define NUM_LONGS(bits) (((bits) + LONG_BITS - 1) / LONG_BITS)-
140-
141#if defined(QT_NO_MTDEV)-
142static inline bool testBit(long bit, const long *array)-
143{-
144 return (array[bit / LONG_BITS] >> bit % LONG_BITS) & 1;-
145}-
146#endif-
147-
148QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const QString &spec, QObject *parent)-
149 : QObject(parent), m_notify(Q_NULLPTR), m_fd(-1), d(Q_NULLPTR), m_device(Q_NULLPTR)-
150#if !defined(QT_NO_MTDEV)-
151 , m_mtdev(Q_NULLPTR)-
152#endif-
153{-
154 setObjectName(QLatin1String("Evdev Touch Handler"));-
155-
156 const QStringList args = spec.split(QLatin1Char(':'));-
157 int rotationAngle = 0;-
158 bool invertx = false;-
159 bool inverty = false;-
160 for (int i = 0; i < args.count(); ++i) {
i < args.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
161 if (args.at(i).startsWith(QLatin1String("rotate"))) {
args.at(i).sta...ing("rotate"))Description
TRUEnever evaluated
FALSEnever evaluated
0
162 QString rotateArg = args.at(i).section(QLatin1Char('='), 1, 1);-
163 bool ok;-
164 uint argValue = rotateArg.toUInt(&ok);-
165 if (ok) {
okDescription
TRUEnever evaluated
FALSEnever evaluated
0
166 switch (argValue) {-
167 case 90:
never executed: case 90:
0
168 case 180:
never executed: case 180:
0
169 case 270:
never executed: case 270:
0
170 rotationAngle = argValue;-
171 default:
code before this statement never executed: default:
never executed: default:
0
172 break;
never executed: break;
0
173 }-
174 }-
175 } else if (args.at(i) == QLatin1String("invertx")) {
never executed: end of block
args.at(i) == ...ing("invertx")Description
TRUEnever evaluated
FALSEnever evaluated
0
176 invertx = true;-
177 } else if (args.at(i) == QLatin1String("inverty")) {
never executed: end of block
args.at(i) == ...ing("inverty")Description
TRUEnever evaluated
FALSEnever evaluated
0
178 inverty = true;-
179 }
never executed: end of block
0
180 }
never executed: end of block
0
181-
182 qCDebug(qLcEvdevTouch, "evdevtouch: Using device %s", qPrintable(device));
never executed: QMessageLogger(__FILE__, 182, __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: Using device %s", QString(device).toLocal8Bit().constData());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
183-
184 m_fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0);-
185-
186 if (m_fd >= 0) {
m_fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
187 m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);-
188 connect(m_notify, SIGNAL(activated(int)), this, SLOT(readData()));-
189 } else {
never executed: end of block
0
190 qErrnoWarning(errno, "evdevtouch: Cannot open input device %s", qPrintable(device));-
191 return;
never executed: return;
0
192 }-
193-
194#if !defined(QT_NO_MTDEV)-
195 m_mtdev = static_cast<mtdev *>(calloc(1, sizeof(mtdev)));-
196 int mtdeverr = mtdev_open(m_mtdev, m_fd);-
197 if (mtdeverr) {
mtdeverrDescription
TRUEnever evaluated
FALSEnever evaluated
0
198 qWarning("evdevtouch: mtdev_open failed: %d", mtdeverr);-
199 QT_CLOSE(m_fd);-
200 return;
never executed: return;
0
201 }-
202#endif-
203-
204 d = new QEvdevTouchScreenData(this, args);-
205-
206#if !defined(QT_NO_MTDEV)-
207 const char *mtdevStr = "(mtdev)";-
208 d->m_typeB = true;-
209#else-
210 const char *mtdevStr = "";-
211 long absbits[NUM_LONGS(ABS_CNT)];-
212 if (ioctl(m_fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) >= 0) {-
213 d->m_typeB = testBit(ABS_MT_SLOT, absbits);-
214 d->m_singleTouch = !testBit(ABS_MT_POSITION_X, absbits);-
215 }-
216#endif-
217-
218 qCDebug(qLcEvdevTouch, "evdevtouch: %s: Protocol type %c %s (%s)", qPrintable(device),
never executed: QMessageLogger( __FILE__ , 219 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: Protocol type %c %s (%s)", QString(device).toLocal8Bit().constData(), d->m_typeB ? 'B' : 'A', mtdevStr, d->m_singleTouch ? "single" : "multi") ;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 d->m_typeB ? 'B' : 'A', mtdevStr, d->m_singleTouch ? "single" : "multi");
never executed: QMessageLogger( __FILE__ , 219 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: Protocol type %c %s (%s)", QString(device).toLocal8Bit().constData(), d->m_typeB ? 'B' : 'A', mtdevStr, d->m_singleTouch ? "single" : "multi") ;
0
220-
221 input_absinfo absInfo;-
222 memset(&absInfo, 0, sizeof(input_absinfo));-
223 bool has_x_range = false, has_y_range = false;-
224-
225 if (ioctl(m_fd, EVIOCGABS((d->m_singleTouch ? ABS_X : ABS_MT_POSITION_X)), &absInfo) >= 0) {
ioctl(m_fd, ((...&absInfo) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
226 qCDebug(qLcEvdevTouch, "evdevtouch: %s: min X: %d max X: %d", qPrintable(device),
never executed: QMessageLogger( __FILE__ , 227 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: min X: %d max X: %d", QString(device).toLocal8Bit().constData(), absInfo.minimum, absInfo.maximum) ;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
227 absInfo.minimum, absInfo.maximum);
never executed: QMessageLogger( __FILE__ , 227 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: min X: %d max X: %d", QString(device).toLocal8Bit().constData(), absInfo.minimum, absInfo.maximum) ;
0
228 d->hw_range_x_min = absInfo.minimum;-
229 d->hw_range_x_max = absInfo.maximum;-
230 has_x_range = true;-
231 }
never executed: end of block
0
232-
233 if (ioctl(m_fd, EVIOCGABS((d->m_singleTouch ? ABS_Y : ABS_MT_POSITION_Y)), &absInfo) >= 0) {
ioctl(m_fd, ((...&absInfo) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
234 qCDebug(qLcEvdevTouch, "evdevtouch: %s: min Y: %d max Y: %d", qPrintable(device),
never executed: QMessageLogger( __FILE__ , 235 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: min Y: %d max Y: %d", QString(device).toLocal8Bit().constData(), absInfo.minimum, absInfo.maximum) ;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
235 absInfo.minimum, absInfo.maximum);
never executed: QMessageLogger( __FILE__ , 235 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: min Y: %d max Y: %d", QString(device).toLocal8Bit().constData(), absInfo.minimum, absInfo.maximum) ;
0
236 d->hw_range_y_min = absInfo.minimum;-
237 d->hw_range_y_max = absInfo.maximum;-
238 has_y_range = true;-
239 }
never executed: end of block
0
240-
241 if (!has_x_range || !has_y_range)
!has_x_rangeDescription
TRUEnever evaluated
FALSEnever evaluated
!has_y_rangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
242 qWarning("evdevtouch: %s: Invalid ABS limits, behavior unspecified", qPrintable(device));
never executed: QMessageLogger(__FILE__, 242, __PRETTY_FUNCTION__).warning("evdevtouch: %s: Invalid ABS limits, behavior unspecified", QString(device).toLocal8Bit().constData());
0
243-
244 if (ioctl(m_fd, EVIOCGABS(ABS_PRESSURE), &absInfo) >= 0) {
ioctl(m_fd, ((...&absInfo) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
245 qCDebug(qLcEvdevTouch, "evdevtouch: %s: min pressure: %d max pressure: %d", qPrintable(device),
never executed: QMessageLogger( __FILE__ , 246 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: min pressure: %d max pressure: %d", QString(device).toLocal8Bit().constData(), absInfo.minimum, absInfo.maximum) ;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
246 absInfo.minimum, absInfo.maximum);
never executed: QMessageLogger( __FILE__ , 246 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: min pressure: %d max pressure: %d", QString(device).toLocal8Bit().constData(), absInfo.minimum, absInfo.maximum) ;
0
247 if (absInfo.maximum > absInfo.minimum) {
absInfo.maximu...bsInfo.minimumDescription
TRUEnever evaluated
FALSEnever evaluated
0
248 d->hw_pressure_min = absInfo.minimum;-
249 d->hw_pressure_max = absInfo.maximum;-
250 }
never executed: end of block
0
251 }
never executed: end of block
0
252-
253 char name[1024];-
254 if (ioctl(m_fd, EVIOCGNAME(sizeof(name) - 1), name) >= 0) {
ioctl(m_fd, ((...)), name) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
255 d->hw_name = QString::fromLocal8Bit(name);-
256 qCDebug(qLcEvdevTouch, "evdevtouch: %s: device name: %s", qPrintable(device), name);
never executed: QMessageLogger(__FILE__, 256, __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: %s: device name: %s", QString(device).toLocal8Bit().constData(), name);
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
257 }
never executed: end of block
0
258-
259 // Fix up the coordinate ranges for am335x in case the kernel driver does not have them fixed.-
260 if (d->hw_name == QLatin1String("ti-tsc")) {
d->hw_name == ...ring("ti-tsc")Description
TRUEnever evaluated
FALSEnever evaluated
0
261 if (d->hw_range_x_min == 0 && d->hw_range_x_max == 4095) {
d->hw_range_x_min == 0Description
TRUEnever evaluated
FALSEnever evaluated
d->hw_range_x_max == 4095Description
TRUEnever evaluated
FALSEnever evaluated
0
262 d->hw_range_x_min = 165;-
263 d->hw_range_x_max = 4016;-
264 }
never executed: end of block
0
265 if (d->hw_range_y_min == 0 && d->hw_range_y_max == 4095) {
d->hw_range_y_min == 0Description
TRUEnever evaluated
FALSEnever evaluated
d->hw_range_y_max == 4095Description
TRUEnever evaluated
FALSEnever evaluated
0
266 d->hw_range_y_min = 220;-
267 d->hw_range_y_max = 3907;-
268 }
never executed: end of block
0
269 qCDebug(qLcEvdevTouch, "evdevtouch: found ti-tsc, overriding: min X: %d max X: %d min Y: %d max Y: %d",
never executed: QMessageLogger( __FILE__ , 270 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: found ti-tsc, overriding: min X: %d max X: %d min Y: %d max Y: %d", d->hw_range_x_min, d->hw_range_x_max, d->hw_range_y_min, d->hw_range_y_max) ;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
270 d->hw_range_x_min, d->hw_range_x_max, d->hw_range_y_min, d->hw_range_y_max);
never executed: QMessageLogger( __FILE__ , 270 , __PRETTY_FUNCTION__, qLcEvdevTouch().categoryName()).debug("evdevtouch: found ti-tsc, overriding: min X: %d max X: %d min Y: %d max Y: %d", d->hw_range_x_min, d->hw_range_x_max, d->hw_range_y_min, d->hw_range_y_max) ;
0
271 }
never executed: end of block
0
272-
273 bool grabSuccess = !ioctl(m_fd, EVIOCGRAB, (void *) 1);-
274 if (grabSuccess)
grabSuccessDescription
TRUEnever evaluated
FALSEnever evaluated
0
275 ioctl(m_fd, EVIOCGRAB, (void *) 0);
never executed: ioctl(m_fd, (((1U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x90)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) 0);
0
276 else-
277 qWarning("evdevtouch: The device is grabbed by another process. No events will be read.");
never executed: QMessageLogger(__FILE__, 277, __PRETTY_FUNCTION__).warning("evdevtouch: The device is grabbed by another process. No events will be read.");
0
278-
279 if (rotationAngle)
rotationAngleDescription
TRUEnever evaluated
FALSEnever evaluated
0
280 d->m_rotate = QTransform::fromTranslate(0.5, 0.5).rotate(rotationAngle).translate(-0.5, -0.5);
never executed: d->m_rotate = QTransform::fromTranslate(0.5, 0.5).rotate(rotationAngle).translate(-0.5, -0.5);
0
281-
282 if (invertx)
invertxDescription
TRUEnever evaluated
FALSEnever evaluated
0
283 d->m_rotate *= QTransform::fromTranslate(0.5, 0.5).scale(-1.0, 1.0).translate(-0.5, -0.5);
never executed: d->m_rotate *= QTransform::fromTranslate(0.5, 0.5).scale(-1.0, 1.0).translate(-0.5, -0.5);
0
284-
285 if (inverty)
invertyDescription
TRUEnever evaluated
FALSEnever evaluated
0
286 d->m_rotate *= QTransform::fromTranslate(0.5, 0.5).scale(1.0, -1.0).translate(-0.5, -0.5);
never executed: d->m_rotate *= QTransform::fromTranslate(0.5, 0.5).scale(1.0, -1.0).translate(-0.5, -0.5);
0
287-
288 registerTouchDevice();-
289}
never executed: end of block
0
290-
291QEvdevTouchScreenHandler::~QEvdevTouchScreenHandler()-
292{-
293#if !defined(QT_NO_MTDEV)-
294 if (m_mtdev) {
m_mtdevDescription
TRUEnever evaluated
FALSEnever evaluated
0
295 mtdev_close(m_mtdev);-
296 free(m_mtdev);-
297 }
never executed: end of block
0
298#endif-
299-
300 if (m_fd >= 0)
m_fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
301 QT_CLOSE(m_fd);
never executed: qt_safe_close(m_fd);
0
302-
303 delete d;-
304-
305 unregisterTouchDevice();-
306}
never executed: end of block
0
307-
308QTouchDevice *QEvdevTouchScreenHandler::touchDevice() const-
309{-
310 return m_device;
never executed: return m_device;
0
311}-
312-
313void QEvdevTouchScreenHandler::readData()-
314{-
315 ::input_event buffer[32];-
316 int events = 0;-
317-
318#if !defined(QT_NO_MTDEV)-
319 forever {-
320 do {-
321 events = mtdev_get(m_mtdev, m_fd, buffer, sizeof(buffer) / sizeof(::input_event));-
322 // keep trying mtdev_get if we get interrupted. note that we do not-
323 // (and should not) handle EAGAIN; EAGAIN means that reading would-
324 // block and we'll get back here later to try again anyway.-
325 } while (events == -1 && errno == EINTR);
never executed: end of block
events == -1Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
0
326-
327 // 0 events is EOF, -1 means error, handle both in the same place-
328 if (events <= 0)
events <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
329 goto err;
never executed: goto err;
0
330-
331 // process our shiny new events-
332 for (int i = 0; i < events; ++i)
i < eventsDescription
TRUEnever evaluated
FALSEnever evaluated
0
333 d->processInputEvent(&buffer[i]);
never executed: d->processInputEvent(&buffer[i]);
0
334-
335 // and try to get more-
336 }
never executed: end of block
0
337#else-
338 int n = 0;-
339 for (; ;) {-
340 events = QT_READ(m_fd, reinterpret_cast<char*>(buffer) + n, sizeof(buffer) - n);-
341 if (events <= 0)-
342 goto err;-
343 n += events;-
344 if (n % sizeof(::input_event) == 0)-
345 break;-
346 }-
347-
348 n /= sizeof(::input_event);-
349-
350 for (int i = 0; i < n; ++i)-
351 d->processInputEvent(&buffer[i]);-
352#endif-
353 return;
never executed: return;
0
354-
355err:-
356 if (!events) {
!eventsDescription
TRUEnever evaluated
FALSEnever evaluated
0
357 qWarning("evdevtouch: Got EOF from input device");-
358 return;
never executed: return;
0
359 } else if (events < 0) {
events < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
360 if (errno != EINTR && errno != EAGAIN) {
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) != 11Description
TRUEnever evaluated
FALSEnever evaluated
0
361 qErrnoWarning(errno, "evdevtouch: Could not read from input device");-
362 if (errno == ENODEV) { // device got disconnected -> stop reading
(*__errno_location ()) == 19Description
TRUEnever evaluated
FALSEnever evaluated
0
363 delete m_notify;-
364 m_notify = Q_NULLPTR;-
365-
366 QT_CLOSE(m_fd);-
367 m_fd = -1;-
368-
369 unregisterTouchDevice();-
370 }
never executed: end of block
0
371 return;
never executed: return;
0
372 }-
373 }
never executed: end of block
0
374}
never executed: end of block
0
375-
376void QEvdevTouchScreenHandler::registerTouchDevice()-
377{-
378 if (m_device)
m_deviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
379 return;
never executed: return;
0
380-
381 m_device = new QTouchDevice;-
382 m_device->setName(d->hw_name);-
383 m_device->setType(QTouchDevice::TouchScreen);-
384 m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area);-
385 if (d->hw_pressure_max > d->hw_pressure_min)
d->hw_pressure...w_pressure_minDescription
TRUEnever evaluated
FALSEnever evaluated
0
386 m_device->setCapabilities(m_device->capabilities() | QTouchDevice::Pressure);
never executed: m_device->setCapabilities(m_device->capabilities() | QTouchDevice::Pressure);
0
387-
388 QWindowSystemInterface::registerTouchDevice(m_device);-
389}
never executed: end of block
0
390-
391void QEvdevTouchScreenHandler::unregisterTouchDevice()-
392{-
393 if (!m_device)
!m_deviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
394 return;
never executed: return;
0
395-
396 // At app exit the cleanup may have already been done, avoid-
397 // double delete by checking the list first.-
398 if (QWindowSystemInterface::isTouchDeviceRegistered(m_device)) {
QWindowSystemI...ered(m_device)Description
TRUEnever evaluated
FALSEnever evaluated
0
399 QWindowSystemInterface::unregisterTouchDevice(m_device);-
400 delete m_device;-
401 }
never executed: end of block
0
402-
403 m_device = Q_NULLPTR;-
404}
never executed: end of block
0
405-
406void QEvdevTouchScreenData::addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates)-
407{-
408 QWindowSystemInterface::TouchPoint tp;-
409 tp.id = contact.trackingId;-
410 tp.flags = contact.flags;-
411 tp.state = contact.state;-
412 *combinedStates |= tp.state;-
413-
414 // Store the HW coordinates for now, will be updated later.-
415 tp.area = QRectF(0, 0, contact.maj, contact.maj);-
416 tp.area.moveCenter(QPoint(contact.x, contact.y));-
417 tp.pressure = contact.pressure;-
418-
419 // Get a normalized position in range 0..1.-
420 tp.normalPosition = QPointF((contact.x - hw_range_x_min) / qreal(hw_range_x_max - hw_range_x_min),-
421 (contact.y - hw_range_y_min) / qreal(hw_range_y_max - hw_range_y_min));-
422-
423 if (!m_rotate.isIdentity())
!m_rotate.isIdentity()Description
TRUEnever evaluated
FALSEnever evaluated
0
424 tp.normalPosition = m_rotate.map(tp.normalPosition);
never executed: tp.normalPosition = m_rotate.map(tp.normalPosition);
0
425-
426 tp.rawPositions.append(QPointF(contact.x, contact.y));-
427-
428 m_touchPoints.append(tp);-
429}
never executed: end of block
0
430-
431void QEvdevTouchScreenData::processInputEvent(input_event *data)-
432{-
433 if (data->type == EV_ABS) {
data->type == 0x03Description
TRUEnever evaluated
FALSEnever evaluated
0
434-
435 if (data->code == ABS_MT_POSITION_X || (m_singleTouch && data->code == ABS_X)) {
data->code == 0x35Description
TRUEnever evaluated
FALSEnever evaluated
m_singleTouchDescription
TRUEnever evaluated
FALSEnever evaluated
data->code == 0x00Description
TRUEnever evaluated
FALSEnever evaluated
0
436 m_currentData.x = qBound(hw_range_x_min, data->value, hw_range_x_max);-
437 if (m_singleTouch)
m_singleTouchDescription
TRUEnever evaluated
FALSEnever evaluated
0
438 m_contacts[m_currentSlot].x = m_currentData.x;
never executed: m_contacts[m_currentSlot].x = m_currentData.x;
0
439 if (m_typeB) {
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
440 m_contacts[m_currentSlot].x = m_currentData.x;-
441 if (m_contacts[m_currentSlot].state == Qt::TouchPointStationary)
m_contacts[m_c...ointStationaryDescription
TRUEnever evaluated
FALSEnever evaluated
0
442 m_contacts[m_currentSlot].state = Qt::TouchPointMoved;
never executed: m_contacts[m_currentSlot].state = Qt::TouchPointMoved;
0
443 }
never executed: end of block
0
444 } else if (data->code == ABS_MT_POSITION_Y || (m_singleTouch && data->code == ABS_Y)) {
never executed: end of block
data->code == 0x36Description
TRUEnever evaluated
FALSEnever evaluated
m_singleTouchDescription
TRUEnever evaluated
FALSEnever evaluated
data->code == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
0
445 m_currentData.y = qBound(hw_range_y_min, data->value, hw_range_y_max);-
446 if (m_singleTouch)
m_singleTouchDescription
TRUEnever evaluated
FALSEnever evaluated
0
447 m_contacts[m_currentSlot].y = m_currentData.y;
never executed: m_contacts[m_currentSlot].y = m_currentData.y;
0
448 if (m_typeB) {
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
449 m_contacts[m_currentSlot].y = m_currentData.y;-
450 if (m_contacts[m_currentSlot].state == Qt::TouchPointStationary)
m_contacts[m_c...ointStationaryDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 m_contacts[m_currentSlot].state = Qt::TouchPointMoved;
never executed: m_contacts[m_currentSlot].state = Qt::TouchPointMoved;
0
452 }
never executed: end of block
0
453 } else if (data->code == ABS_MT_TRACKING_ID) {
never executed: end of block
data->code == 0x39Description
TRUEnever evaluated
FALSEnever evaluated
0
454 m_currentData.trackingId = data->value;-
455 if (m_typeB) {
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
456 if (m_currentData.trackingId == -1) {
m_currentData.trackingId == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
457 m_contacts[m_currentSlot].state = Qt::TouchPointReleased;-
458 } else {
never executed: end of block
0
459 m_contacts[m_currentSlot].state = Qt::TouchPointPressed;-
460 m_contacts[m_currentSlot].trackingId = m_currentData.trackingId;-
461 }
never executed: end of block
0
462 }-
463 } else if (data->code == ABS_MT_TOUCH_MAJOR) {
never executed: end of block
data->code == 0x30Description
TRUEnever evaluated
FALSEnever evaluated
0
464 m_currentData.maj = data->value;-
465 if (data->value == 0)
data->value == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
466 m_currentData.state = Qt::TouchPointReleased;
never executed: m_currentData.state = Qt::TouchPointReleased;
0
467 if (m_typeB)
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
468 m_contacts[m_currentSlot].maj = m_currentData.maj;
never executed: m_contacts[m_currentSlot].maj = m_currentData.maj;
0
469 } else if (data->code == ABS_PRESSURE) {
never executed: end of block
data->code == 0x18Description
TRUEnever evaluated
FALSEnever evaluated
0
470 m_currentData.pressure = qBound(hw_pressure_min, data->value, hw_pressure_max);-
471 if (m_typeB || m_singleTouch)
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
m_singleTouchDescription
TRUEnever evaluated
FALSEnever evaluated
0
472 m_contacts[m_currentSlot].pressure = m_currentData.pressure;
never executed: m_contacts[m_currentSlot].pressure = m_currentData.pressure;
0
473 } else if (data->code == ABS_MT_SLOT) {
never executed: end of block
data->code == 0x2fDescription
TRUEnever evaluated
FALSEnever evaluated
0
474 m_currentSlot = data->value;-
475 }
never executed: end of block
0
476-
477 } else if (data->type == EV_KEY && !m_typeB) {
never executed: end of block
data->type == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
!m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
478 if (data->code == BTN_TOUCH && data->value == 0)
data->code == 0x14aDescription
TRUEnever evaluated
FALSEnever evaluated
data->value == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
479 m_contacts[m_currentSlot].state = Qt::TouchPointReleased;
never executed: m_contacts[m_currentSlot].state = Qt::TouchPointReleased;
0
480 } else if (data->type == EV_SYN && data->code == SYN_MT_REPORT && m_lastEventType != EV_SYN) {
never executed: end of block
data->type == 0x00Description
TRUEnever evaluated
FALSEnever evaluated
data->code == 2Description
TRUEnever evaluated
FALSEnever evaluated
m_lastEventType != 0x00Description
TRUEnever evaluated
FALSEnever evaluated
0
481-
482 // If there is no tracking id, one will be generated later.-
483 // Until that use a temporary key.-
484 int key = m_currentData.trackingId;-
485 if (key == -1)
key == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
486 key = m_contacts.count();
never executed: key = m_contacts.count();
0
487-
488 m_contacts.insert(key, m_currentData);-
489 m_currentData = Contact();-
490-
491 } else if (data->type == EV_SYN && data->code == SYN_REPORT) {
never executed: end of block
data->type == 0x00Description
TRUEnever evaluated
FALSEnever evaluated
data->code == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
492-
493 // Ensure valid IDs even when the driver does not report ABS_MT_TRACKING_ID.-
494 if (!m_contacts.isEmpty() && m_contacts.constBegin().value().trackingId == -1)
!m_contacts.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
m_contacts.con...ackingId == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
495 assignIds();
never executed: assignIds();
0
496-
497 m_touchPoints.clear();-
498 Qt::TouchPointStates combinedStates;-
499-
500 QMutableHashIterator<int, Contact> it(m_contacts);-
501 while (it.hasNext()) {
it.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
0
502 it.next();-
503 Contact &contact(it.value());-
504-
505 if (!contact.state)
!contact.stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
506 continue;
never executed: continue;
0
507-
508 int key = m_typeB ? it.key() : contact.trackingId;
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
509 if (!m_typeB && m_lastContacts.contains(key)) {
!m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
m_lastContacts.contains(key)Description
TRUEnever evaluated
FALSEnever evaluated
0
510 const Contact &prev(m_lastContacts.value(key));-
511 if (contact.state == Qt::TouchPointReleased) {
contact.state ...hPointReleasedDescription
TRUEnever evaluated
FALSEnever evaluated
0
512 // Copy over the previous values for released points, just in case.-
513 contact.x = prev.x;-
514 contact.y = prev.y;-
515 contact.maj = prev.maj;-
516 } else {
never executed: end of block
0
517 contact.state = (prev.x == contact.x && prev.y == contact.y)
prev.x == contact.xDescription
TRUEnever evaluated
FALSEnever evaluated
prev.y == contact.yDescription
TRUEnever evaluated
FALSEnever evaluated
0
518 ? Qt::TouchPointStationary : Qt::TouchPointMoved;-
519 }
never executed: end of block
0
520 }-
521-
522 // Avoid reporting a contact in released state more than once.-
523 if (!m_typeB && contact.state == Qt::TouchPointReleased
!m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
contact.state ...hPointReleasedDescription
TRUEnever evaluated
FALSEnever evaluated
0
524 && !m_lastContacts.contains(key)) {
!m_lastContacts.contains(key)Description
TRUEnever evaluated
FALSEnever evaluated
0
525 it.remove();-
526 continue;
never executed: continue;
0
527 }-
528-
529 addTouchPoint(contact, &combinedStates);-
530 }
never executed: end of block
0
531-
532 // Now look for contacts that have disappeared since the last sync.-
533 it = m_lastContacts;-
534 while (it.hasNext()) {
it.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
0
535 it.next();-
536 Contact &contact(it.value());-
537 int key = m_typeB ? it.key() : contact.trackingId;
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
538 if (m_typeB) {
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
539 if (contact.trackingId != m_contacts[key].trackingId && contact.state) {
contact.tracki...ey].trackingIdDescription
TRUEnever evaluated
FALSEnever evaluated
contact.stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
540 contact.state = Qt::TouchPointReleased;-
541 addTouchPoint(contact, &combinedStates);-
542 }
never executed: end of block
0
543 } else {
never executed: end of block
0
544 if (!m_contacts.contains(key)) {
!m_contacts.contains(key)Description
TRUEnever evaluated
FALSEnever evaluated
0
545 contact.state = Qt::TouchPointReleased;-
546 addTouchPoint(contact, &combinedStates);-
547 }
never executed: end of block
0
548 }
never executed: end of block
0
549 }-
550-
551 // Remove contacts that have just been reported as released.-
552 it = m_contacts;-
553 while (it.hasNext()) {
it.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
0
554 it.next();-
555 Contact &contact(it.value());-
556-
557 if (!contact.state)
!contact.stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
558 continue;
never executed: continue;
0
559-
560 if (contact.state == Qt::TouchPointReleased) {
contact.state ...hPointReleasedDescription
TRUEnever evaluated
FALSEnever evaluated
0
561 if (m_typeB)
m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
0
562 contact.state = static_cast<Qt::TouchPointState>(0);
never executed: contact.state = static_cast<Qt::TouchPointState>(0);
0
563 else-
564 it.remove();
never executed: it.remove();
0
565 } else {-
566 contact.state = Qt::TouchPointStationary;-
567 }
never executed: end of block
0
568 }-
569-
570 m_lastContacts = m_contacts;-
571 if (!m_typeB && !m_singleTouch)
!m_typeBDescription
TRUEnever evaluated
FALSEnever evaluated
!m_singleTouchDescription
TRUEnever evaluated
FALSEnever evaluated
0
572 m_contacts.clear();
never executed: m_contacts.clear();
0
573-
574 if (!m_touchPoints.isEmpty() && combinedStates != Qt::TouchPointStationary)
!m_touchPoints.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
combinedStates...ointStationaryDescription
TRUEnever evaluated
FALSEnever evaluated
0
575 reportPoints();
never executed: reportPoints();
0
576 }
never executed: end of block
0
577-
578 m_lastEventType = data->type;-
579}
never executed: end of block
0
580-
581int QEvdevTouchScreenData::findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist)-
582{-
583 int minDist = -1, id = -1;-
584 for (QHash<int, Contact>::const_iterator it = contacts.constBegin(), ite = contacts.constEnd();-
585 it != ite; ++it) {
it != iteDescription
TRUEnever evaluated
FALSEnever evaluated
0
586 const Contact &contact(it.value());-
587 int dx = x - contact.x;-
588 int dy = y - contact.y;-
589 int dist = dx * dx + dy * dy;-
590 if (minDist == -1 || dist < minDist) {
minDist == -1Description
TRUEnever evaluated
FALSEnever evaluated
dist < minDistDescription
TRUEnever evaluated
FALSEnever evaluated
0
591 minDist = dist;-
592 id = contact.trackingId;-
593 }
never executed: end of block
0
594 }
never executed: end of block
0
595 if (dist)
distDescription
TRUEnever evaluated
FALSEnever evaluated
0
596 *dist = minDist;
never executed: *dist = minDist;
0
597 return id;
never executed: return id;
0
598}-
599-
600void QEvdevTouchScreenData::assignIds()-
601{-
602 QHash<int, Contact> candidates = m_lastContacts, pending = m_contacts, newContacts;-
603 int maxId = -1;-
604 QHash<int, Contact>::iterator it, ite, bestMatch;-
605 while (!pending.isEmpty() && !candidates.isEmpty()) {
!pending.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!candidates.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
606 int bestDist = -1, bestId = 0;-
607 for (it = pending.begin(), ite = pending.end(); it != ite; ++it) {
it != iteDescription
TRUEnever evaluated
FALSEnever evaluated
0
608 int dist;-
609 int id = findClosestContact(candidates, it->x, it->y, &dist);-
610 if (id >= 0 && (bestDist == -1 || dist < bestDist)) {
id >= 0Description
TRUEnever evaluated
FALSEnever evaluated
bestDist == -1Description
TRUEnever evaluated
FALSEnever evaluated
dist < bestDistDescription
TRUEnever evaluated
FALSEnever evaluated
0
611 bestDist = dist;-
612 bestId = id;-
613 bestMatch = it;-
614 }
never executed: end of block
0
615 }
never executed: end of block
0
616 if (bestDist >= 0) {
bestDist >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
617 bestMatch->trackingId = bestId;-
618 newContacts.insert(bestId, *bestMatch);-
619 candidates.remove(bestId);-
620 pending.erase(bestMatch);-
621 if (bestId > maxId)
bestId > maxIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
622 maxId = bestId;
never executed: maxId = bestId;
0
623 }
never executed: end of block
0
624 }
never executed: end of block
0
625 if (candidates.isEmpty()) {
candidates.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
626 for (it = pending.begin(), ite = pending.end(); it != ite; ++it) {
it != iteDescription
TRUEnever evaluated
FALSEnever evaluated
0
627 it->trackingId = ++maxId;-
628 newContacts.insert(it->trackingId, *it);-
629 }
never executed: end of block
0
630 }
never executed: end of block
0
631 m_contacts = newContacts;-
632}
never executed: end of block
0
633-
634void QEvdevTouchScreenData::reportPoints()-
635{-
636 QRect winRect;-
637 if (m_forceToActiveWindow) {
m_forceToActiveWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
638 QWindow *win = QGuiApplication::focusWindow();-
639 if (!win)
!winDescription
TRUEnever evaluated
FALSEnever evaluated
0
640 return;
never executed: return;
0
641 winRect = QHighDpi::toNativePixels(win->geometry(), win);-
642 } else {
never executed: end of block
0
643 QScreen *primary = QGuiApplication::primaryScreen();-
644 winRect = QHighDpi::toNativePixels(primary->geometry(), primary);-
645 }
never executed: end of block
0
646-
647 const int hw_w = hw_range_x_max - hw_range_x_min;-
648 const int hw_h = hw_range_y_max - hw_range_y_min;-
649-
650 // Map the coordinates based on the normalized position. QPA expects 'area'-
651 // to be in screen coordinates.-
652 const int pointCount = m_touchPoints.count();-
653 for (int i = 0; i < pointCount; ++i) {
i < pointCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
654 QWindowSystemInterface::TouchPoint &tp(m_touchPoints[i]);-
655-
656 // Generate a screen position that is always inside the active window-
657 // or the primary screen. Even though we report this as a QRectF, internally-
658 // Qt uses QRect/QPoint so we need to bound the size to winRect.size() - QSize(1, 1)-
659 const qreal wx = winRect.left() + tp.normalPosition.x() * (winRect.width() - 1);-
660 const qreal wy = winRect.top() + tp.normalPosition.y() * (winRect.height() - 1);-
661 const qreal sizeRatio = (winRect.width() + winRect.height()) / qreal(hw_w + hw_h);-
662 if (tp.area.width() == -1) // touch major was not provided
tp.area.width() == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
663 tp.area = QRectF(0, 0, 8, 8);
never executed: tp.area = QRectF(0, 0, 8, 8);
0
664 else-
665 tp.area = QRectF(0, 0, tp.area.width() * sizeRatio, tp.area.height() * sizeRatio);
never executed: tp.area = QRectF(0, 0, tp.area.width() * sizeRatio, tp.area.height() * sizeRatio);
0
666 tp.area.moveCenter(QPointF(wx, wy));-
667-
668 // Calculate normalized pressure.-
669 if (!hw_pressure_min && !hw_pressure_max)
!hw_pressure_minDescription
TRUEnever evaluated
FALSEnever evaluated
!hw_pressure_maxDescription
TRUEnever evaluated
FALSEnever evaluated
0
670 tp.pressure = tp.state == Qt::TouchPointReleased ? 0 : 1;
never executed: tp.pressure = tp.state == Qt::TouchPointReleased ? 0 : 1;
tp.state == Qt...hPointReleasedDescription
TRUEnever evaluated
FALSEnever evaluated
0
671 else-
672 tp.pressure = (tp.pressure - hw_pressure_min) / qreal(hw_pressure_max - hw_pressure_min);
never executed: tp.pressure = (tp.pressure - hw_pressure_min) / qreal(hw_pressure_max - hw_pressure_min);
0
673 }-
674-
675 QWindowSystemInterface::handleTouchEvent(Q_NULLPTR, q->touchDevice(), m_touchPoints);-
676}
never executed: end of block
0
677-
678-
679QEvdevTouchScreenHandlerThread::QEvdevTouchScreenHandlerThread(const QString &device, const QString &spec, QObject *parent)-
680 : QDaemonThread(parent), m_device(device), m_spec(spec), m_handler(Q_NULLPTR), m_touchDeviceRegistered(false)-
681{-
682 start();-
683}
never executed: end of block
0
684-
685QEvdevTouchScreenHandlerThread::~QEvdevTouchScreenHandlerThread()-
686{-
687 quit();-
688 wait();-
689}
never executed: end of block
0
690-
691void QEvdevTouchScreenHandlerThread::run()-
692{-
693 m_handler = new QEvdevTouchScreenHandler(m_device, m_spec);-
694 // Report the registration to the parent thread by invoking the method asynchronously-
695 QMetaObject::invokeMethod(this, "notifyTouchDeviceRegistered", Qt::QueuedConnection);-
696-
697 exec();-
698-
699 delete m_handler;-
700 m_handler = Q_NULLPTR;-
701}
never executed: end of block
0
702-
703bool QEvdevTouchScreenHandlerThread::isTouchDeviceRegistered() const-
704{-
705 return m_touchDeviceRegistered;
never executed: return m_touchDeviceRegistered;
0
706}-
707-
708void QEvdevTouchScreenHandlerThread::notifyTouchDeviceRegistered()-
709{-
710 m_touchDeviceRegistered = true;-
711 emit touchDeviceRegistered();-
712}
never executed: end of block
0
713-
714-
715QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9