Added the hint SDL_HINT_ENABLE_SCREEN_KEYBOARD to control whether the on-screen keyboard should be shown when text input is active

Fixes https://github.com/libsdl-org/SDL/issues/7160
This commit is contained in:
Sam Lantinga 2023-05-20 11:09:36 -07:00
parent 00b87f1ded
commit 69644346ac
3 changed files with 55 additions and 39 deletions

View File

@ -7,6 +7,7 @@ This is a list of major changes in SDL's version history.
General: General:
* Added a display event SDL_DISPLAYEVENT_MOVED which is sent when the primary monitor changes or displays change position relative to each other * Added a display event SDL_DISPLAYEVENT_MOVED which is sent when the primary monitor changes or displays change position relative to each other
* Added the hint SDL_HINT_ENABLE_SCREEN_KEYBOARD to control whether the on-screen keyboard should be shown when text input is active
--------------------------------------------------------------------------- ---------------------------------------------------------------------------

View File

@ -377,6 +377,17 @@ extern "C" {
*/ */
#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT" #define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
/**
* \brief A variable that controls whether the on-screen keyboard should be shown when text input is active
*
* The variable can be set to the following values:
* "0" - Do not show the on-screen keyboard
* "1" - Show the on-screen keyboard
*
* The default value is "1". This hint must be set before text input is activated.
*/
#define SDL_HINT_ENABLE_SCREEN_KEYBOARD "SDL_ENABLE_SCREEN_KEYBOARD"
/** /**
* \brief A variable that controls whether Steam Controllers should be exposed using the SDL joystick and game controller APIs * \brief A variable that controls whether Steam Controllers should be exposed using the SDL joystick and game controller APIs
* *

View File

@ -4294,10 +4294,12 @@ void SDL_StartTextInput(void)
(void)SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE); (void)SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
/* Then show the on-screen keyboard, if any */ /* Then show the on-screen keyboard, if any */
if (SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
window = SDL_GetFocusWindow(); window = SDL_GetFocusWindow();
if (window && _this && _this->ShowScreenKeyboard) { if (window && _this && _this->ShowScreenKeyboard) {
_this->ShowScreenKeyboard(_this, window); _this->ShowScreenKeyboard(_this, window);
} }
}
/* Finally start the text input system */ /* Finally start the text input system */
if (_this && _this->StartTextInput) { if (_this && _this->StartTextInput) {
@ -4338,10 +4340,12 @@ void SDL_StopTextInput(void)
} }
/* Hide the on-screen keyboard, if any */ /* Hide the on-screen keyboard, if any */
if (SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
window = SDL_GetFocusWindow(); window = SDL_GetFocusWindow();
if (window && _this && _this->HideScreenKeyboard) { if (window && _this && _this->HideScreenKeyboard) {
_this->HideScreenKeyboard(_this, window); _this->HideScreenKeyboard(_this, window);
} }
}
/* Finally disable text events */ /* Finally disable text events */
(void)SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); (void)SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);