From 0969db638d6ca0718d6bfbb2ba2df48e31fec338 Mon Sep 17 00:00:00 2001 From: QQQQWAS <108005841+QQQQWAS@users.noreply.github.com> Date: Wed, 30 Apr 2025 22:35:14 +0300 Subject: [PATCH 1/6] modified function to properly handle touches --- CNFGEGLDriver.c | 67 ++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index 8a72355..de9ae8f 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -366,51 +366,54 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_number ) int debuga, debugb, debugc; +bool touch_is_down[10]; + int32_t handle_input(struct android_app* app, AInputEvent* event) { -#ifdef ANDROID + #ifdef ANDROID //Potentially do other things here. + if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { - int action = AMotionEvent_getAction( event ); - int whichsource = action >> 8; - action &= AMOTION_EVENT_ACTION_MASK; - size_t pointerCount = AMotionEvent_getPointerCount(event); - - for (size_t i = 0; i < pointerCount; ++i) - { - int x, y, index; - x = AMotionEvent_getX(event, i); - y = AMotionEvent_getY(event, i); - index = AMotionEvent_getPointerId( event, i ); - - if( action == AMOTION_EVENT_ACTION_POINTER_DOWN || action == AMOTION_EVENT_ACTION_DOWN ) - { - int id = index; - if( action == AMOTION_EVENT_ACTION_POINTER_DOWN && id != whichsource ) continue; - HandleButton( x, y, id, 1 ); - ANativeActivity_showSoftInput( gapp->activity, ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED ); + int pointer_count = AMotionEvent_getPointerCount(event); + int32_t action = AMotionEvent_getAction(event); + int flags = action & AMOTION_EVENT_ACTION_MASK; + int id = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + int pid = AMotionEvent_getPointerId(event, id); + + switch(flags){ + case AMOTION_EVENT_ACTION_POINTER_UP: + case AMOTION_EVENT_ACTION_UP:{ + touch_is_down[pid] = 0; + HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 0); + break; } - else if( action == AMOTION_EVENT_ACTION_POINTER_UP || action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL ) - { - int id = index; - if( action == AMOTION_EVENT_ACTION_POINTER_UP && id != whichsource ) continue; - HandleButton( x, y, id, 0 ); + case AMOTION_EVENT_ACTION_POINTER_DOWN: + case AMOTION_EVENT_ACTION_DOWN:{ + touch_is_down[id] = 1; + HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 1); + break; } - else if( action == AMOTION_EVENT_ACTION_MOVE ) - { - HandleMotion( x, y, index ); + case AMOTION_EVENT_ACTION_MOVE:{ + int off = 0; //number of touches preceeding i that are not down + for(int i = 0; i-off < pointer_count && pid+i<10; i++){ + if(touch_is_down[pid+i] == 0){ + off++; + continue; + } + HandleMotion(AMotionEvent_getX(event, i-off), AMotionEvent_getY(event, i-off), pid+i); + } + break; } } - return 1; } else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { int code = AKeyEvent_getKeyCode(event); -#ifdef ANDROID_USE_SCANCODES + #ifdef ANDROID_USE_SCANCODES HandleKey( code, AKeyEvent_getAction(event) ); -#else + #else int unicode = AndroidGetUnicodeChar( code, AMotionEvent_getMetaState( event ) ); if( unicode ) HandleKey( unicode, AKeyEvent_getAction(event) ); @@ -419,11 +422,11 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) HandleKey( code, !AKeyEvent_getAction(event) ); return (code == 4)?1:0; //don't override functionality. } -#endif + #endif return 1; } -#endif + #endif return 0; } From bac7918a74fc69b3e84117abc939369b68b02453 Mon Sep 17 00:00:00 2001 From: QQQQWAS <108005841+QQQQWAS@users.noreply.github.com> Date: Wed, 30 Apr 2025 22:37:10 +0300 Subject: [PATCH 2/6] tab --- CNFGEGLDriver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index de9ae8f..073ad1f 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -370,7 +370,7 @@ bool touch_is_down[10]; int32_t handle_input(struct android_app* app, AInputEvent* event) { - #ifdef ANDROID +#ifdef ANDROID //Potentially do other things here. @@ -411,9 +411,9 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { int code = AKeyEvent_getKeyCode(event); - #ifdef ANDROID_USE_SCANCODES +#ifdef ANDROID_USE_SCANCODES HandleKey( code, AKeyEvent_getAction(event) ); - #else +#else int unicode = AndroidGetUnicodeChar( code, AMotionEvent_getMetaState( event ) ); if( unicode ) HandleKey( unicode, AKeyEvent_getAction(event) ); @@ -422,11 +422,11 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) HandleKey( code, !AKeyEvent_getAction(event) ); return (code == 4)?1:0; //don't override functionality. } - #endif +#endif return 1; } - #endif +#endif return 0; } From 1c46357d6856d81efcf304edb5fdad2f62d869f9 Mon Sep 17 00:00:00 2001 From: QQQQWAS <108005841+QQQQWAS@users.noreply.github.com> Date: Wed, 30 Apr 2025 22:39:27 +0300 Subject: [PATCH 3/6] --- CNFGEGLDriver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index 073ad1f..8ff947e 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -373,7 +373,6 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) #ifdef ANDROID //Potentially do other things here. - if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { int pointer_count = AMotionEvent_getPointerCount(event); From e086673b09a36fd2cfe5d715123b3c7ed7e797b5 Mon Sep 17 00:00:00 2001 From: qwas <108005841+QQQQWAS@users.noreply.github.com> Date: Thu, 1 May 2025 10:24:50 +0300 Subject: [PATCH 4/6] add bounds checking in CNFGEGLDriver.c --- CNFGEGLDriver.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index 8ff947e..9aab538 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -381,6 +381,11 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) int id = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; int pid = AMotionEvent_getPointerId(event, id); + if(pid > 9 || pointer_count > 10){ + printf("No support for more than 10 pointers\n"); + return 0; + } + switch(flags){ case AMOTION_EVENT_ACTION_POINTER_UP: case AMOTION_EVENT_ACTION_UP:{ From 8253cb6a386c1d26328ba1ea7e71d04c6ef4a8c6 Mon Sep 17 00:00:00 2001 From: QQQQWAS <108005841+QQQQWAS@users.noreply.github.com> Date: Thu, 1 May 2025 10:47:25 +0300 Subject: [PATCH 5/6] added define MAX_NUM_TOUCHES --- CNFGEGLDriver.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index 9aab538..b5a5660 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -366,7 +366,10 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_number ) int debuga, debugb, debugc; -bool touch_is_down[10]; +#ifndef MAX_NUM_TOUCHES +#define MAX_NUM_TOUCHES 10 +#endif +bool touch_is_down[MAX_NUM_TOUCHES]; int32_t handle_input(struct android_app* app, AInputEvent* event) { @@ -381,8 +384,8 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) int id = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; int pid = AMotionEvent_getPointerId(event, id); - if(pid > 9 || pointer_count > 10){ - printf("No support for more than 10 pointers\n"); + if(pid > 9 || pointer_count > MAX_NUM_TOUCHES){ + printf("Pointer id larger than MAX_NUM_TOUCHES\n"); return 0; } @@ -401,7 +404,7 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) } case AMOTION_EVENT_ACTION_MOVE:{ int off = 0; //number of touches preceeding i that are not down - for(int i = 0; i-off < pointer_count && pid+i<10; i++){ + for(int i = 0; i-off < pointer_count && pid+i Date: Thu, 1 May 2025 10:49:41 +0300 Subject: [PATCH 6/6] --- CNFGEGLDriver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index b5a5660..b4b760e 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -398,7 +398,7 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) } case AMOTION_EVENT_ACTION_POINTER_DOWN: case AMOTION_EVENT_ACTION_DOWN:{ - touch_is_down[id] = 1; + touch_is_down[pid] = 1; HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 1); break; }