From 0461834be034d3e6ba9462db5a6ab8f66a26ba04 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Fri, 1 Sep 2023 14:24:27 +0200 Subject: [PATCH] ViewGroup: adjust scroll velocity for touchpads --- src/api-impl-jni/views/android_view_ViewGroup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/api-impl-jni/views/android_view_ViewGroup.c b/src/api-impl-jni/views/android_view_ViewGroup.c index 7c7ad39f..10117bfe 100644 --- a/src/api-impl-jni/views/android_view_ViewGroup.c +++ b/src/api-impl-jni/views/android_view_ViewGroup.c @@ -72,9 +72,17 @@ static GtkLayoutManager *android_layout_new(jobject view) { return &layout->parent_instance; } +#define MAGIC_SCROLL_FACTOR 32 + static gboolean scroll_cb(GtkEventControllerScroll* self, gdouble dx, gdouble dy, jobject this) { JNIEnv *env = get_jni_env(); + GdkScrollUnit scroll_unit = gtk_event_controller_scroll_get_unit (self); + + if (scroll_unit == GDK_SCROLL_UNIT_SURFACE) { + dx /= MAGIC_SCROLL_FACTOR; + dy /= MAGIC_SCROLL_FACTOR; + } jobject motion_event = (*env)->NewObject(env, handle_cache.motion_event.class, handle_cache.motion_event.constructor, SOURCE_CLASS_POINTER, MOTION_EVENT_ACTION_SCROLL, dx, -dy); gboolean ret = (*env)->CallBooleanMethod(env, this, handle_cache.view.onGenericMotionEvent, motion_event);