From a6a222095e85e179209b9badb611c3dbdb16ccc6 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 20 May 2023 11:14:34 -0700
Subject: [PATCH] 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
---
include/SDL3/SDL_hints.h | 11 +++++++++++
src/video/SDL_video.c | 16 ++++++++++------
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 739a250e409f..ee9d2f11540f 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -395,6 +395,17 @@ extern "C" {
*/
#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
*
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index e7dc22635bb8..753dd485ea30 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -4665,9 +4665,11 @@ void SDL_StartTextInput(void)
SDL_SetEventEnabled(SDL_EVENT_TEXT_EDITING, SDL_TRUE);
/* Then show the on-screen keyboard, if any */
- window = SDL_GetFocusWindow();
- if (window && _this && _this->ShowScreenKeyboard) {
- _this->ShowScreenKeyboard(_this, window);
+ if (SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
+ window = SDL_GetFocusWindow();
+ if (window && _this && _this->ShowScreenKeyboard) {
+ _this->ShowScreenKeyboard(_this, window);
+ }
}
/* Finally start the text input system */
@@ -4707,9 +4709,11 @@ void SDL_StopTextInput(void)
}
/* Hide the on-screen keyboard, if any */
- window = SDL_GetFocusWindow();
- if (window && _this && _this->HideScreenKeyboard) {
- _this->HideScreenKeyboard(_this, window);
+ if (SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
+ window = SDL_GetFocusWindow();
+ if (window && _this && _this->HideScreenKeyboard) {
+ _this->HideScreenKeyboard(_this, window);
+ }
}
/* Finally disable text events */