7#include <QCoreApplication>
11#include <QLoggingCategory>
12#include <QtCore/private/qcore_unix_p.h>
15#include <dev/evdev/input.h>
17#include <linux/input.h>
22
23
25#define KEY_CNT (KEY_MAX+1
)
28#define REL_CNT (REL_MAX+1
)
31#define ABS_CNT (ABS_MAX+1
)
34#define ABS_MT_POSITION_X 0x35
37#define ABS_MT_POSITION_Y 0x36
40#define LONG_BITS (sizeof(long) * 8
)
41#define LONG_FIELD_SIZE(bits) ((bits / LONG_BITS) + 1
)
43static bool testBit(
long bit,
const long *field)
50using namespace Qt::StringLiterals;
54QDeviceDiscovery *QDeviceDiscovery::create(QDeviceTypes types, QObject *parent)
56 return new QDeviceDiscoveryStatic(types, parent);
59QDeviceDiscoveryStatic::QDeviceDiscoveryStatic(QDeviceTypes types, QObject *parent)
60 : QDeviceDiscovery(types, parent)
62 qCDebug(lcDD) <<
"static device discovery for type" << types;
65QStringList QDeviceDiscoveryStatic::scanConnectedDevices()
69 auto addDevices = [
this, &devices](
const char *path) {
70 for (
const auto &entry : QDirListing(QString::fromLatin1(path))) {
71 QString absoluteFilePath = entry.absoluteFilePath();
72 if (checkDeviceType(absoluteFilePath))
73 devices.emplace_back(std::move(absoluteFilePath));
78 if (m_types & Device_InputMask)
82 if (m_types & Device_VideoMask)
85 qCDebug(lcDD) <<
"Found matching devices" << devices;
90bool QDeviceDiscoveryStatic::checkDeviceType(
const QString &device)
92 int fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0);
93 if (Q_UNLIKELY(fd == -1)) {
94 qWarning() <<
"Device discovery cannot open device" << device;
98 qCDebug(lcDD) <<
"doing static device discovery for " << device;
108 memset(bitsAbs, 0,
sizeof(bitsAbs));
109 memset(bitsKey, 0,
sizeof(bitsKey));
110 memset(bitsRel, 0,
sizeof(bitsRel));
112 ioctl(fd, EVIOCGBIT(
EV_ABS,
sizeof(bitsAbs)), bitsAbs);
113 ioctl(fd, EVIOCGBIT(
EV_KEY,
sizeof(bitsKey)), bitsKey);
114 ioctl(fd, EVIOCGBIT(EV_REL,
sizeof(bitsRel)), bitsRel);
118 if ((m_types & Device_Keyboard)) {
119 if (testBit(KEY_Q, bitsKey)) {
120 qCDebug(lcDD) <<
"Found keyboard at" << device;
125 if ((m_types & Device_Mouse)) {
126 if (testBit(REL_X, bitsRel) && testBit(REL_Y, bitsRel) && testBit(BTN_MOUSE, bitsKey)) {
127 qCDebug(lcDD) <<
"Found mouse at" << device;
132 if ((m_types & (Device_Touchpad | Device_Touchscreen))) {
133 if (testBit(
ABS_X, bitsAbs) && testBit(
ABS_Y, bitsAbs)) {
134 if ((m_types & Device_Touchpad) && testBit(BTN_TOOL_FINGER, bitsKey)) {
135 qCDebug(lcDD) <<
"Found touchpad at" << device;
137 }
else if ((m_types & Device_Touchscreen) && testBit(
BTN_TOUCH, bitsKey)) {
138 qCDebug(lcDD) <<
"Found touchscreen at" << device;
140 }
else if ((m_types & Device_Tablet) && (testBit(BTN_STYLUS, bitsKey) || testBit(BTN_TOOL_PEN, bitsKey))) {
141 qCDebug(lcDD) <<
"Found tablet at" << device;
146 qCDebug(lcDD) <<
"Found new-style touchscreen at" << device;
151 if ((m_types & Device_Joystick)) {
152 if (testBit(BTN_A, bitsKey) || testBit(BTN_TRIGGER, bitsKey) || testBit(ABS_RX, bitsAbs)) {
153 qCDebug(lcDD) <<
"Found joystick/gamepad at" << device;
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
#define QT_DRM_DEVICE_PATH
#define QT_EVDEV_DEVICE_PATH
#define QT_DRM_DEVICE_PREFIX
#define ABS_MT_POSITION_X
static bool testBit(long bit, const long *field)
#define ABS_MT_POSITION_Y
#define LONG_FIELD_SIZE(bits)