From 1258d54afa231e91e7103e5e83d6e1386f6acb00 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 31 Oct 2016 21:22:27 +0200 Subject: [PATCH] SDL: SDL_ANDROID_GetScreenKeyboardTextInputAsync() for anychronous text input without buggy synthetic keypresses --- .../ninslash/AndroidAppSettings.cfg | 4 ++-- project/jni/application/ninslash/src | 2 +- .../jni/sdl-1.2/include/SDL_screenkeyboard.h | 18 ++++++++++++++++-- .../video/android/SDL_androidvideo-1.3-stub.c | 2 +- .../src/video/android/SDL_androidvideo.c | 12 ++++++++++-- .../src/video/android/SDL_androidvideo.h | 2 +- .../video/android/SDL_touchscreenkeyboard.c | 19 ++++++++++++++++--- project/jni/sdl_native_helpers/repoNatives.c | 3 +++ 8 files changed, 50 insertions(+), 12 deletions(-) diff --git a/project/jni/application/ninslash/AndroidAppSettings.cfg b/project/jni/application/ninslash/AndroidAppSettings.cfg index e220f75d9..2c45b6914 100644 --- a/project/jni/application/ninslash/AndroidAppSettings.cfg +++ b/project/jni/application/ninslash/AndroidAppSettings.cfg @@ -7,10 +7,10 @@ AppName="Ninslash" AppFullName=ninslash.com # Application version code (integer) -AppVersionCode=01910 +AppVersionCode=01911 # Application user-visible version name (string) -AppVersionName="0.1.9.10 pre-alpha early access" +AppVersionName="0.1.9.11 pre-alpha early access" # Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...' # If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu diff --git a/project/jni/application/ninslash/src b/project/jni/application/ninslash/src index 9b9294782..78c0b8623 160000 --- a/project/jni/application/ninslash/src +++ b/project/jni/application/ninslash/src @@ -1 +1 @@ -Subproject commit 9b929478259f01383fb8bc54e0de4fddbb6745d0 +Subproject commit 78c0b862397e0f3a0ec0411d447a489745338feb diff --git a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h index 6ddaf5f7b..4a2c403d0 100644 --- a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h +++ b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h @@ -128,10 +128,24 @@ typedef enum extern DECLSPEC int SDLCALL SDL_ANDROID_ToggleInternalScreenKeyboard(SDL_InternalKeyboard_t keyboard); /* Show Android QWERTY keyboard, and pass entered text back to application in a buffer, - using buffer contents as previous text (UTF-8 encoded), the buffer may be of any size - - this call will block until user typed all text. */ + using buffer contents as previous text (UTF-8 encoded), the buffer may be of any size. + This function will block until user typed all text. */ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSize); +typedef enum +{ + SDL_ANDROID_TEXTINPUT_ASYNC_IN_PROGRESS = 0, + SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED = 1, +} SDL_AndroidTextInputAsyncStatus_t; + +/* Show Android QWERTY keyboard, and pass entered text back to application in a buffer, + using buffer contents as previous text (UTF-8 encoded), the buffer may be of any size. + This function will return immediately with return status SDL_ANDROID_TEXTINPUT_ASYNC_IN_PROGRESS, + and will change the contents of the buffer in another thread. You then should call this function + with the same parameters, until it will return status SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED, + and only after this you can access the contents of the buffer. */ +extern DECLSPEC SDL_AndroidTextInputAsyncStatus_t SDLCALL SDL_ANDROID_GetScreenKeyboardTextInputAsync(char * textBuf, int textBufSize); + /* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser(void); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c index e6700f665..d155bf471 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c @@ -62,7 +62,7 @@ SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex) if ( device ) { SDL_memset(device, 0, sizeof (*device)); } - if ( (device == NULL) ) { + if ( device == NULL ) { SDL_OutOfMemory(); if ( device ) { SDL_free(device); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index 18117e5c0..e4d31f434 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -42,6 +42,7 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li #include "SDL_mouse.h" #include "SDL_mutex.h" #include "SDL_thread.h" +#include "SDL_timer.h" #include "SDL_android.h" #include "SDL_syswm.h" #include "../SDL_sysvideo.h" @@ -50,6 +51,7 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li #include "../SDL_sysvideo.h" #include "SDL_androidvideo.h" +#include "SDL_androidinput.h" #include "jniwrapperstuff.h" @@ -264,7 +266,7 @@ extern int SDL_Flip(SDL_Surface *screen); extern SDL_Surface *SDL_GetVideoSurface(void); #endif -void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen) +void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen, int async) { JNIEnv *JavaEnv = GetJavaEnv(); @@ -307,6 +309,9 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, (*JavaEnv)->PopLocalFrame(JavaEnv, NULL); } + if( async ) + return; + while( !SDL_ANDROID_TextInputFinished ) SDL_Delay(100); SDL_ANDROID_TextInputFinished = 0; @@ -394,6 +399,7 @@ int SDL_ANDROID_SetApplicationPutToBackgroundCallback( if( appRestoredCallback ) appRestoredCallback = appRestored; + return 0; } extern int SDL_ANDROID_SetOpenALPutToBackgroundCallback( @@ -406,6 +412,7 @@ int SDL_ANDROID_SetOpenALPutToBackgroundCallback( { openALPutToBackgroundCallback = PutToBackground; openALRestoredCallback = Restored; + return 0; } JNIEXPORT void JNICALL @@ -458,6 +465,7 @@ int SDLCALL SDL_SetClipboardText(const char *text) if( s ) (*JavaEnv)->DeleteLocalRef( JavaEnv, s ); (*JavaEnv)->PopLocalFrame(JavaEnv, NULL); + return 0; } char * SDLCALL SDL_GetClipboardText(void) @@ -495,7 +503,7 @@ int SDLCALL SDL_HasClipboardText(void) return ret; } -JAVA_EXPORT_NAME(DemoRenderer_nativeClipboardChanged) ( JNIEnv* env, jobject thiz ) +void JAVA_EXPORT_NAME(DemoRenderer_nativeClipboardChanged) ( JNIEnv* env, jobject thiz ) { if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h index 74733b174..e25573b24 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h @@ -66,7 +66,7 @@ extern int SDL_ANDROID_ForceClearScreenRectAmount; extern int SDL_ANDROID_ShowScreenUnderFinger; extern SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect, SDL_ANDROID_ShowScreenUnderFingerRectSrc; extern int SDL_ANDROID_CallJavaSwapBuffers(); -extern void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen); +extern void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen, int async); extern void SDL_ANDROID_CallJavaHideScreenKeyboard(); extern void SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(const char *hint); extern int SDL_ANDROID_IsScreenKeyboardShown(); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c index 7e34379ff..61c1015c3 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c @@ -85,7 +85,7 @@ typedef struct GLfloat h; } GLTexture_t; -static GLTexture_t arrowImages[9]; +static GLTexture_t arrowImages[12]; static GLTexture_t buttonAutoFireImages[MAX_BUTTONS_AUTOFIRE*2]; // These are not used anymore static GLTexture_t buttonImages[MAX_BUTTONS*2]; static GLTexture_t mousePointer; @@ -1171,6 +1171,7 @@ SDLKey SDL_ANDROID_GetScreenKeyboardButtonKey(int buttonId) int SDL_ANDROID_SetScreenKeyboardShown(int shown) { touchscreenKeyboardShown = shown; + return 0; }; int SDL_ANDROID_GetScreenKeyboardShown(void) @@ -1215,16 +1216,28 @@ int SDL_ANDROID_ToggleScreenKeyboardTextInput(const char * previousText) previousText = ""; strncpy(textIn, previousText, sizeof(textIn)); textIn[sizeof(textIn)-1] = 0; - SDL_ANDROID_CallJavaShowScreenKeyboard(textIn, NULL, 0); + SDL_ANDROID_CallJavaShowScreenKeyboard(textIn, NULL, 0, 0); return 1; }; int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSize) { - SDL_ANDROID_CallJavaShowScreenKeyboard(textBuf, textBuf, textBufSize); + SDL_ANDROID_CallJavaShowScreenKeyboard(textBuf, textBuf, textBufSize, 0); return 1; }; +SDL_AndroidTextInputAsyncStatus_t SDLCALL SDL_ANDROID_GetScreenKeyboardTextInputAsync(char * textBuf, int textBufSize) +{ + if( SDL_ANDROID_TextInputFinished ) + { + SDL_ANDROID_TextInputFinished = 0; + SDL_ANDROID_IsScreenKeyboardShownFlag = 0; + return SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED; + } + SDL_ANDROID_CallJavaShowScreenKeyboard(textBuf, textBuf, textBufSize, 1); + return SDL_ANDROID_TEXTINPUT_ASYNC_IN_PROGRESS; +} + int SDLCALL SDL_HasScreenKeyboardSupport(void *unused) { return 1; diff --git a/project/jni/sdl_native_helpers/repoNatives.c b/project/jni/sdl_native_helpers/repoNatives.c index 263bdd4b1..01b95300d 100644 --- a/project/jni/sdl_native_helpers/repoNatives.c +++ b/project/jni/sdl_native_helpers/repoNatives.c @@ -5,6 +5,9 @@ #include #include #include // for memset() +#include +#include +#include #include "jniwrapperstuff.h"