SDL: We should still set the text input area if SDL_DISABLE_WINDOWS_IME is defined

From e47179c4c7f084cf769e4c675c1c165889f2cbfb Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 28 Jun 2024 18:00:48 -0700
Subject: [PATCH] We should still set the text input area if
 SDL_DISABLE_WINDOWS_IME is defined

Fixes https://github.com/libsdl-org/SDL/issues/6254
---
 src/video/windows/SDL_windowskeyboard.c | 24 ++++++++++++++----------
 src/video/windows/SDL_windowsvideo.h    |  3 ++-
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index 52e162aff0e34..cba4f59f8c295 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -39,10 +39,12 @@
 static int IME_Init(SDL_VideoData *videodata, SDL_Window *window);
 static void IME_Enable(SDL_VideoData *videodata, HWND hwnd);
 static void IME_Disable(SDL_VideoData *videodata, HWND hwnd);
-static void IME_SetTextInputArea(SDL_VideoData *videodata, const SDL_Rect *rect, int cursor);
+static void IME_SetTextInputArea(SDL_VideoData *videodata, HWND hwnd, const SDL_Rect *rect, int cursor);
 static void IME_ClearComposition(SDL_VideoData *videodata);
 static void IME_GetCandidateList(SDL_VideoData *videodata, HWND hwnd);
 static void IME_Quit(SDL_VideoData *videodata);
+#else
+static void IME_SetTextInputArea(SDL_VideoData *videodata, HWND hwnd, const SDL_Rect *rect, int cursor);
 #endif /* !SDL_DISABLE_WINDOWS_IME */
 
 #ifndef MAPVK_VK_TO_VSC
@@ -231,12 +233,10 @@ int WIN_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
 
 int WIN_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
 {
-#ifndef SDL_DISABLE_WINDOWS_IME
-    SDL_VideoData *data = _this->driverdata;
-
-    IME_SetTextInputArea(data, &window->text_input_rect, window->text_input_cursor);
-#endif /* !SDL_DISABLE_WINDOWS_IME */
+    SDL_VideoData *videodata = _this->driverdata;
+    SDL_WindowData *data = window->driverdata;
 
+    IME_SetTextInputArea(videodata, data->hwnd, &window->text_input_rect, window->text_input_cursor);
     return 0;
 }
 
@@ -645,14 +645,16 @@ static void IME_SetWindow(SDL_VideoData *videodata, SDL_Window *window)
         SDL_zero(videodata->ime_candidate_area);
     }
 
-    IME_SetTextInputArea(videodata, &window->text_input_rect, window->text_input_cursor);
+    IME_SetTextInputArea(videodata, hwnd, &window->text_input_rect, window->text_input_cursor);
 }
 
-static void IME_SetTextInputArea(SDL_VideoData *videodata, const SDL_Rect *rect, int cursor)
+#endif
+
+static void IME_SetTextInputArea(SDL_VideoData *videodata, HWND hwnd, const SDL_Rect *rect, int cursor)
 {
     HIMC himc;
 
-    himc = ImmGetContext(videodata->ime_hwnd_current);
+    himc = ImmGetContext(hwnd);
     if (himc) {
         COMPOSITIONFORM cof;
         CANDIDATEFORM caf;
@@ -690,10 +692,12 @@ static void IME_SetTextInputArea(SDL_VideoData *videodata, const SDL_Rect *rect,
             ImmSetCandidateWindow(himc, &caf);
         }
 
-        ImmReleaseContext(videodata->ime_hwnd_current, himc);
+        ImmReleaseContext(hwnd, himc);
     }
 }
 
+#ifndef SDL_DISABLE_WINDOWS_IME
+
 static void IME_UpdateInputLocale(SDL_VideoData *videodata)
 {
     HKL hklnext = GetKeyboardLayout(0);
diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h
index 7f74a27779ff3..5a07f1a100b72 100644
--- a/src/video/windows/SDL_windowsvideo.h
+++ b/src/video/windows/SDL_windowsvideo.h
@@ -420,7 +420,6 @@ struct SDL_VideoData
     Uint32 raw_input_enabled;
 
 #ifndef SDL_DISABLE_WINDOWS_IME
-    SDL_bool ime_com_initialized;
     SDL_bool ime_initialized;
     SDL_bool ime_enabled;
     SDL_bool ime_available;
@@ -444,10 +443,12 @@ struct SDL_VideoData
     DWORD ime_candsel;
     int ime_candlistindexbase;
     SDL_bool ime_horizontal_candidates;
+#endif
 
     COMPOSITIONFORM ime_composition_area;
     CANDIDATEFORM ime_candidate_area;
 
+#ifndef SDL_DISABLE_WINDOWS_IME
     HKL ime_hkl;
     void *ime_himm32;
     /* *INDENT-OFF* */ /* clang-format off */