Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
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) | - |
46 | extern "C" { | - |
47 | #include <mtdev.h> | - |
48 | } | - |
49 | #endif | - |
50 | | - |
51 | QT_BEGIN_NAMESPACE | - |
52 | | - |
53 | Q_LOGGING_CATEGORY(qLcEvdevTouch, "qt.qpa.input") never executed: return category; | 0 |
54 | | - |
55 | | - |
56 | | - |
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 | | - |
80 | class QEvdevTouchScreenData | - |
81 | { | - |
82 | public: | - |
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; | - |
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 | | - |
126 | QEvdevTouchScreenData::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) | - |
142 | static inline bool testBit(long bit, const long *array) | - |
143 | { | - |
144 | return (array[bit / LONG_BITS] >> bit % LONG_BITS) & 1; | - |
145 | } | - |
146 | #endif | - |
147 | | - |
148 | QEvdevTouchScreenHandler::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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
161 | if (args.at(i).startsWith(QLatin1String("rotate"))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
162 | QString rotateArg = args.at(i).section(QLatin1Char('='), 1, 1); | - |
163 | bool ok; | - |
164 | uint argValue = rotateArg.toUInt(&ok); | - |
165 | if (ok) {TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
| 0 |
176 | invertx = true; | - |
177 | } else if (args.at(i) == QLatin1String("inverty")) { never executed: end of block TRUE | never evaluated | FALSE | never 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()); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
183 | | - |
184 | m_fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); | - |
185 | | - |
186 | if (m_fd >= 0) {TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never 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") ; TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never 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) ; TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never 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) ; TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never 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) ; TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never 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); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
257 | } never executed: end of block | 0 |
258 | | - |
259 | | - |
260 | if (d->hw_name == QLatin1String("ti-tsc")) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
261 | if (d->hw_range_x_min == 0 && d->hw_range_x_max == 4095) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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) ; TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never 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 | | - |
291 | QEvdevTouchScreenHandler::~QEvdevTouchScreenHandler() | - |
292 | { | - |
293 | #if !defined(QT_NO_MTDEV) | - |
294 | if (m_mtdev) {TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never 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 | | - |
308 | QTouchDevice *QEvdevTouchScreenHandler::touchDevice() const | - |
309 | { | - |
310 | return m_device; never executed: return m_device; | 0 |
311 | } | - |
312 | | - |
313 | void 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 | | - |
323 | | - |
324 | | - |
325 | } while (events == -1 && errno == EINTR); never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
326 | | - |
327 | | - |
328 | if (events <= 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
329 | goto err; never executed: goto err; | 0 |
330 | | - |
331 | | - |
332 | for (int i = 0; i < events; ++i)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
333 | d->processInputEvent(&buffer[i]); never executed: d->processInputEvent(&buffer[i]); | 0 |
334 | | - |
335 | | - |
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 | | - |
355 | err: | - |
356 | if (!events) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
357 | qWarning("evdevtouch: Got EOF from input device"); | - |
358 | return; never executed: return; | 0 |
359 | } else if (events < 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
360 | if (errno != EINTR && errno != EAGAIN) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
361 | qErrnoWarning(errno, "evdevtouch: Could not read from input device"); | - |
362 | if (errno == ENODEV) { TRUE | never evaluated | FALSE | never 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 | | - |
376 | void QEvdevTouchScreenHandler::registerTouchDevice() | - |
377 | { | - |
378 | if (m_device)TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never 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 | | - |
391 | void QEvdevTouchScreenHandler::unregisterTouchDevice() | - |
392 | { | - |
393 | if (!m_device)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
394 | return; never executed: return; | 0 |
395 | | - |
396 | | - |
397 | | - |
398 | if (QWindowSystemInterface::isTouchDeviceRegistered(m_device)) {TRUE | never evaluated | FALSE | never 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 | | - |
406 | void 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 | | - |
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 | | - |
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())TRUE | never evaluated | FALSE | never 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 | | - |
431 | void QEvdevTouchScreenData::processInputEvent(input_event *data) | - |
432 | { | - |
433 | if (data->type == EV_ABS) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
434 | | - |
435 | if (data->code == ABS_MT_POSITION_X || (m_singleTouch && data->code == ABS_X)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
436 | m_currentData.x = qBound(hw_range_x_min, data->value, hw_range_x_max); | - |
437 | if (m_singleTouch)TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
440 | m_contacts[m_currentSlot].x = m_currentData.x; | - |
441 | if (m_contacts[m_currentSlot].state == Qt::TouchPointStationary)TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
445 | m_currentData.y = qBound(hw_range_y_min, data->value, hw_range_y_max); | - |
446 | if (m_singleTouch)TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
449 | m_contacts[m_currentSlot].y = m_currentData.y; | - |
450 | if (m_contacts[m_currentSlot].state == Qt::TouchPointStationary)TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
| 0 |
454 | m_currentData.trackingId = data->value; | - |
455 | if (m_typeB) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
456 | if (m_currentData.trackingId == -1) {TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
| 0 |
464 | m_currentData.maj = data->value; | - |
465 | if (data->value == 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
466 | m_currentData.state = Qt::TouchPointReleased; never executed: m_currentData.state = Qt::TouchPointReleased; | 0 |
467 | if (m_typeB)TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
| 0 |
470 | m_currentData.pressure = qBound(hw_pressure_min, data->value, hw_pressure_max); | - |
471 | if (m_typeB || m_singleTouch)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
478 | if (data->code == BTN_TOUCH && data->value == 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
481 | | - |
482 | | - |
483 | | - |
484 | int key = m_currentData.trackingId; | - |
485 | if (key == -1)TRUE | never evaluated | FALSE | never 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 TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
492 | | - |
493 | | - |
494 | if (!m_contacts.isEmpty() && m_contacts.constBegin().value().trackingId == -1)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
502 | it.next(); | - |
503 | Contact &contact(it.value()); | - |
504 | | - |
505 | if (!contact.state)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
506 | continue; never executed: continue; | 0 |
507 | | - |
508 | int key = m_typeB ? it.key() : contact.trackingId;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
509 | if (!m_typeB && m_lastContacts.contains(key)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
510 | const Contact &prev(m_lastContacts.value(key)); | - |
511 | if (contact.state == Qt::TouchPointReleased) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
512 | | - |
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)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
518 | ? Qt::TouchPointStationary : Qt::TouchPointMoved; | - |
519 | } never executed: end of block | 0 |
520 | } | - |
521 | | - |
522 | | - |
523 | if (!m_typeB && contact.state == Qt::TouchPointReleasedTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
524 | && !m_lastContacts.contains(key)) {TRUE | never evaluated | FALSE | never 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 | | - |
533 | it = m_lastContacts; | - |
534 | while (it.hasNext()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
535 | it.next(); | - |
536 | Contact &contact(it.value()); | - |
537 | int key = m_typeB ? it.key() : contact.trackingId;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
538 | if (m_typeB) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
539 | if (contact.trackingId != m_contacts[key].trackingId && contact.state) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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)) {TRUE | never evaluated | FALSE | never 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 | | - |
552 | it = m_contacts; | - |
553 | while (it.hasNext()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
554 | it.next(); | - |
555 | Contact &contact(it.value()); | - |
556 | | - |
557 | if (!contact.state)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
558 | continue; never executed: continue; | 0 |
559 | | - |
560 | if (contact.state == Qt::TouchPointReleased) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
561 | if (m_typeB)TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
572 | m_contacts.clear(); never executed: m_contacts.clear(); | 0 |
573 | | - |
574 | if (!m_touchPoints.isEmpty() && combinedStates != Qt::TouchPointStationary)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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 | | - |
581 | int 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) {TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
596 | *dist = minDist; never executed: *dist = minDist; | 0 |
597 | return id; never executed: return id; | 0 |
598 | } | - |
599 | | - |
600 | void 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()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
606 | int bestDist = -1, bestId = 0; | - |
607 | for (it = pending.begin(), ite = pending.end(); it != ite; ++it) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
608 | int dist; | - |
609 | int id = findClosestContact(candidates, it->x, it->y, &dist); | - |
610 | if (id >= 0 && (bestDist == -1 || dist < bestDist)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
617 | bestMatch->trackingId = bestId; | - |
618 | newContacts.insert(bestId, *bestMatch); | - |
619 | candidates.remove(bestId); | - |
620 | pending.erase(bestMatch); | - |
621 | if (bestId > maxId)TRUE | never evaluated | FALSE | never 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()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
626 | for (it = pending.begin(), ite = pending.end(); it != ite; ++it) {TRUE | never evaluated | FALSE | never 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 | | - |
634 | void QEvdevTouchScreenData::reportPoints() | - |
635 | { | - |
636 | QRect winRect; | - |
637 | if (m_forceToActiveWindow) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
638 | QWindow *win = QGuiApplication::focusWindow(); | - |
639 | if (!win)TRUE | never evaluated | FALSE | never 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 | | - |
651 | | - |
652 | const int pointCount = m_touchPoints.count(); | - |
653 | for (int i = 0; i < pointCount; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
654 | QWindowSystemInterface::TouchPoint &tp(m_touchPoints[i]); | - |
655 | | - |
656 | | - |
657 | | - |
658 | | - |
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) TRUE | never evaluated | FALSE | never 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 | | - |
669 | if (!hw_pressure_min && !hw_pressure_max)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
670 | tp.pressure = tp.state == Qt::TouchPointReleased ? 0 : 1; never executed: tp.pressure = tp.state == Qt::TouchPointReleased ? 0 : 1; TRUE | never evaluated | FALSE | never 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 | | - |
679 | QEvdevTouchScreenHandlerThread::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 | | - |
685 | QEvdevTouchScreenHandlerThread::~QEvdevTouchScreenHandlerThread() | - |
686 | { | - |
687 | quit(); | - |
688 | wait(); | - |
689 | } never executed: end of block | 0 |
690 | | - |
691 | void QEvdevTouchScreenHandlerThread::run() | - |
692 | { | - |
693 | m_handler = new QEvdevTouchScreenHandler(m_device, m_spec); | - |
694 | | - |
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 | | - |
703 | bool QEvdevTouchScreenHandlerThread::isTouchDeviceRegistered() const | - |
704 | { | - |
705 | return m_touchDeviceRegistered; never executed: return m_touchDeviceRegistered; | 0 |
706 | } | - |
707 | | - |
708 | void QEvdevTouchScreenHandlerThread::notifyTouchDeviceRegistered() | - |
709 | { | - |
710 | m_touchDeviceRegistered = true; | - |
711 | emit touchDeviceRegistered(); | - |
712 | } never executed: end of block | 0 |
713 | | - |
714 | | - |
715 | QT_END_NAMESPACE | - |
| | |