Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qvxtouchmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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
18QVxTouchManager::QVxTouchManager(const QString &key, const QString &specification, QObject *parent)
19 : QObject(parent)
20{
21 Q_UNUSED(key);
22
23 if (qEnvironmentVariableIsSet("QT_QPA_VXEVDEV_DEBUG"))
24 const_cast<QLoggingCategory &>(qLcVxTouch()).setEnabled(QtDebugMsg, true);
25
26 QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_VXEVDEV_TOUCHSCREEN_PARAMETERS"));
27
28 if (spec.isEmpty())
29 spec = specification;
30
31 auto parsed = QEvdevUtil::parseSpecification(spec);
32 m_spec = std::move(parsed.spec);
33
34 for (const QString &device : std::as_const(parsed.devices))
35 addDevice(device);
36
37 // when no devices specified, use device discovery to scan and monitor
38 if (parsed.devices.isEmpty()) {
39 qCDebug(qLcVxTouch, "vxtouch: Using device discovery");
40 if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Touchpad | QDeviceDiscovery::Device_Touchscreen, this)) {
41 const QStringList devices = deviceDiscovery->scanConnectedDevices();
42 for (const QString &device : devices)
43 addDevice(device);
44
45 connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected,
46 this, &QVxTouchManager::addDevice);
47 connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved,
48 this, &QVxTouchManager::removeDevice);
49 }
50 }
51}
52
56
57void QVxTouchManager::addDevice(const QString &deviceNode)
58{
59 qCDebug(qLcVxTouch, "vxtouch: Adding device at %ls", qUtf16Printable(deviceNode));
60 auto handler = std::make_unique<QVxTouchScreenHandlerThread>(deviceNode, m_spec);
61 if (handler) {
62 connect(handler.get(), &QVxTouchScreenHandlerThread::touchDeviceRegistered, this, &QVxTouchManager::updateInputDeviceCount);
63 m_activeDevices.add(deviceNode, std::move(handler));
64 } else {
65 qWarning("vxtouch: Failed to open touch device %ls", qUtf16Printable(deviceNode));
66 }
67}
68
69void QVxTouchManager::removeDevice(const QString &deviceNode)
70{
71 if (m_activeDevices.remove(deviceNode)) {
72 qCDebug(qLcVxTouch, "vxtouch: Removing device at %ls", qUtf16Printable(deviceNode));
74 }
75}
76
78{
79 int registeredTouchDevices = 0;
80 for (const auto &device : m_activeDevices) {
81 if (device.handler->isPointingDeviceRegistered())
82 ++registeredTouchDevices;
83 }
84
85 qCDebug(qLcVxTouch, "vxtouch: Updating QInputDeviceManager device count: %d touch devices, %d pending handler(s)",
86 registeredTouchDevices, m_activeDevices.count() - registeredTouchDevices);
87
88 QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
89 QInputDeviceManager::DeviceTypeTouch, registeredTouchDevices);
90}
91
92QT_END_NAMESPACE
void addDevice(const QString &deviceNode)
void removeDevice(const QString &deviceNode)