SDL: Enable text input on video initialization without popping up an on-screen keyboard (dff76)

From dff76bf29565bbf5c90b73855f8fd74613227036 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 27 Jan 2024 11:52:58 -0800
Subject: [PATCH] Enable text input on video initialization without popping up
 an on-screen keyboard

Fixes https://github.com/libsdl-org/SDL/issues/8561

(cherry picked from commit 4ff3b28273a9b64892620435231539a1d2c98301)
---
 src/video/SDL_video.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index b452818322c0..72d235128542 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -566,16 +566,21 @@ int SDL_VideoInit(const char *driver_name)
         SDL_DisableScreenSaver();
     }
 
-    /* If we don't use a screen keyboard, turn on text input by default,
-       otherwise programs that expect to get text events without enabling
-       UNICODE input won't get any events.
-
-       Actually, come to think of it, you needed to call SDL_EnableUNICODE(1)
-       in SDL 1.2 before you got text input events.  Hmm...
-     */
-    if (!SDL_HasScreenKeyboardSupport()) {
+#if !defined(SDL_VIDEO_DRIVER_N3DS)
+    {
+        /* In the initial state we don't want to pop up an on-screen keyboard,
+         * but we do want to allow text input from other mechanisms.
+         */
+        const char *hint = SDL_GetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD);
+        if (!hint) {
+            SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, "0");
+        }
         SDL_StartTextInput();
+        if (!hint) {
+            SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, NULL);
+        }
     }
+#endif /* !SDL_VIDEO_DRIVER_N3DS */
 
     SDL_PostInitMouse();