From 014a63b4b5b94ce50f329eddb345f5434654305b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 6 Jan 2024 08:11:22 -0800
Subject: [PATCH] Renamed ShowTextInput/HideTextInput to
ShowScreenKeyboard/HideScreenKeyboard on Android
This better reflects the actual implementation and makes SDL_HINT_ENABLE_SCREEN_KEYBOARD work on Android.
Fixes https://github.com/libsdl-org/SDL/issues/8652
---
src/core/android/SDL_android.c | 4 ++--
src/core/android/SDL_android.h | 4 ++--
src/video/android/SDL_androidevents.c | 10 ++++++----
src/video/android/SDL_androidkeyboard.c | 14 +++++++-------
src/video/android/SDL_androidkeyboard.h | 5 ++---
src/video/android/SDL_androidvideo.c | 4 ++--
6 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 8b3dc1507c5f..b4ee8b7a0f2f 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -2239,7 +2239,7 @@ int Android_JNI_SuspendScreenSaver(SDL_bool suspend)
return Android_JNI_SendMessage(COMMAND_SET_KEEP_SCREEN_ON, (suspend == SDL_FALSE) ? 0 : 1);
}
-void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
+void Android_JNI_ShowScreenKeyboard(SDL_Rect *inputRect)
{
JNIEnv *env = Android_JNI_GetEnv();
(*env)->CallStaticBooleanMethod(env, mActivityClass, midShowTextInput,
@@ -2249,7 +2249,7 @@ void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
inputRect->h);
}
-void Android_JNI_HideTextInput(void)
+void Android_JNI_HideScreenKeyboard(void)
{
/* has to match Activity constant */
const int COMMAND_TEXTEDIT_HIDE = 3;
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index c1256306b346..af8ed1d47ba2 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -43,8 +43,8 @@ extern void Android_JNI_MinizeWindow(void);
extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void);
extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
-extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
-extern void Android_JNI_HideTextInput(void);
+extern void Android_JNI_ShowScreenKeyboard(SDL_Rect *inputRect);
+extern void Android_JNI_HideScreenKeyboard(void);
extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
extern ANativeWindow *Android_JNI_GetNativeWindow(void);
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index a24a9f150eb8..6f92e347eca2 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -132,8 +132,9 @@ void Android_PumpEvents_Blocking(SDL_VideoDevice *_this)
#endif
/* Make sure SW Keyboard is restored when an app becomes foreground */
- if (SDL_TextInputActive()) {
- Android_StartTextInput(_this); /* Only showTextInput */
+ if (SDL_TextInputActive() &&
+ SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
+ Android_ShowScreenKeyboard(_this, Android_Window); /* Only showTextInput */
}
SDL_SendAppEvent(SDL_EVENT_DID_ENTER_FOREGROUND);
@@ -212,8 +213,9 @@ void Android_PumpEvents_NonBlocking(SDL_VideoDevice *_this)
#endif
/* Make sure SW Keyboard is restored when an app becomes foreground */
- if (SDL_TextInputActive()) {
- Android_StartTextInput(_this); /* Only showTextInput */
+ if (SDL_TextInputActive() &&
+ SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
+ Android_ShowScreenKeyboard(_this, Android_Window); /* Only showTextInput */
}
SDL_SendAppEvent(SDL_EVENT_DID_ENTER_FOREGROUND);
diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c
index 4325faa3b6a7..4d80397f001b 100644
--- a/src/video/android/SDL_androidkeyboard.c
+++ b/src/video/android/SDL_androidkeyboard.c
@@ -341,20 +341,20 @@ SDL_bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this)
return SDL_TRUE;
}
-SDL_bool Android_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window)
+void Android_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window)
{
- return Android_JNI_IsScreenKeyboardShown();
+ SDL_VideoData *videodata = _this->driverdata;
+ Android_JNI_ShowScreenKeyboard(&videodata->textRect);
}
-void Android_StartTextInput(SDL_VideoDevice *_this)
+void Android_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window)
{
- SDL_VideoData *videodata = _this->driverdata;
- Android_JNI_ShowTextInput(&videodata->textRect);
+ Android_JNI_HideScreenKeyboard();
}
-void Android_StopTextInput(SDL_VideoDevice *_this)
+SDL_bool Android_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window)
{
- Android_JNI_HideTextInput();
+ return Android_JNI_IsScreenKeyboardShown();
}
int Android_SetTextInputRect(SDL_VideoDevice *_this, const SDL_Rect *rect)
diff --git a/src/video/android/SDL_androidkeyboard.h b/src/video/android/SDL_androidkeyboard.h
index 0a194d63d691..2693fa0e182e 100644
--- a/src/video/android/SDL_androidkeyboard.h
+++ b/src/video/android/SDL_androidkeyboard.h
@@ -26,8 +26,7 @@ extern int Android_OnKeyDown(int keycode);
extern int Android_OnKeyUp(int keycode);
extern SDL_bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
+extern void Android_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window);
+extern void Android_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window);
extern SDL_bool Android_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window);
-
-extern void Android_StartTextInput(SDL_VideoDevice *_this);
-extern void Android_StopTextInput(SDL_VideoDevice *_this);
extern int Android_SetTextInputRect(SDL_VideoDevice *_this, const SDL_Rect *rect);
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index eea89b8b07c6..e000ec6963dd 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -142,12 +142,12 @@ static SDL_VideoDevice *Android_CreateDevice(void)
device->SuspendScreenSaver = Android_SuspendScreenSaver;
/* Text input */
- device->StartTextInput = Android_StartTextInput;
- device->StopTextInput = Android_StopTextInput;
device->SetTextInputRect = Android_SetTextInputRect;
/* Screen keyboard */
device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
+ device->ShowScreenKeyboard = Android_ShowScreenKeyboard;
+ device->HideScreenKeyboard = Android_HideScreenKeyboard;
device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
/* Clipboard */