diff options
author | Romain Pokrzywka <romain.pokrzywka@bluescape.com> | 2015-09-22 11:38:09 -0700 |
---|---|---|
committer | Romain Pokrzywka <romain.pokrzywka@gmail.com> | 2015-09-23 16:29:30 +0000 |
commit | 68ea2f7e9bb2d4ea6182101521325dbfd9b74abb (patch) | |
tree | 567634fce8b3e51cdd8fee16eef6048b9359c561 /src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp | |
parent | 29bc68cf169b8cf87d306a1c72e12eb9b6fbfce7 (diff) |
Synchronize QInputDeviceManager touch device count with QTouchDevice
This ensures that the values and signals reported by QInputDeviceManager
for touch devices always have corresponding entries in the list returned
by QTouchDevice::devices().
It also adds proper QTouchDevice unregistration when the underlying
input device gets removed by the evdevtouch QPA plugin.
Change-Id: I7bdf2f7435c775d15bddce8ba1e731afdc1d948a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp')
-rw-r--r-- | src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp index 98fc83700c..35a685ff21 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp @@ -91,17 +91,17 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif QEvdevTouchManager::~QEvdevTouchManager() { qDeleteAll(m_activeDevices); + updateInputDeviceCount(); } void QEvdevTouchManager::addDevice(const QString &deviceNode) { - qCDebug(qLcEvdevTouch) << "Adding device at" << deviceNode; + qCDebug(qLcEvdevTouch) << "evdevtouch: Adding device at" << deviceNode; QEvdevTouchScreenHandlerThread *handler; handler = new QEvdevTouchScreenHandlerThread(deviceNode, m_spec); if (handler) { m_activeDevices.insert(deviceNode, handler); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTouch, m_activeDevices.count()); + connect(handler, &QEvdevTouchScreenHandlerThread::touchDeviceRegistered, this, &QEvdevTouchManager::updateInputDeviceCount); } else { qWarning("evdevtouch: Failed to open touch device %s", qPrintable(deviceNode)); } @@ -110,13 +110,28 @@ void QEvdevTouchManager::addDevice(const QString &deviceNode) void QEvdevTouchManager::removeDevice(const QString &deviceNode) { if (m_activeDevices.contains(deviceNode)) { - qCDebug(qLcEvdevTouch) << "Removing device at" << deviceNode; + qCDebug(qLcEvdevTouch) << "evdevtouch: Removing device at" << deviceNode; QEvdevTouchScreenHandlerThread *handler = m_activeDevices.value(deviceNode); m_activeDevices.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTouch, m_activeDevices.count()); delete handler; + + updateInputDeviceCount(); } } +void QEvdevTouchManager::updateInputDeviceCount() +{ + int registeredTouchDevices = 0; + Q_FOREACH (QEvdevTouchScreenHandlerThread *handler, m_activeDevices) { + if (handler->isTouchDeviceRegistered()) + ++registeredTouchDevices; + } + + qCDebug(qLcEvdevTouch) << "evdevtouch: Updating QInputDeviceManager device count:" << registeredTouchDevices << " touch devices," + << m_activeDevices.count() - registeredTouchDevices << "pending handler(s)" ; + + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypeTouch, registeredTouchDevices); +} + QT_END_NAMESPACE |