From aa4ff7b2e9d4523dbc44afad98a4e3570ec6a997 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 12 Sep 2017 17:07:54 +0200 Subject: macOS touch and gestures: pay attention to deviceID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we pretended that there is only one touch device; but in fact, different trackpads have different deviceIDs, and this may be useful in some scenarios to tell them apart, as on other platforms. So far we don't expect to get touch events from actual touchscreens though, because macOS only turns single-touch events into mouse events and does not interpret gestures on touchscreens. So there isn't API which can distinguish touchscreens from touchpads as far as we know. QCocoaTouch::getTouchDevice() takes the type as a parameter, just in case this changes some day. Change-Id: I56228471363235c5d0cc2a55a35a3c3288f3b1a1 Reviewed-by: Jan Arve Sæther --- src/plugins/platforms/cocoa/qmultitouch_mac.mm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/plugins/platforms/cocoa/qmultitouch_mac.mm') diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm index f0ea3b1e66..79f8af7783 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm +++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm @@ -39,10 +39,14 @@ #include "qmultitouch_mac_p.h" #include "qcocoahelpers.h" +#include QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcInputDevices, "qt.qpa.input.devices") + QHash QCocoaTouch::_currentTouches; +QHash QCocoaTouch::_touchDevices; QPointF QCocoaTouch::_screenReferencePos; QPointF QCocoaTouch::_trackpadReferencePos; int QCocoaTouch::_idAssignmentCount = 0; @@ -209,4 +213,19 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) return touchPoints.values(); } +QTouchDevice *QCocoaTouch::getTouchDevice(QTouchDevice::DeviceType type, quint64 id) +{ + QTouchDevice *ret = _touchDevices.value(id); + if (!ret) { + ret = new QTouchDevice; + ret->setType(type); + ret->setCapabilities(QTouchDevice::Position | QTouchDevice::NormalizedPosition | QTouchDevice::MouseEmulation); + QWindowSystemInterface::registerTouchDevice(ret); + _touchDevices.insert(id, ret); + qCDebug(lcInputDevices) << "touch device" << id << "of type" << type + << "registered as Qt device" << QTouchDevicePrivate::get(ret)->id; + } + return ret; +} + QT_END_NAMESPACE -- cgit v1.2.3