diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-01 14:37:29 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-03 07:39:14 +0200 |
commit | 3fb31819fd4a209873ef671494cba8bd95dae73a (patch) | |
tree | a61b064804d5b2d7010b83cb17f31983885e8a38 /src | |
parent | 39d99c714bb87bd39e92d85fb1f46c52eb9f8d33 (diff) |
Windows QPA: Refactor touch device creation
There was duplicated code in QWindowsMouseHandler::ensureTouchDevice() and
QWindowsPointerHandler::ensureTouchDevice() which caused deprecation
warnings since the setters of QInputDevice were deprecated.
Join the 2 functions into a single creation function and add simple getters
and setters.
Fix deprecation warnings:
qwindowscontext.cpp:357:108: warning: 'void
QPointingDevice::setCapabilities(QInputDevice::Capabilities)' is deprecated: Use the constructor
qwindowsmousehandler.cpp:132:97: warning: 'void QPointingDevice::setType(QInputDevice::DeviceType)' is deprecated: Use the constructor
qwindowsmousehandler.cpp:136:41: warning: 'void QPointingDevice::setCapabilities(QInputDevice::Capabilities)' is deprecated: Use the constructor
qwindowsmousehandler.cpp:137:49: warning: 'void QPointingDevice::setMaximumTouchPoints(int)' is deprecated: Use the constructor
Change-Id: Iab5385e84d600e45b60f38225175f25ef043c3eb
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
5 files changed, 43 insertions, 60 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index f17fc1629b..161777d70f 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -347,14 +347,19 @@ bool QWindowsContext::initTouch(unsigned integrationOptions) { if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch) return true; - - QPointingDevice *touchDevice = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) ? - d->m_pointerHandler.ensureTouchDevice() : d->m_mouseHandler.ensureTouchDevice(); + const bool usePointerHandler = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) != 0; + auto touchDevice = usePointerHandler ? d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); + if (!touchDevice) { + const bool mouseEmulation = + (integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0; + touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation); + } if (!touchDevice) return false; - - if (!(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch)) - touchDevice->setCapabilities(touchDevice->capabilities() | QInputDevice::Capability::MouseEmulation); + if (usePointerHandler) + d->m_pointerHandler.setTouchDevice(touchDevice); + else + d->m_mouseHandler.setTouchDevice(touchDevice); QWindowSystemInterface::registerInputDevice(touchDevice); diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 4fd6e4131e..4efeaa9d34 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -117,27 +117,6 @@ static inline void compressMouseMove(MSG *msg) } } -static inline QPointingDevice *createTouchDevice() -{ - const int digitizers = GetSystemMetrics(SM_DIGITIZER); - if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) - return nullptr; - const int tabletPc = GetSystemMetrics(SM_TABLETPC); - const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES); - qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) - << "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase - << "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints; - auto *result = new QPointingDevice; - result->setType(digitizers & NID_INTEGRATED_TOUCH - ? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad); - QPointingDevice::Capabilities capabilities = QPointingDevice::Capability::Position | QPointingDevice::Capability::Area | QPointingDevice::Capability::NormalizedPosition; - if (result->type() == QInputDevice::DeviceType::TouchPad) - capabilities.setFlag(QInputDevice::Capability::MouseEmulation); - result->setCapabilities(capabilities); - result->setMaximumTouchPoints(maxTouchPoints); - return result; -} - /*! \class QWindowsMouseHandler \brief Windows mouse handler @@ -149,13 +128,6 @@ static inline QPointingDevice *createTouchDevice() QWindowsMouseHandler::QWindowsMouseHandler() = default; -QPointingDevice *QWindowsMouseHandler::ensureTouchDevice() -{ - if (!m_touchDevice) - m_touchDevice = createTouchDevice(); - return m_touchDevice; -} - void QWindowsMouseHandler::clearEvents() { m_lastEventType = QEvent::None; diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.h b/src/plugins/platforms/windows/qwindowsmousehandler.h index 764733e3ad..0b7f26f6c6 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.h +++ b/src/plugins/platforms/windows/qwindowsmousehandler.h @@ -59,7 +59,7 @@ public: QWindowsMouseHandler(); QPointingDevice *touchDevice() const { return m_touchDevice; } - QPointingDevice *ensureTouchDevice(); + void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; } bool translateMouseEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp index 7c6ca0a61e..7dc2bd729a 100644 --- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp +++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp @@ -317,31 +317,34 @@ static bool isValidWheelReceiver(QWindow *candidate) return false; } -QPointingDevice *QWindowsPointerHandler::ensureTouchDevice() +QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation) { - if (!m_touchDevice) { - const int digitizers = GetSystemMetrics(SM_DIGITIZER); - if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) - return nullptr; - const int tabletPc = GetSystemMetrics(SM_TABLETPC); - const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES); - const bool touchScreen = digitizers & NID_INTEGRATED_TOUCH; - QPointingDevice::Capabilities capabilities = QPointingDevice::Capability::Position; - if (!touchScreen) { - capabilities.setFlag(QInputDevice::Capability::MouseEmulation); - capabilities.setFlag(QInputDevice::Capability::Scroll); - } - qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) - << "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase - << "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities; - // TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId - m_touchDevice = new QPointingDevice(QString(), m_nextInputDeviceId++, - (touchScreen ? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad), - QPointingDevice::PointerType::Finger, capabilities, maxTouchPoints, - // TODO: precise button count (detect whether the touchpad can emulate 3 or more buttons) - (touchScreen ? 1 : 3)); - } - return m_touchDevice; + const int digitizers = GetSystemMetrics(SM_DIGITIZER); + if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) + return nullptr; + const int tabletPc = GetSystemMetrics(SM_TABLETPC); + const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES); + const QPointingDevice::DeviceType type = (digitizers & NID_INTEGRATED_TOUCH) + ? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad; + QInputDevice::Capabilities capabilities = QInputDevice::Capability::Position + | QInputDevice::Capability::Area + | QInputDevice::Capability::NormalizedPosition; + if (type != QInputDevice::DeviceType::TouchScreen) { + capabilities.setFlag(QInputDevice::Capability::MouseEmulation); + capabilities.setFlag(QInputDevice::Capability::Scroll); + } else if (mouseEmulation) { + capabilities.setFlag(QInputDevice::Capability::MouseEmulation); + } + + qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) + << "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); } void QWindowsPointerHandler::clearEvents() diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.h b/src/plugins/platforms/windows/qwindowspointerhandler.h index d232941ba5..3b204c675b 100644 --- a/src/plugins/platforms/windows/qwindowspointerhandler.h +++ b/src/plugins/platforms/windows/qwindowspointerhandler.h @@ -61,8 +61,11 @@ public: ~QWindowsPointerHandler(); 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; } - QPointingDevice *ensureTouchDevice(); + void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; } + static QPointingDevice *createTouchDevice(bool mouseEmulation); + QWindow *windowUnderMouse() const { return m_windowUnderPointer.data(); } void clearWindowUnderMouse() { m_windowUnderPointer = nullptr; } void clearEvents(); |