From ee677dc8d85b36990d67e1be0e6e3187fd6b6a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 12 Apr 2013 13:44:56 +0200 Subject: Enable touch events on Mac for MultiPointTouchArea Enabling touch events on a window causes scroll event lag so we want to avoid avoid it as far as possible. Enable/disable on scene changes, similar to what we do for WA_AcceptTouchEvents for widgets. Task-number: QTBUG-28483 Change-Id: I2e5b5e2b093cccfc5253f7228f5ec0c588c60371 Reviewed-by: Shawn Rutledge Reviewed-by: Gabriel de Dietrich --- src/quick/items/qquickmultipointtoucharea.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/quick/items/qquickmultipointtoucharea.cpp') diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp index 384c1c7ac8..a6c92ac060 100644 --- a/src/quick/items/qquickmultipointtoucharea.cpp +++ b/src/quick/items/qquickmultipointtoucharea.cpp @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -322,6 +323,7 @@ void QQuickTouchPoint::setSceneY(qreal sceneY) QQuickMultiPointTouchArea::QQuickMultiPointTouchArea(QQuickItem *parent) : QQuickItem(parent), + _currentWindow(0), _minimumTouchPoints(0), _maximumTouchPoints(INT_MAX), _stealMouse(false) @@ -331,6 +333,9 @@ QQuickMultiPointTouchArea::QQuickMultiPointTouchArea(QQuickItem *parent) if (qmlVisualTouchDebugging()) { setFlag(QQuickItem::ItemHasContents); } +#ifdef Q_OS_MAC + connect(this, &QQuickItem::windowChanged, this, &QQuickMultiPointTouchArea::setTouchEventsEnabledForWindow); +#endif } QQuickMultiPointTouchArea::~QQuickMultiPointTouchArea() @@ -542,6 +547,27 @@ void QQuickMultiPointTouchArea::addTouchPoint(const QTouchEvent::TouchPoint *p) _pressedTouchPoints.append(dtp); } +void QQuickMultiPointTouchArea::setTouchEventsEnabledForWindow(QWindow *window) +{ +#ifdef Q_OS_MAC + // Resolve function for enabling touch events from the (cocoa) platform plugin. + typedef void (*RegisterTouchWindowFunction)(QWindow *, bool); + RegisterTouchWindowFunction registerTouchWindow = reinterpret_cast( + QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow")); + if (!registerTouchWindow) + return; // Not necessarily an error, Qt migh be using a different platform plugin. + + // Disable touch on the old window, enable on the new window. + if (_currentWindow) + registerTouchWindow(_currentWindow, false); + if (window) + registerTouchWindow(window, true); + // Save the current window, setTouchEventsEnabledForWindow will be called + // with a null window on disable. + _currentWindow = window; +#endif +} + void QQuickMultiPointTouchArea::addTouchPrototype(QQuickTouchPoint *prototype) { int id = _touchPrototypes.count(); -- cgit v1.2.3 From 3fb03d8e0d8275349241eee619466698f6fc4825 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 6 May 2013 10:57:53 +0200 Subject: Fix warnings about unused parameters. Change-Id: I091a0369f2026ae820d623aadd13a3190d40a56b Reviewed-by: Shawn Rutledge --- src/quick/items/qquickmultipointtoucharea.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/quick/items/qquickmultipointtoucharea.cpp') diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp index a6c92ac060..d6b00cee14 100644 --- a/src/quick/items/qquickmultipointtoucharea.cpp +++ b/src/quick/items/qquickmultipointtoucharea.cpp @@ -565,6 +565,8 @@ void QQuickMultiPointTouchArea::setTouchEventsEnabledForWindow(QWindow *window) // Save the current window, setTouchEventsEnabledForWindow will be called // with a null window on disable. _currentWindow = window; +#else // Q_OS_MAC + Q_UNUSED(window) #endif } -- cgit v1.2.3