From 97eec16e4ff6367c233f8ea6c4a343c286c3a514 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 9 Jun 2017 14:46:29 +0200 Subject: [PATCH] Android: fix missing wheel events Change-Id: I65b4f6a8fcbdad537a984064e332a4a1f34a265a Task-number: QTBUG-43669 Reviewed-by: BogDan Vatra --- .../org/qtproject/qt5/android/QtNative.java | 13 ++++++++++++ .../org/qtproject/qt5/android/QtSurface.java | 7 +++++++ .../platforms/android/androidjniinput.cpp | 20 +++++++++++++++++++ 3 files changed, 40 insertions(+) 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 b11883a105..902e2f68e7 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -61,6 +61,7 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MotionEvent; import android.view.View; +import android.view.InputDevice; import java.lang.reflect.Method; import java.security.KeyStore; @@ -470,6 +471,17 @@ public class QtNative } } + static public void sendGenericMotionEvent(MotionEvent event, int id) + { + if (event.getActionMasked() != MotionEvent.ACTION_SCROLL + || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != InputDevice.SOURCE_CLASS_POINTER) { + return; + } + + mouseWheel(id, (int) event.getX(), (int) event.getY(), + event.getAxisValue(MotionEvent.AXIS_HSCROLL), event.getAxisValue(MotionEvent.AXIS_VSCROLL)); + } + public static Context getContext() { if (m_activity != null) return m_activity; @@ -801,6 +813,7 @@ public class QtNative public static native void mouseDown(int winId, int x, int y); public static native void mouseUp(int winId, int x, int y); public static native void mouseMove(int winId, int x, int y); + public static native void mouseWheel(int winId, int x, int y, float hdelta, float vdelta); 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); diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java index 4d8abb2117..e994002dd3 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java @@ -112,4 +112,11 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback QtNative.sendTrackballEvent(event, getId()); return true; } + + @Override + public boolean onGenericMotionEvent(MotionEvent event) + { + QtNative.sendGenericMotionEvent(event, getId()); + return true; + } } diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 048be662be..32630003d1 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -173,6 +173,25 @@ namespace QtAndroidInput Qt::MouseButtons(Qt::LeftButton)); } + static void mouseWheel(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y, jfloat hdelta, jfloat vdelta) + { + if (m_ignoreMouseEvents) + return; + + QPoint globalPos(x,y); + QWindow *tlw = m_mouseGrabber.data(); + if (!tlw) + tlw = topLevelWindowAt(globalPos); + QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; + QPoint angleDelta(hdelta * 120, vdelta * 120); + + QWindowSystemInterface::handleWheelEvent(tlw, + localPos, + globalPos, + QPoint(), + angleDelta); + } + static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) { QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext(); @@ -824,6 +843,7 @@ namespace QtAndroidInput {"mouseDown", "(III)V", (void *)mouseDown}, {"mouseUp", "(III)V", (void *)mouseUp}, {"mouseMove", "(III)V", (void *)mouseMove}, + {"mouseWheel", "(IIIFF)V", (void *)mouseWheel}, {"longPress", "(III)V", (void *)longPress}, {"isTabletEventSupported", "()Z", (void *)isTabletEventSupported}, {"tabletEvent", "(IIJIIIFFF)V", (void *)tabletEvent},