diff options
author | Mike Achtelik <mike.achtelik@gmail.com> | 2021-08-04 14:30:34 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2022-03-18 00:20:57 +0000 |
commit | 879c14e9ff118a2ccb4f21428adbf4288bb5b13e (patch) | |
tree | 3dab3a418fc8ba8d5d7db32f74aa137f4bcafc78 | |
parent | ee386d92651e3542976d438eecca719e4d83fe82 (diff) | |
download | qtbase-879c14e9ff118a2ccb4f21428adbf4288bb5b13e.tar.gz |
Android: Treat ACTION_CANCEL as TouchCancelEvent
Change 64d62c53c1e92a1cc07449a0ea3c71501592c1e7 started treating an
ACTION_CANCEL as a TouchPointReleased. This leads to unintentional
presses, if e.g. an edge swipe for the android back gesture starts on a
MouseArea.
When Android takes possession of the motion, an ACTION_CANCEL is
delivered, which needs to be handled as such. It should not be treated
as a normal up event that triggers a press. Otherwise, we get the
above-mentioned issue, where an unintentional action is performed.
So let's use QWindowSystemInterface::handleTouchCancelEvent to treat it
as a canceled touch in Qt.
Task-number: QTBUG-72110
Change-Id: I68650a180130501568e5a1e9a7f20ea469461e97
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit d6da61f3b9e7e57e85d1e16f2756a8e39e571f77)
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtNative.java | 11 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniinput.cpp | 38 |
2 files changed, 40 insertions, 9 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java index 6742a3781b..b077014b81 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -708,9 +708,11 @@ public class QtNative } return 1; } - if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN && index == event.getActionIndex()) { + if (action == MotionEvent.ACTION_DOWN + || action == MotionEvent.ACTION_POINTER_DOWN && index == event.getActionIndex()) { return 0; - } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_POINTER_UP && index == event.getActionIndex()) { + } else if (action == MotionEvent.ACTION_UP + || action == MotionEvent.ACTION_POINTER_UP && index == event.getActionIndex()) { return 3; } return 2; @@ -762,6 +764,10 @@ public class QtNative touchEnd(id, 2); break; + case MotionEvent.ACTION_CANCEL: + touchCancel(id); + break; + default: touchEnd(id, 1); } @@ -1365,6 +1371,7 @@ public class QtNative public static native void touchBegin(int winId); public static native void touchAdd(int winId, int pointerId, int action, boolean primary, int x, int y, float major, float minor, float rotation, float pressure); public static native void touchEnd(int winId, int action); + public static native void touchCancel(int winId); public static native void longPress(int winId, int x, int y); // pointer methods diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 8ec77e7c97..726caa5015 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -263,18 +263,14 @@ namespace QtAndroidInput } } - static void touchEnd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint /*action*/) + static QTouchDevice *getTouchDevice() { - if (m_touchPoints.isEmpty()) - return; - - QMutexLocker lock(QtAndroid::platformInterfaceMutex()); QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration(); if (!platformIntegration) - return; + return nullptr; QTouchDevice *touchDevice = platformIntegration->touchDevice(); - if (touchDevice == 0) { + if (!touchDevice) { touchDevice = new QTouchDevice; touchDevice->setType(QTouchDevice::TouchScreen); touchDevice->setCapabilities(QTouchDevice::Position @@ -285,10 +281,37 @@ namespace QtAndroidInput platformIntegration->setTouchDevice(touchDevice); } + return touchDevice; + } + + static void touchEnd(JNIEnv * /*env*/, jobject /*thiz*/, jint /*winId*/, jint /*action*/) + { + if (m_touchPoints.isEmpty()) + return; + + QMutexLocker lock(QtAndroid::platformInterfaceMutex()); + QTouchDevice *touchDevice = getTouchDevice(); + if (!touchDevice) + return; + QWindow *window = QtAndroid::topLevelWindowAt(m_touchPoints.at(0).area.center().toPoint()); QWindowSystemInterface::handleTouchEvent(window, touchDevice, m_touchPoints); } + static void touchCancel(JNIEnv * /*env*/, jobject /*thiz*/, jint /*winId*/) + { + if (m_touchPoints.isEmpty()) + return; + + QMutexLocker lock(QtAndroid::platformInterfaceMutex()); + QTouchDevice *touchDevice = getTouchDevice(); + if (!touchDevice) + return; + + QWindow *window = QtAndroid::topLevelWindowAt(m_touchPoints.at(0).area.center().toPoint()); + QWindowSystemInterface::handleTouchCancelEvent(window, touchDevice); + } + static bool isTabletEventSupported(JNIEnv */*env*/, jobject /*thiz*/) { #if QT_CONFIG(tabletevent) @@ -840,6 +863,7 @@ namespace QtAndroidInput {"touchBegin","(I)V",(void*)touchBegin}, {"touchAdd","(IIIZIIFFFF)V",(void*)touchAdd}, {"touchEnd","(II)V",(void*)touchEnd}, + {"touchCancel", "(I)V", (void *)touchCancel}, {"mouseDown", "(III)V", (void *)mouseDown}, {"mouseUp", "(III)V", (void *)mouseUp}, {"mouseMove", "(III)V", (void *)mouseMove}, |