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.
This commit is contained in:
Julian Winkler 2025-04-18 07:21:21 +02:00
parent db29a02c73
commit bd83e211d0
3 changed files with 6 additions and 3 deletions

View file

@ -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.getScrollY = _METHOD(handle_cache.view.class, "getScrollY", "()I");
handle_cache.view.performClick = _METHOD(handle_cache.view.class, "performClick", "()Z"); 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.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.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.onInterceptTouchEvent = _METHOD(handle_cache.view.class, "onInterceptTouchEvent", "(Landroid/view/MotionEvent;)Z");
handle_cache.view.layoutInternal = _METHOD(handle_cache.view.class, "layoutInternal", "(II)V"); handle_cache.view.layoutInternal = _METHOD(handle_cache.view.class, "layoutInternal", "(II)V");

View file

@ -67,7 +67,7 @@ bool view_dispatch_motionevent(JNIEnv *env, WrapperWidget *wrapper, GtkPropagati
} }
ret = false; ret = false;
} else { } 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)) if((*env)->ExceptionCheck(env))

View file

@ -1076,7 +1076,7 @@ public class View implements Drawable.Callback {
private OnTouchListener on_touch_listener = null; private OnTouchListener on_touch_listener = null;
public boolean onTouchEventInternal(MotionEvent event) { public boolean onTouchEventInternal(MotionEvent event, boolean handle_gestures) {
boolean handled = false; boolean handled = false;
if (on_touch_listener != null) if (on_touch_listener != null)
handled = on_touch_listener.onTouch(this, event); handled = on_touch_listener.onTouch(this, event);
@ -1084,6 +1084,9 @@ public class View implements Drawable.Callback {
if (!handled) if (!handled)
handled = onTouchEvent(event); handled = onTouchEvent(event);
if (handle_gestures && !handled && event.getAction() == MotionEvent.ACTION_UP)
handled = performClick();
return handled; return handled;
} }