From ce5c1db2d3db7d7c7af28e9053ca591f76c6101c Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 21 May 2012 15:41:58 -0700 Subject: udev: UDevHelper becomes DeviceDiscovery Rename QUDeviceHelper to QDeviceDiscovery and add a static device discovery fallback in case we dont have udev. The fallback so far only scans /dev/input/event* and /dev/dri/card* at startup and detects device nodes only by device path. Change-Id: I7a423910b30ae16a10d8f1f47b86c6b4d2c2ec36 Reviewed-by: Girish Ramakrishnan Reviewed-by: Donald Carr --- .../devicediscovery/devicediscovery.pri | 12 + .../devicediscovery/qdevicediscovery_p.h | 120 ++++++++++ .../devicediscovery/qdevicediscovery_static.cpp | 114 ++++++++++ .../devicediscovery/qdevicediscovery_udev.cpp | 250 ++++++++++++++++++++ src/platformsupport/platformsupport.pro | 2 +- src/platformsupport/udev/qudevicehelper.cpp | 251 --------------------- src/platformsupport/udev/qudevicehelper_p.h | 101 --------- src/platformsupport/udev/udev.pri | 7 - .../evdevkeyboard/qevdevkeyboardmanager.cpp | 24 +- .../generic/evdevkeyboard/qevdevkeyboardmanager.h | 8 +- .../generic/evdevmouse/qevdevmousemanager.cpp | 26 +-- .../generic/evdevmouse/qevdevmousemanager.h | 8 +- src/plugins/generic/evdevtouch/qevdevtouch.cpp | 14 +- 13 files changed, 521 insertions(+), 416 deletions(-) create mode 100644 src/platformsupport/devicediscovery/devicediscovery.pri create mode 100644 src/platformsupport/devicediscovery/qdevicediscovery_p.h create mode 100644 src/platformsupport/devicediscovery/qdevicediscovery_static.cpp create mode 100644 src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp delete mode 100644 src/platformsupport/udev/qudevicehelper.cpp delete mode 100644 src/platformsupport/udev/qudevicehelper_p.h delete mode 100644 src/platformsupport/udev/udev.pri (limited to 'src') diff --git a/src/platformsupport/devicediscovery/devicediscovery.pri b/src/platformsupport/devicediscovery/devicediscovery.pri new file mode 100644 index 0000000000..900419888e --- /dev/null +++ b/src/platformsupport/devicediscovery/devicediscovery.pri @@ -0,0 +1,12 @@ +unix:!mac { + HEADERS += $$PWD/qdevicediscovery_p.h + + contains(QT_CONFIG, libudev) { + SOURCES += $$PWD/qdevicediscovery_udev.cpp + + INCLUDEPATH += $$QMAKE_INCDIR_LIBUDEV + LIBS += $$QMAKE_LIBS_LIBUDEV + } else { + SOURCES += $$PWD/qdevicediscovery_static.cpp + } +} diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_p.h b/src/platformsupport/devicediscovery/qdevicediscovery_p.h new file mode 100644 index 0000000000..3bec6928bf --- /dev/null +++ b/src/platformsupport/devicediscovery/qdevicediscovery_p.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDEVICEDISCOVERY_H +#define QDEVICEDISCOVERY_H + +#include +#include + +#ifndef QT_NO_LIBUDEV +#include +#endif + +#define QT_EVDEV_DEVICE_PATH "/dev/input/" +#define QT_EVDEV_DEVICE_PREFIX "event" +#define QT_EVDEV_DEVICE QT_EVDEV_DEVICE_PATH QT_EVDEV_DEVICE_PREFIX + +#define QT_DRM_DEVICE_PATH "/dev/dri/" +#define QT_DRM_DEVICE_PREFIX "card" +#define QT_DRM_DEVICE QT_DRM_DEVICE_PATH QT_DRM_DEVICE_PREFIX + +QT_BEGIN_NAMESPACE + +class QDeviceDiscovery : public QObject +{ + Q_OBJECT + Q_ENUMS(QDeviceType) + +public: + enum QDeviceType { + Device_Unknown = 0x00, + Device_Mouse = 0x01, + Device_Touchpad = 0x02, + Device_Touchscreen = 0x04, + Device_Keyboard = 0x08, + Device_DRM = 0x10, + Device_InputMask = Device_Mouse | Device_Touchpad | Device_Touchscreen | Device_Keyboard, + Device_VideoMask = Device_DRM + }; + Q_DECLARE_FLAGS(QDeviceTypes, QDeviceType) + + static QDeviceDiscovery *create(QDeviceTypes type, QObject *parent); + ~QDeviceDiscovery(); + + QStringList scanConnectedDevices(); + +signals: + void deviceDetected(const QString &deviceNode); + void deviceRemoved(const QString &deviceNode); + +#ifndef QT_NO_LIBUDEV +private slots: + void handleUDevNotification(); +#endif + +private: +#ifndef QT_NO_LIBUDEV + QDeviceDiscovery(QDeviceTypes types, struct udev *udev, QObject *parent = 0); + bool checkDeviceType(struct udev_device *dev); +#else + QDeviceDiscovery(QDeviceTypes types, QObject *parent = 0); + bool checkDeviceType(const QString &device); +#endif + + QDeviceTypes m_types; + +#ifndef QT_NO_LIBUDEV + void startWatching(); + void stopWatching(); + + struct udev *m_udev; + struct udev_monitor *m_udevMonitor; + int m_udevMonitorFileDescriptor; + QSocketNotifier *m_udevSocketNotifier; +#endif +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QDeviceDiscovery::QDeviceTypes) + +QT_END_NAMESPACE + +#endif // QDEVICEDISCOVERY_H diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp b/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp new file mode 100644 index 0000000000..918ab8799a --- /dev/null +++ b/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdevicediscovery_p.h" + +#include +#include +#include +#include +#include + +//#define QT_QPA_DEVICE_DISCOVERY_DEBUG + +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG +#include +#endif + +QT_BEGIN_NAMESPACE + +QDeviceDiscovery *QDeviceDiscovery::create(QDeviceTypes types, QObject *parent) +{ + return new QDeviceDiscovery(types, parent); +} + +QDeviceDiscovery::QDeviceDiscovery(QDeviceTypes types, QObject *parent) : + QObject(parent), + m_types(types) +{ +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning() << "New static DeviceDiscovery created for type" << types; +#endif +} + +QDeviceDiscovery::~QDeviceDiscovery() +{ +} + +QStringList QDeviceDiscovery::scanConnectedDevices() +{ + QStringList devices; + + // check for input devices + QDir dir(QString::fromLatin1(QT_EVDEV_DEVICE_PATH)); + dir.setFilter(QDir::System); + + foreach (const QString &deviceFile, dir.entryList()) { + if (checkDeviceType(deviceFile)) + devices << (dir.absolutePath() + QString::fromLatin1("/") + deviceFile); + } + + // check for drm devices + dir.setPath(QString::fromLatin1(QT_DRM_DEVICE_PATH)); + foreach (const QString &deviceFile, dir.entryList()) { + if (checkDeviceType(deviceFile)) + devices << (dir.absolutePath() + QString::fromLatin1("/") + deviceFile); + } + +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning() << "Static DeviceDiscovery found matching devices" << devices; +#endif + + return devices; +} + +bool QDeviceDiscovery::checkDeviceType(const QString &device) +{ + if ((m_types & (Device_Keyboard | Device_Mouse | Device_Touchpad | Device_Touchscreen)) && device.startsWith(QString::fromLatin1(QT_EVDEV_DEVICE_PREFIX))) + return true; + + if ((m_types & Device_DRM) && device.startsWith(QString::fromLatin1(QT_DRM_DEVICE_PREFIX))) + return true; + + return false; +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp b/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp new file mode 100644 index 0000000000..f7fe7cb87c --- /dev/null +++ b/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp @@ -0,0 +1,250 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdevicediscovery_p.h" + +#include +#include +#include +#include +#include + +#include + +//#define QT_QPA_DEVICE_DISCOVERY_DEBUG + +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG +#include +#endif + +QT_BEGIN_NAMESPACE + +QDeviceDiscovery *QDeviceDiscovery::create(QDeviceTypes types, QObject *parent) +{ +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning() << "Try to create new UDeviceHelper"; +#endif + + QDeviceDiscovery *helper = 0; + struct udev *udev; + + udev = udev_new(); + if (udev) { + helper = new QDeviceDiscovery(types, udev, parent); + } else { + qWarning("Failed to get udev library context."); + } + + return helper; +} + +QDeviceDiscovery::QDeviceDiscovery(QDeviceTypes types, struct udev *udev, QObject *parent) : + QObject(parent), + m_types(types), m_udev(udev), m_udevMonitor(0), m_udevMonitorFileDescriptor(-1), m_udevSocketNotifier(0) +{ +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning() << "New UDeviceHelper created for type" << types; +#endif + + if (!m_udev) + return; + + m_udevMonitor = udev_monitor_new_from_netlink(m_udev, "udev"); + if (!m_udevMonitor) { +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning("Unable to create an Udev monitor. No devices can be detected."); +#endif + return; + } + + udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "input", 0); + udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "drm", 0); + udev_monitor_enable_receiving(m_udevMonitor); + m_udevMonitorFileDescriptor = udev_monitor_get_fd(m_udevMonitor); + + m_udevSocketNotifier = new QSocketNotifier(m_udevMonitorFileDescriptor, QSocketNotifier::Read, this); + connect(m_udevSocketNotifier, SIGNAL(activated(int)), this, SLOT(handleUDevNotification())); +} + +QDeviceDiscovery::~QDeviceDiscovery() +{ + if (m_udevMonitor) + udev_monitor_unref(m_udevMonitor); + + if (m_udev) + udev_unref(m_udev); +} + +QStringList QDeviceDiscovery::scanConnectedDevices() +{ + QStringList devices; + + if (!m_udev) + return devices; + + udev_enumerate *ue = udev_enumerate_new(m_udev); + udev_enumerate_add_match_subsystem(ue, "input"); + udev_enumerate_add_match_subsystem(ue, "drm"); + + if (m_types & Device_Mouse) + udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1"); + if (m_types & Device_Touchpad) + udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1"); + if (m_types & Device_Touchscreen) + udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1"); + if (m_types & Device_Keyboard) + udev_enumerate_add_match_property(ue, "ID_INPUT_KEYBOARD", "1"); + + if (udev_enumerate_scan_devices(ue) != 0) { +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning() << "UDeviceHelper scan connected devices for enumeration failed"; +#endif + return devices; + } + + udev_list_entry *entry; + udev_list_entry_foreach (entry, udev_enumerate_get_list_entry(ue)) { + const char *syspath = udev_list_entry_get_name(entry); + udev_device *udevice = udev_device_new_from_syspath(m_udev, syspath); + QString candidate = QString::fromUtf8(udev_device_get_devnode(udevice)); + if ((m_types & Device_InputMask) && candidate.startsWith(QLatin1String(QT_EVDEV_DEVICE))) + devices << candidate; + if ((m_types & Device_VideoMask) && candidate.startsWith(QLatin1String(QT_DRM_DEVICE))) + devices << candidate; + + udev_device_unref(udevice); + } + udev_enumerate_unref(ue); + +#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG + qWarning() << "UDeviceHelper found matching devices" << devices; +#endif + + return devices; +} + +void QDeviceDiscovery::handleUDevNotification() +{ + if (!m_udevMonitor) + return; + + struct udev_device *dev; + QString devNode; + + dev = udev_monitor_receive_device(m_udevMonitor); + if (!dev) + goto cleanup; + + const char *action; + action = udev_device_get_action(dev); + if (!action) + goto cleanup; + + const char *str; + str = udev_device_get_devnode(dev); + if (!str) + goto cleanup; + + const char *subsystem; + devNode = QString::fromUtf8(str); + if (devNode.startsWith(QLatin1String(QT_EVDEV_DEVICE))) + subsystem = "input"; + else if (devNode.startsWith(QLatin1String(QT_DRM_DEVICE))) + subsystem = "drm"; + else goto cleanup; + + // if we cannot determine a type, walk up the device tree + if (!checkDeviceType(dev)) { + // does not increase the refcount + dev = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, 0); + if (!dev) + goto cleanup; + + if (!checkDeviceType(dev)) + goto cleanup; + } + + if (qstrcmp(action, "add") == 0) + emit deviceDetected(devNode); + + if (qstrcmp(action, "remove") == 0) + emit deviceRemoved(devNode); + +cleanup: + udev_device_unref(dev); +} + +bool QDeviceDiscovery::checkDeviceType(udev_device *dev) +{ + if (!dev) + return false; + + if ((m_types & Device_Keyboard) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"), "1") == 0 )) { + const char *capabilities_key = udev_device_get_sysattr_value(dev, "capabilities/key"); + QStringList val = QString::fromUtf8(capabilities_key).split(QString::fromUtf8(" "), QString::SkipEmptyParts); + if (!val.isEmpty()) { + bool ok; + unsigned long long keys = val.last().toULongLong(&ok, 16); + if (ok) { + // Tests if the letter Q is valid for the device. We may want to alter this test, but it seems mostly reliable. + bool test = (keys >> KEY_Q) & 1; + if (test) + return true; + } + } + } + + if ((m_types & Device_Mouse) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_MOUSE"), "1") == 0)) + return true; + + if ((m_types & Device_Touchpad) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD"), "1") == 0)) + return true; + + if ((m_types & Device_Touchscreen) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"), "1") == 0)) + return true; + + if ((m_types & Device_DRM) && (qstrcmp(udev_device_get_subsystem(dev), "drm") == 0)) + return true; + + return false; +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/platformsupport.pro b/src/platformsupport/platformsupport.pro index 47618f02e3..d035dda166 100644 --- a/src/platformsupport/platformsupport.pro +++ b/src/platformsupport/platformsupport.pro @@ -33,6 +33,6 @@ include(fontdatabases/fontdatabases.pri) include(glxconvenience/glxconvenience.pri) #include(printersupport/printersupport.pri) include(inputcontext/inputcontext.pri) -include(udev/udev.pri) +include(devicediscovery/devicediscovery.pri) include(services/services.pri) include(themes/themes.pri) diff --git a/src/platformsupport/udev/qudevicehelper.cpp b/src/platformsupport/udev/qudevicehelper.cpp deleted file mode 100644 index 0cf370badc..0000000000 --- a/src/platformsupport/udev/qudevicehelper.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qudevicehelper_p.h" - -#include -#include -#include -#include -#include - -#include - -//#define QT_QPA_UDEVICE_HELPER_DEBUG - -#ifdef QT_QPA_UDEVICE_HELPER_DEBUG -#include -#endif - -QT_BEGIN_NAMESPACE - -QUDeviceHelper *QUDeviceHelper::createUDeviceHelper(QUDeviceTypes types, QObject *parent) -{ -#ifdef QT_QPA_UDEVICE_HELPER_DEBUG - qWarning() << "Try to create new UDeviceHelper"; -#endif - - QUDeviceHelper *helper = 0; - struct udev *udev; - - udev = udev_new(); - if (udev) { - helper = new QUDeviceHelper(types, udev, parent); - } else { - qWarning("Failed to get udev library context."); - } - - return helper; -} - -QUDeviceHelper::QUDeviceHelper(QUDeviceTypes types, struct udev *udev, QObject *parent) : - QObject(parent), - m_udev(udev), m_types(types), m_udevMonitor(0), m_udevMonitorFileDescriptor(-1), m_udevSocketNotifier(0) -{ -#ifdef QT_QPA_UDEVICE_HELPER_DEBUG - qWarning() << "New UDeviceHelper created for type" << types; -#endif - - if (!m_udev) - return; - - m_udevMonitor = udev_monitor_new_from_netlink(m_udev, "udev"); - if (!m_udevMonitor) { -#ifdef QT_QPA_UDEVICE_HELPER_DEBUG - qWarning("Unable to create an Udev monitor. No devices can be detected."); -#endif - return; - } - - udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "input", 0); - udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "drm", 0); - udev_monitor_enable_receiving(m_udevMonitor); - m_udevMonitorFileDescriptor = udev_monitor_get_fd(m_udevMonitor); - - m_udevSocketNotifier = new QSocketNotifier(m_udevMonitorFileDescriptor, QSocketNotifier::Read, this); - connect(m_udevSocketNotifier, SIGNAL(activated(int)), this, SLOT(handleUDevNotification())); -} - -QUDeviceHelper::~QUDeviceHelper() -{ - if (m_udevMonitor) - udev_monitor_unref(m_udevMonitor); - - if (m_udev) - udev_unref(m_udev); -} - -QStringList QUDeviceHelper::scanConnectedDevices() -{ - QStringList devices; - - if (!m_udev) - return devices; - - udev_enumerate *ue = udev_enumerate_new(m_udev); - udev_enumerate_add_match_subsystem(ue, "input"); - udev_enumerate_add_match_subsystem(ue, "drm"); - - if (m_types & UDev_Mouse) - udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1"); - if (m_types & UDev_Touchpad) - udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1"); - if (m_types & UDev_Touchscreen) - udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1"); - if (m_types & UDev_Keyboard) - udev_enumerate_add_match_property(ue, "ID_INPUT_KEYBOARD", "1"); - - if (udev_enumerate_scan_devices(ue) != 0) { -#ifdef QT_QPA_UDEVICE_HELPER_DEBUG - qWarning() << "UDeviceHelper scan connected devices for enumeration failed"; -#endif - return devices; - } - - udev_list_entry *entry; - udev_list_entry_foreach (entry, udev_enumerate_get_list_entry(ue)) { - const char *syspath = udev_list_entry_get_name(entry); - udev_device *udevice = udev_device_new_from_syspath(m_udev, syspath); - QString candidate = QString::fromUtf8(udev_device_get_devnode(udevice)); - if ((m_types & UDev_InputMask) && candidate.startsWith(QLatin1String("/dev/input/event"))) - devices << candidate; - if ((m_types & UDev_VideoMask) && candidate.startsWith(QLatin1String("/dev/dri/card"))) - devices << candidate; - - udev_device_unref(udevice); - } - udev_enumerate_unref(ue); - -#ifdef QT_QPA_UDEVICE_HELPER_DEBUG - qWarning() << "UDeviceHelper found matching devices" << devices; -#endif - - return devices; -} - -void QUDeviceHelper::handleUDevNotification() -{ - if (!m_udevMonitor) - return; - - struct udev_device *dev; - QString devNode; - QUDeviceTypes types = QFlag(UDev_Unknown); - - dev = udev_monitor_receive_device(m_udevMonitor); - if (!dev) - goto cleanup; - - const char *action; - action = udev_device_get_action(dev); - if (!action) - goto cleanup; - - const char *str; - str = udev_device_get_devnode(dev); - if (!str) - goto cleanup; - - const char *subsystem; - devNode = QString::fromUtf8(str); - if (devNode.startsWith(QLatin1String("/dev/input/event"))) - subsystem = "input"; - else if (devNode.startsWith(QLatin1String("/dev/dri/card"))) - subsystem = "drm"; - else goto cleanup; - - types = checkDeviceType(dev); - - // if we cannot determine a type, walk up the device tree - if (types == UDev_Unknown) { - // does not increase the refcount - dev = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, 0); - if (!dev) - goto cleanup; - - types = checkDeviceType(dev); - } - - if (types && (qstrcmp(action, "add") == 0)) - emit deviceDetected(devNode, types); - - if (types && (qstrcmp(action, "remove") == 0)) - emit deviceRemoved(devNode, types); - -cleanup: - udev_device_unref(dev); -} - -QUDeviceHelper::QUDeviceTypes QUDeviceHelper::checkDeviceType(udev_device *dev) -{ - QUDeviceTypes types = QFlag(UDev_Unknown); - - if ((m_types & UDev_Keyboard) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"), "1") == 0 )) { - const char *capabilities_key = udev_device_get_sysattr_value(dev, "capabilities/key"); - QStringList val = QString::fromUtf8(capabilities_key).split(QString::fromUtf8(" "), QString::SkipEmptyParts); - if (!val.isEmpty()) { - bool ok; - unsigned long long keys = val.last().toULongLong(&ok, 16); - if (ok) { - // Tests if the letter Q is valid for the device. We may want to alter this test, but it seems mostly reliable. - bool test = (keys >> KEY_Q) & 1; - if (test) - types |= UDev_Keyboard; - } - } - } - - if ((m_types & UDev_Mouse) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_MOUSE"), "1") == 0)) - types |= UDev_Mouse; - - if ((m_types & UDev_Touchpad) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD"), "1") == 0)) - types |= UDev_Touchpad; - - if ((m_types & UDev_Touchscreen) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"), "1") == 0)) - types |= UDev_Touchscreen; - - if ((m_types & UDev_DRM) && (qstrcmp(udev_device_get_subsystem(dev), "drm") == 0)) - types |= UDev_DRM; - - return types; -} - -QT_END_NAMESPACE diff --git a/src/platformsupport/udev/qudevicehelper_p.h b/src/platformsupport/udev/qudevicehelper_p.h deleted file mode 100644 index 15dbe2926c..0000000000 --- a/src/platformsupport/udev/qudevicehelper_p.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QUDEVICEHELPER_H -#define QUDEVICEHELPER_H - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -class QUDeviceHelper : public QObject -{ - Q_OBJECT - Q_ENUMS(QUDeviceType) - -public: - enum QUDeviceType { - UDev_Unknown = 0x00, - UDev_Mouse = 0x01, - UDev_Touchpad = 0x02, - UDev_Touchscreen = 0x04, - UDev_Keyboard = 0x08, - UDev_DRM = 0x10, - UDev_InputMask = UDev_Mouse | UDev_Touchpad | UDev_Touchscreen | UDev_Keyboard, - UDev_VideoMask = UDev_DRM - }; - Q_DECLARE_FLAGS(QUDeviceTypes, QUDeviceType) - - static QUDeviceHelper *createUDeviceHelper(QUDeviceTypes type, QObject *parent); - ~QUDeviceHelper(); - - QStringList scanConnectedDevices(); - -signals: - void deviceDetected(const QString &deviceNode, QUDeviceTypes types); - void deviceRemoved(const QString &deviceNode, QUDeviceTypes types); - -private slots: - void handleUDevNotification(); - -private: - QUDeviceHelper(QUDeviceTypes types, struct udev *udev, QObject *parent = 0); - - void startWatching(); - void stopWatching(); - - QUDeviceTypes checkDeviceType(struct udev_device *dev); - - struct udev *m_udev; - QUDeviceTypes m_types; - struct udev_monitor *m_udevMonitor; - int m_udevMonitorFileDescriptor; - QSocketNotifier *m_udevSocketNotifier; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QUDeviceHelper::QUDeviceTypes) - -QT_END_NAMESPACE - -#endif // QUDEVICEHELPER_H diff --git a/src/platformsupport/udev/udev.pri b/src/platformsupport/udev/udev.pri deleted file mode 100644 index e3d7f2dadc..0000000000 --- a/src/platformsupport/udev/udev.pri +++ /dev/null @@ -1,7 +0,0 @@ -contains(QT_CONFIG, libudev) { - HEADERS += $$PWD/qudevicehelper_p.h - SOURCES += $$PWD/qudevicehelper.cpp - - INCLUDEPATH += $$QMAKE_INCDIR_LIBUDEV - LIBS += $$QMAKE_LIBS_LIBUDEV -} diff --git a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp index 6a891a4cb7..412695579d 100644 --- a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -56,11 +56,6 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & { Q_UNUSED(key); -#ifndef QT_NO_LIBUDEV - bool useUDev = true; -#else - bool useUDev = false; -#endif // QT_NO_LIBUDEV QStringList args = specification.split(QLatin1Char(':')); QStringList devices; @@ -69,7 +64,6 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & // if device is specified try to use it devices.append(arg); args.removeAll(arg); - useUDev = false; } } @@ -80,27 +74,23 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & foreach (const QString &device, devices) addKeyboard(device); -#ifndef QT_NO_LIBUDEV - if (useUDev) { + if (devices.isEmpty()) { #ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Use UDev for device discovery"; + qWarning() << "Use device discovery"; #endif - m_udeviceHelper = QUDeviceHelper::createUDeviceHelper(QUDeviceHelper::UDev_Keyboard, this); - if (m_udeviceHelper) { + m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard, this); + if (m_deviceDiscovery) { // scan and add already connected keyboards - QStringList devices = m_udeviceHelper->scanConnectedDevices(); + QStringList devices = m_deviceDiscovery->scanConnectedDevices(); foreach (QString device, devices) { addKeyboard(device); } - connect(m_udeviceHelper, SIGNAL(deviceDetected(QString,QUDeviceTypes)), this, SLOT(addKeyboard(QString))); - connect(m_udeviceHelper, SIGNAL(deviceRemoved(QString,QUDeviceTypes)), this, SLOT(removeKeyboard(QString))); + connect(m_deviceDiscovery, SIGNAL(deviceDetected(QString)), this, SLOT(addKeyboard(QString))); + connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeKeyboard(QString))); } } -#else - Q_UNUSED(useUDev) -#endif // QT_NO_LIBUDEV } QEvdevKeyboardManager::~QEvdevKeyboardManager() diff --git a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h index a505ce834e..e76814209e 100644 --- a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h +++ b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h @@ -44,9 +44,7 @@ #include "qevdevkeyboardhandler.h" -#ifndef QT_NO_LIBUDEV -#include -#endif // QT_NO_LIBUDEV +#include #include #include @@ -70,9 +68,7 @@ private slots: private: QString m_spec; QHash m_keyboards; -#ifndef QT_NO_LIBUDEV - QUDeviceHelper *m_udeviceHelper; -#endif // QT_NO_LIBUDEV + QDeviceDiscovery *m_deviceDiscovery; }; QT_END_HEADER diff --git a/src/plugins/generic/evdevmouse/qevdevmousemanager.cpp b/src/plugins/generic/evdevmouse/qevdevmousemanager.cpp index 07d7d0fe06..8547e444f0 100644 --- a/src/plugins/generic/evdevmouse/qevdevmousemanager.cpp +++ b/src/plugins/generic/evdevmouse/qevdevmousemanager.cpp @@ -46,7 +46,7 @@ #include #include -#define QT_QPA_MOUSEMANAGER_DEBUG +//#define QT_QPA_MOUSEMANAGER_DEBUG #ifdef QT_QPA_MOUSEMANAGER_DEBUG #include @@ -59,11 +59,6 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif { Q_UNUSED(key); -#ifndef QT_NO_LIBUDEV - bool useUDev = true; -#else - bool useUDev = false; -#endif // QT_NO_LIBUDEV QStringList args = specification.split(QLatin1Char(':')); QStringList devices; @@ -72,7 +67,6 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif // if device is specified try to use it devices.append(arg); args.removeAll(arg); - useUDev = false; } else if (arg.startsWith("xoffset=")) { m_xoffset = arg.mid(8).toInt(); } else if (arg.startsWith("yoffset=")) { @@ -87,27 +81,23 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif foreach (const QString &device, devices) addMouse(device); -#ifdef QT_NO_LIBUDEV - Q_UNUSED(useUDev) -#else - if (useUDev) { + if (devices.isEmpty()) { #ifdef QT_QPA_MOUSEMANAGER_DEBUG - qWarning() << "Use UDev for device discovery"; + qWarning() << "Use device discovery"; #endif - m_udeviceHelper = QUDeviceHelper::createUDeviceHelper(QUDeviceHelper::UDev_Mouse | QUDeviceHelper::UDev_Touchpad, this); - if (m_udeviceHelper) { + m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this); + if (m_deviceDiscovery) { // scan and add already connected keyboards - QStringList devices = m_udeviceHelper->scanConnectedDevices(); + QStringList devices = m_deviceDiscovery->scanConnectedDevices(); foreach (QString device, devices) { addMouse(device); } - connect(m_udeviceHelper, SIGNAL(deviceDetected(QString,QUDeviceTypes)), this, SLOT(addMouse(QString))); - connect(m_udeviceHelper, SIGNAL(deviceRemoved(QString,QUDeviceTypes)), this, SLOT(removeMouse(QString))); + connect(m_deviceDiscovery, SIGNAL(deviceDetected(QString)), this, SLOT(addMouse(QString))); + connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeMouse(QString))); } } -#endif // QT_NO_LIBUDEV } QEvdevMouseManager::~QEvdevMouseManager() diff --git a/src/plugins/generic/evdevmouse/qevdevmousemanager.h b/src/plugins/generic/evdevmouse/qevdevmousemanager.h index 7a1e705ed1..b90347986b 100644 --- a/src/plugins/generic/evdevmouse/qevdevmousemanager.h +++ b/src/plugins/generic/evdevmouse/qevdevmousemanager.h @@ -44,9 +44,7 @@ #include "qevdevmousehandler.h" -#ifndef QT_NO_LIBUDEV -#include -#endif // QT_NO_LIBUDEV +#include #include #include @@ -73,9 +71,7 @@ private slots: private: QString m_spec; QHash m_mice; -#ifndef QT_NO_LIBUDEV - QUDeviceHelper *m_udeviceHelper; -#endif // QT_NO_LIBUDEV + QDeviceDiscovery *m_deviceDiscovery; int m_x; int m_y; int m_xoffset; diff --git a/src/plugins/generic/evdevtouch/qevdevtouch.cpp b/src/plugins/generic/evdevtouch/qevdevtouch.cpp index 37db20a419..c372b0d1ff 100644 --- a/src/plugins/generic/evdevtouch/qevdevtouch.cpp +++ b/src/plugins/generic/evdevtouch/qevdevtouch.cpp @@ -46,9 +46,7 @@ #include #include #include -#ifndef QT_NO_LIBUDEV -#include -#endif // QT_NO_LIBUDEV +#include #include #ifdef USE_MTDEV @@ -159,22 +157,20 @@ QTouchScreenHandler::QTouchScreenHandler(const QString &spec) } } -#ifndef QT_NO_LIBUDEV if (dev.isEmpty()) { // try to let udev scan for already connected devices - QScopedPointer udeviceHelper(QUDeviceHelper::createUDeviceHelper(QUDeviceHelper::UDev_Touchpad | QUDeviceHelper::UDev_Touchscreen, this)); - if (udeviceHelper) { - QStringList devices = udeviceHelper->scanConnectedDevices(); + QScopedPointer deviceDiscovery(QDeviceDiscovery::create(QDeviceDiscovery::Device_Touchpad | QDeviceDiscovery::Device_Touchscreen, this)); + if (deviceDiscovery) { + QStringList devices = deviceDiscovery->scanConnectedDevices(); // only the first device found is used for now if (devices.size() > 0) dev = devices[0]; } } -#endif // QT_NO_LIBUDEV if (dev.isEmpty()) - dev = QLatin1String("/dev/input/event0"); + return; qDebug("evdevtouch: Using device %s", qPrintable(dev)); m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); -- cgit v1.2.3