From bd83e211d00862127e5d0bdfa52d977cb16e2daa Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Fri, 18 Apr 2025 07:21:21 +0200 Subject: [PATCH] handle onClickListener for synthesized MotionEvents Since synthesized events can't be handled by GTK, we also need to handle gestures by ourself in that case. --- src/api-impl-jni/util.c | 2 +- src/api-impl-jni/views/android_view_View.c | 2 +- src/api-impl/android/view/View.java | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api-impl-jni/util.c b/src/api-impl-jni/util.c index ba1716be..523ff2db 100644 --- a/src/api-impl-jni/util.c +++ b/src/api-impl-jni/util.c @@ -132,7 +132,7 @@ void set_up_handle_cache(JNIEnv *env) handle_cache.view.getScrollY = _METHOD(handle_cache.view.class, "getScrollY", "()I"); handle_cache.view.performClick = _METHOD(handle_cache.view.class, "performClick", "()Z"); handle_cache.view.onTouchEvent = _METHOD(handle_cache.view.class, "onTouchEvent", "(Landroid/view/MotionEvent;)Z"); - handle_cache.view.onTouchEventInternal = _METHOD(handle_cache.view.class, "onTouchEventInternal", "(Landroid/view/MotionEvent;)Z"); + handle_cache.view.onTouchEventInternal = _METHOD(handle_cache.view.class, "onTouchEventInternal", "(Landroid/view/MotionEvent;Z)Z"); handle_cache.view.dispatchTouchEvent = _METHOD(handle_cache.view.class, "dispatchTouchEvent", "(Landroid/view/MotionEvent;)Z"); handle_cache.view.onInterceptTouchEvent = _METHOD(handle_cache.view.class, "onInterceptTouchEvent", "(Landroid/view/MotionEvent;)Z"); handle_cache.view.layoutInternal = _METHOD(handle_cache.view.class, "layoutInternal", "(II)V"); diff --git a/src/api-impl-jni/views/android_view_View.c b/src/api-impl-jni/views/android_view_View.c index 191167cc..8ca0d94d 100644 --- a/src/api-impl-jni/views/android_view_View.c +++ b/src/api-impl-jni/views/android_view_View.c @@ -67,7 +67,7 @@ bool view_dispatch_motionevent(JNIEnv *env, WrapperWidget *wrapper, GtkPropagati } ret = false; } else { - ret = (*env)->CallBooleanMethod(env, this, handle_cache.view.onTouchEventInternal, motion_event); + ret = (*env)->CallBooleanMethod(env, this, handle_cache.view.onTouchEventInternal, motion_event, (jboolean)(event == NULL)); } if((*env)->ExceptionCheck(env)) diff --git a/src/api-impl/android/view/View.java b/src/api-impl/android/view/View.java index f01b4436..a2a992f3 100644 --- a/src/api-impl/android/view/View.java +++ b/src/api-impl/android/view/View.java @@ -1076,7 +1076,7 @@ public class View implements Drawable.Callback { private OnTouchListener on_touch_listener = null; - public boolean onTouchEventInternal(MotionEvent event) { + public boolean onTouchEventInternal(MotionEvent event, boolean handle_gestures) { boolean handled = false; if (on_touch_listener != null) handled = on_touch_listener.onTouch(this, event); @@ -1084,6 +1084,9 @@ public class View implements Drawable.Callback { if (!handled) handled = onTouchEvent(event); + if (handle_gestures && !handled && event.getAction() == MotionEvent.ACTION_UP) + handled = performClick(); + return handled; }