SDL: Prevent duplicate calls to start/stop text input

From b7748c15134c6160518fc2d4343861ec074aaed1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 27 Jun 2024 10:49:24 -0700
Subject: [PATCH] Prevent duplicate calls to start/stop text input

---
 src/video/SDL_video.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index e7c5111f6991e..69b71b3bcc154 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -5032,13 +5032,15 @@ int SDL_StartTextInput(SDL_Window *window)
         }
     }
 
-    /* Finally start the text input system */
-    if (_this->StartTextInput) {
-        if (_this->StartTextInput(_this, window) < 0) {
-            return -1;
+    if (!window->text_input_active) {
+        /* Finally start the text input system */
+        if (_this->StartTextInput) {
+            if (_this->StartTextInput(_this, window) < 0) {
+                return -1;
+            }
         }
+        window->text_input_active = SDL_TRUE;
     }
-    window->text_input_active = SDL_TRUE;
     return 0;
 }
 
@@ -5053,11 +5055,13 @@ int SDL_StopTextInput(SDL_Window *window)
 {
     CHECK_WINDOW_MAGIC(window, -1);
 
-    /* Stop the text input system */
-    if (_this->StopTextInput) {
-        _this->StopTextInput(_this, window);
+    if (window->text_input_active) {
+        /* Stop the text input system */
+        if (_this->StopTextInput) {
+            _this->StopTextInput(_this, window);
+        }
+        window->text_input_active = SDL_FALSE;
     }
-    window->text_input_active = SDL_FALSE;
 
     /* Hide the on-screen keyboard, if desired */
     const char *hint = SDL_GetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD);