From 68ea2f7e9bb2d4ea6182101521325dbfd9b74abb Mon Sep 17 00:00:00 2001 From: Romain Pokrzywka Date: Tue, 22 Sep 2015 11:38:09 -0700 Subject: 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 Reviewed-by: Laszlo Agocs --- src/gui/kernel/qtouchdevice.cpp | 11 +++++++++++ src/gui/kernel/qtouchdevice_p.h | 1 + src/gui/kernel/qwindowsysteminterface.cpp | 7 ++++++- src/gui/kernel/qwindowsysteminterface.h | 3 ++- 4 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qtouchdevice.cpp b/src/gui/kernel/qtouchdevice.cpp index 9d19fa4b92..266b5308a2 100644 --- a/src/gui/kernel/qtouchdevice.cpp +++ b/src/gui/kernel/qtouchdevice.cpp @@ -237,6 +237,17 @@ void QTouchDevicePrivate::registerDevice(const QTouchDevice *dev) deviceList()->append(dev); } +/*! + \internal + */ +void QTouchDevicePrivate::unregisterDevice(const QTouchDevice *dev) +{ + QMutexLocker lock(&devicesMutex); + bool wasRemoved = deviceList()->removeOne(dev); + if (wasRemoved && deviceList()->isEmpty()) + qRemovePostRoutine(cleanupDevicesList); +} + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const QTouchDevice *device) { diff --git a/src/gui/kernel/qtouchdevice_p.h b/src/gui/kernel/qtouchdevice_p.h index 4aff8f2f33..63b83d33ec 100644 --- a/src/gui/kernel/qtouchdevice_p.h +++ b/src/gui/kernel/qtouchdevice_p.h @@ -65,6 +65,7 @@ public: int maxTouchPoints; static void registerDevice(const QTouchDevice *dev); + static void unregisterDevice(const QTouchDevice *dev); static bool isRegistered(const QTouchDevice *dev); }; diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 91a935ad0f..faa1ff8068 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -486,11 +486,16 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent(QWindowSystemInterfa return accepted; } -void QWindowSystemInterface::registerTouchDevice(QTouchDevice *device) +void QWindowSystemInterface::registerTouchDevice(const QTouchDevice *device) { QTouchDevicePrivate::registerDevice(device); } +void QWindowSystemInterface::unregisterTouchDevice(const QTouchDevice *device) +{ + QTouchDevicePrivate::unregisterDevice(device); +} + void QWindowSystemInterface::handleTouchEvent(QWindow *w, QTouchDevice *device, const QList &points, Qt::KeyboardModifiers mods) { diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 99589e8aa1..97bd087b53 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -127,7 +127,8 @@ public: QVector rawPositions; // in screen coordinates }; - static void registerTouchDevice(QTouchDevice *device); + static void registerTouchDevice(const QTouchDevice *device); + static void unregisterTouchDevice(const QTouchDevice *device); static void handleTouchEvent(QWindow *w, QTouchDevice *device, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); static void handleTouchEvent(QWindow *w, ulong timestamp, QTouchDevice *device, -- cgit v1.2.3