Skip to content

Commit

Permalink
Keep track of whether the Android on-screen keyboard was opened by th…
Browse files Browse the repository at this point in the history
…e application

Fixes #9202

(cherry picked from commit edbcef1)
(cherry picked from commit bdc7ad8)
  • Loading branch information
slouken committed Mar 5, 2024
1 parent 2f2cca8 commit e910e6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/video/android/SDL_androidevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ void Android_PumpEvents_Blocking(_THIS)
#endif

/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive() &&
SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
Android_ShowScreenKeyboard(_this, Android_Window); /* Only showTextInput */
}
Android_RestoreScreenKeyboardOnResume(_this, Android_Window);
}
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
Expand Down Expand Up @@ -235,10 +232,7 @@ void Android_PumpEvents_NonBlocking(_THIS)
#endif

/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive() &&
SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
Android_ShowScreenKeyboard(_this, Android_Window); /* Only showTextInput */
}
Android_RestoreScreenKeyboardOnResume(_this, Android_Window);
}
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
Expand Down
11 changes: 11 additions & 0 deletions src/video/android/SDL_androidkeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ static SDL_Scancode Android_Keycodes[] = {
SDL_SCANCODE_PASTE, /* AKEYCODE_PASTE */
};

static SDL_bool SDL_screen_keyboard_shown;

static SDL_Scancode TranslateKeycode(int keycode)
{
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
Expand Down Expand Up @@ -345,11 +347,20 @@ void Android_ShowScreenKeyboard(_THIS, SDL_Window *window)
{
SDL_VideoData *videodata = _this->driverdata;
Android_JNI_ShowScreenKeyboard(&videodata->textRect);
SDL_screen_keyboard_shown = SDL_TRUE;
}

void Android_HideScreenKeyboard(_THIS, SDL_Window *window)
{
Android_JNI_HideScreenKeyboard();
SDL_screen_keyboard_shown = SDL_FALSE;
}

void Android_RestoreScreenKeyboardOnResume(_THIS, SDL_Window *window)
{
if (SDL_screen_keyboard_shown) {
Android_ShowScreenKeyboard(_this, window);
}
}

SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window *window)
Expand Down
1 change: 1 addition & 0 deletions src/video/android/SDL_androidkeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern int Android_OnKeyUp(int keycode);
extern SDL_bool Android_HasScreenKeyboardSupport(_THIS);
extern void Android_ShowScreenKeyboard(_THIS, SDL_Window *window);
extern void Android_HideScreenKeyboard(_THIS, SDL_Window *window);
extern void Android_RestoreScreenKeyboardOnResume(_THIS, SDL_Window *window);
extern SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window *window);
extern void Android_SetTextInputRect(_THIS, const SDL_Rect *rect);

Expand Down

0 comments on commit e910e6f

Please sign in to comment.