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
qevdevtouchmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QtInputSupport/private/qevdevutil_p.h>
8
9#include <QStringList>
10#include <QGuiApplication>
11#include <QLoggingCategory>
12#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
13#include <private/qguiapplication_p.h>
14#include <private/qinputdevicemanager_p_p.h>
15
17
18Q_DECLARE_LOGGING_CATEGORY(qLcEvdevTouch)
19
20QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specification, QObject *parent)
21 : QObject(parent)
22{
24
25 if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG"))
26 const_cast<QLoggingCategory &>(qLcEvdevTouch()).setEnabled(QtDebugMsg, true);
27
28 QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS"));
29
30 if (spec.isEmpty())
31 spec = specification;
32
33 auto parsed = QEvdevUtil::parseSpecification(spec);
34 m_spec = std::move(parsed.spec);
35
36 for (const QString &device : std::as_const(parsed.devices))
37 addDevice(device);
38
39 // when no devices specified, use device discovery to scan and monitor
40 if (parsed.devices.isEmpty()) {
41 qCDebug(qLcEvdevTouch, "evdevtouch: Using device discovery");
43 const QStringList devices = deviceDiscovery->scanConnectedDevices();
44 for (const QString &device : devices)
45 addDevice(device);
46
51 }
52 }
53}
54
58
60{
61 qCDebug(qLcEvdevTouch, "evdevtouch: Adding device at %ls", qUtf16Printable(deviceNode));
62 auto handler = std::make_unique<QEvdevTouchScreenHandlerThread>(deviceNode, m_spec);
63 if (handler) {
65 m_activeDevices.add(deviceNode, std::move(handler));
66 } else {
67 qWarning("evdevtouch: Failed to open touch device %ls", qUtf16Printable(deviceNode));
68 }
69}
70
72{
73 if (m_activeDevices.remove(deviceNode)) {
74 qCDebug(qLcEvdevTouch, "evdevtouch: Removing device at %ls", qUtf16Printable(deviceNode));
76 }
77}
78
80{
81 int registeredTouchDevices = 0;
82 for (const auto &device : m_activeDevices) {
83 if (device.handler->isPointingDeviceRegistered())
84 ++registeredTouchDevices;
85 }
86
87 qCDebug(qLcEvdevTouch, "evdevtouch: Updating QInputDeviceManager device count: %d touch devices, %d pending handler(s)",
88 registeredTouchDevices, m_activeDevices.count() - registeredTouchDevices);
89
91 QInputDeviceManager::DeviceTypeTouch, registeredTouchDevices);
92}
93
IOBluetoothDevice * device
void deviceDetected(const QString &deviceNode)
static QDeviceDiscovery * create(QDeviceTypes type, QObject *parent=nullptr)
void deviceRemoved(const QString &deviceNode)
void removeDevice(const QString &deviceNode)
void addDevice(const QString &deviceNode)
static QInputDeviceManager * inputDeviceManager()
static QInputDeviceManagerPrivate * get(QInputDeviceManager *mgr)
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5949
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void add(const QString &deviceNode, std::unique_ptr< Handler > handler)
bool remove(const QString &deviceNode)
ParsedSpecification parseSpecification(const QString &specification)
Combined button and popup list for selecting options.
EGLDeviceEXT * devices
@ QtDebugMsg
Definition qlogging.h:30
#define qWarning
Definition qlogging.h:166
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint64 key
#define qUtf16Printable(string)
Definition qstring.h:1543
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
#define Q_UNUSED(x)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)