From e3470a98e98c8a789a4cb298a0afaacf0cc62ce9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 16 Oct 2020 11:50:27 +0200 Subject: Windows QPA: Use a QSharedPointer for the touch device For reasons of symmetry with the tablet devices. As a drive by, give it more distinct IDs. Task-number: QTBUG-46412 Change-Id: Ie667621246b26db6fdda84c5ff2455fe38633cb3 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowscontext.cpp | 19 +++++-------------- src/plugins/platforms/windows/qwindowscontext.h | 2 -- .../platforms/windows/qwindowsmousehandler.cpp | 2 +- src/plugins/platforms/windows/qwindowsmousehandler.h | 9 ++++++--- .../platforms/windows/qwindowspointerhandler.cpp | 19 +++++++++++-------- .../platforms/windows/qwindowspointerhandler.h | 8 ++++---- 6 files changed, 27 insertions(+), 32 deletions(-) (limited to 'src/plugins/platforms/windows') diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 1e5b247f0f..b2cbae408c 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -349,19 +349,16 @@ bool QWindowsContext::initTouch(unsigned integrationOptions) return true; const bool usePointerHandler = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) != 0; auto touchDevice = usePointerHandler ? d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); - if (!touchDevice) { + if (touchDevice.isNull()) { const bool mouseEmulation = (integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0; touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation); } - if (!touchDevice) + if (touchDevice.isNull()) return false; - if (usePointerHandler) - d->m_pointerHandler.setTouchDevice(touchDevice); - else - d->m_mouseHandler.setTouchDevice(touchDevice); - - QWindowSystemInterface::registerInputDevice(touchDevice); + d->m_pointerHandler.setTouchDevice(touchDevice); + d->m_mouseHandler.setTouchDevice(touchDevice); + QWindowSystemInterface::registerInputDevice(touchDevice.data()); d->m_systemInfo |= QWindowsContext::SI_SupportsTouch; @@ -1637,12 +1634,6 @@ void QWindowsContext::setAsyncExpose(bool value) d->m_asyncExpose = value; } -QPointingDevice *QWindowsContext::touchDevice() const -{ - return (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) ? - d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); -} - DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue) { const auto value = diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h index 0cc5f0f595..aacdafebb6 100644 --- a/src/plugins/platforms/windows/qwindowscontext.h +++ b/src/plugins/platforms/windows/qwindowscontext.h @@ -266,8 +266,6 @@ public: static DWORD readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue); - QPointingDevice *touchDevice() const; - static bool filterNativeEvent(MSG *msg, LRESULT *result); static bool filterNativeEvent(QWindow *window, MSG *msg, LRESULT *result); diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 02c59d4d27..060b3a84bb 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -652,7 +652,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, m_touchInputIDToTouchPointID.clear(); QWindowSystemInterface::handleTouchEvent(window, - m_touchDevice, + m_touchDevice.data(), touchPoints, QWindowsKeyMapper::queryKeyboardModifiers()); return true; diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.h b/src/plugins/platforms/windows/qwindowsmousehandler.h index 0b7f26f6c6..c007cf5a5b 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.h +++ b/src/plugins/platforms/windows/qwindowsmousehandler.h @@ -45,6 +45,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -56,10 +57,12 @@ class QWindowsMouseHandler { Q_DISABLE_COPY_MOVE(QWindowsMouseHandler) public: + using QPointingDevicePtr = QSharedPointer; + QWindowsMouseHandler(); - QPointingDevice *touchDevice() const { return m_touchDevice; } - void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; } + const QPointingDevicePtr &touchDevice() const { return m_touchDevice; } + void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; } bool translateMouseEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, @@ -90,7 +93,7 @@ private: QPointer m_trackedWindow; QHash m_touchInputIDToTouchPointID; QHash m_lastTouchPositions; - QPointingDevice *m_touchDevice = nullptr; + QPointingDevicePtr m_touchDevice; bool m_leftButtonDown = false; QWindow *m_previousCaptureWindow = nullptr; QEvent::Type m_lastEventType = QEvent::None; diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp index 41f17f5c3b..7c021700f2 100644 --- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp +++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp @@ -82,7 +82,6 @@ qint64 QWindowsPointerHandler::m_nextInputDeviceId = 1; QWindowsPointerHandler::~QWindowsPointerHandler() { - delete m_touchDevice; } bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result) @@ -320,7 +319,7 @@ static bool isValidWheelReceiver(QWindow *candidate) return false; } -QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation) +QWindowsPointerHandler::QPointingDevicePtr QWindowsPointerHandler::createTouchDevice(bool mouseEmulation) { const int digitizers = GetSystemMetrics(SM_DIGITIZER); if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) @@ -339,15 +338,19 @@ QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation) capabilities.setFlag(QInputDevice::Capability::MouseEmulation); } - qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) + const int flags = digitizers & ~NID_READY; + qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << flags << "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase << "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities; const int buttonCount = type == QInputDevice::DeviceType::TouchScreen ? 1 : 3; // TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId - return new QPointingDevice(QString(), m_nextInputDeviceId++, - type, QPointingDevice::PointerType::Finger, - capabilities, maxTouchPoints, buttonCount); + const qint64 systemId = m_nextInputDeviceId++ | (qint64(flags << 2)); + auto d = new QPointingDevice(QString(), systemId, type, + QPointingDevice::PointerType::Finger, + capabilities, maxTouchPoints, buttonCount, + QString(), QPointingDeviceUniqueId::fromNumericId(systemId)); + return QPointingDevicePtr(d); } void QWindowsPointerHandler::clearEvents() @@ -466,7 +469,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd, return false; if (msg.message == WM_POINTERCAPTURECHANGED) { - QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice, + QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice.data(), QWindowsKeyMapper::queryKeyboardModifiers()); m_lastTouchPositions.clear(); return true; @@ -550,7 +553,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd, if (allStates == QEventPoint::State::Released) m_touchInputIDToTouchPointID.clear(); - QWindowSystemInterface::handleTouchEvent(window, m_touchDevice, touchPoints, + QWindowSystemInterface::handleTouchEvent(window, m_touchDevice.data(), touchPoints, QWindowsKeyMapper::queryKeyboardModifiers()); return false; // Allow mouse messages to be generated. } diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.h b/src/plugins/platforms/windows/qwindowspointerhandler.h index d0f0b816d3..6b02412e74 100644 --- a/src/plugins/platforms/windows/qwindowspointerhandler.h +++ b/src/plugins/platforms/windows/qwindowspointerhandler.h @@ -65,9 +65,9 @@ public: bool translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result); bool translateMouseEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result); - QPointingDevice *touchDevice() const { return m_touchDevice; } - void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; } - static QPointingDevice *createTouchDevice(bool mouseEmulation); + const QPointingDevicePtr &touchDevice() const { return m_touchDevice; } + void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; } + static QPointingDevicePtr createTouchDevice(bool mouseEmulation); QWindow *windowUnderMouse() const { return m_windowUnderPointer.data(); } void clearWindowUnderMouse() { m_windowUnderPointer = nullptr; } @@ -83,7 +83,7 @@ private: QPointingDevicePtr findTabletDevice(QPointingDevice::PointerType pointerType) const; #endif - QPointingDevice *m_touchDevice = nullptr; + QPointingDevicePtr m_touchDevice; #if QT_CONFIG(tabletevent) QList m_tabletDevices; #endif -- cgit v1.2.3