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
qevdevtabletmanager.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
18QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &specification, QObject *parent)
19 : QObject(parent)
20{
21 Q_UNUSED(key);
22
23 if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG"))
24 const_cast<QLoggingCategory &>(qLcEvdevTablet()).setEnabled(QtDebugMsg, true);
25
26 QString spec = qEnvironmentVariable("QT_QPA_EVDEV_TABLET_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(qLcEvdevTablet, "evdevtablet: Using device discovery");
40 if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this)) {
41 const QStringList devices = deviceDiscovery->scanConnectedDevices();
42 for (const QString &device : devices)
43 addDevice(device);
44
45 connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected,
46 this, &QEvdevTabletManager::addDevice);
47 connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved,
48 this, &QEvdevTabletManager::removeDevice);
49 }
50 }
51}
52
56
57void QEvdevTabletManager::addDevice(const QString &deviceNode)
58{
59 qCDebug(qLcEvdevTablet, "Adding device at %ls", qUtf16Printable(deviceNode));
60 auto handler = std::make_unique<QEvdevTabletHandlerThread>(deviceNode, m_spec);
61 if (handler) {
62 m_activeDevices.add(deviceNode, std::move(handler));
63 updateDeviceCount();
64 } else {
65 qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode));
66 }
67}
68
69void QEvdevTabletManager::removeDevice(const QString &deviceNode)
70{
71 if (m_activeDevices.remove(deviceNode)) {
72 qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode));
73 updateDeviceCount();
74 }
75}
76
77void QEvdevTabletManager::updateDeviceCount()
78{
79 QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
80 QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count());
81}
82
83QT_END_NAMESPACE
void addDevice(const QString &deviceNode)
void removeDevice(const QString &deviceNode)