summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowspointerhandler.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-01 14:37:29 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-03 07:39:14 +0200
commit3fb31819fd4a209873ef671494cba8bd95dae73a (patch)
treea61b064804d5b2d7010b83cb17f31983885e8a38 /src/plugins/platforms/windows/qwindowspointerhandler.cpp
parent39d99c714bb87bd39e92d85fb1f46c52eb9f8d33 (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/plugins/platforms/windows/qwindowspointerhandler.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowspointerhandler.cpp51
1 files changed, 27 insertions, 24 deletions
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()