From cf36b8262f14af56051065dbd9a4557d27311c80 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Fri, 28 Aug 2020 19:43:46 -0400
Subject: [PATCH] Hook up more of the IME

---
 indra/llwindow/llwindowsdl.cpp | 44 ++++++++++++++++++++++++++++++++--
 indra/llwindow/llwindowsdl.h   |  3 +++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp
index 5f6f8081302..8c12d04e86a 100644
--- a/indra/llwindow/llwindowsdl.cpp
+++ b/indra/llwindow/llwindowsdl.cpp
@@ -1665,7 +1665,6 @@ BOOL LLWindowSDL::SDLReallyCaptureInput(BOOL capture)
 	}
 
 	bool newGrab = wantGrab;
-#if LL_X11
     if (!mFullscreen) /* only bother if we're windowed anyway */
     {
         if (mSDL_Display)
@@ -1696,7 +1695,6 @@ BOOL LLWindowSDL::SDLReallyCaptureInput(BOOL capture)
             }
         }
     }
-#endif // LL_X11
 		// pretend we got what we wanted, when really we don't care.
 	
 	// return boolean success for whether we ended up in the desired state
@@ -2730,6 +2728,48 @@ void LLWindowSDL::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b)
     }
 }
 
+void LLWindowSDL::updateLanguageTextInputArea()
+{
+	if (mLanguageTextInputAllowed && mPreeditor)
+	{
+		LLCoordGL caret_coord;
+		LLRect preedit_bounds;
+		if (mPreeditor->getPreeditLocation(-1, &caret_coord, &preedit_bounds, NULL))
+		{
+			LLCoordWindow window_pos;
+			convertCoords(caret_coord, &window_pos);
+
+			SDL_Rect coords;
+			coords.x = window_pos.mX;
+			coords.y = window_pos.mY;
+			coords.w = preedit_bounds.getWidth() - coords.x;
+			coords.h = preedit_bounds.getHeight() - coords.y;
+			SDL_SetTextInputRect(&coords);
+		}
+	}
+}
+
+void LLWindowSDL::setLanguageTextInput( const LLCoordGL & pos )
+{
+	if (mLanguageTextInputAllowed && mPreeditor)
+	{
+		LLCoordGL caret_coord;
+		LLRect preedit_bounds;
+		if (mPreeditor->getPreeditLocation(-1, &caret_coord, &preedit_bounds, NULL))
+		{
+			LLCoordWindow window_pos;
+			convertCoords(pos, &window_pos);
+
+			SDL_Rect coords;
+			coords.x = window_pos.mX;
+			coords.y = window_pos.mY;
+			coords.w = preedit_bounds.getWidth() - coords.x;
+			coords.h = preedit_bounds.getHeight() - coords.y;
+			SDL_SetTextInputRect(&coords);
+		}
+	}
+}
+
 //static
 std::vector<std::string> LLWindowSDL::getDynamicFallbackFontList()
 {
diff --git a/indra/llwindow/llwindowsdl.h b/indra/llwindow/llwindowsdl.h
index e293707dda7..ab6e757c85b 100644
--- a/indra/llwindow/llwindowsdl.h
+++ b/indra/llwindow/llwindowsdl.h
@@ -31,6 +31,7 @@
 
 #include "llwindow.h"
 #include "lltimer.h"
+#include "llpreeditor.h"
 
 #ifndef SDL_MAIN_HANDLED
 #define SDL_MAIN_HANDLED 1
@@ -127,6 +128,8 @@ class LLWindowSDL final : public LLWindow
 	/*virtual*/ void bringToFront();
 
 	void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) override;
+	/*virtual*/ void updateLanguageTextInputArea() override;
+	/*virtual*/ void setLanguageTextInput( const LLCoordGL & pos ) override;
 
 	/*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async);
 	
-- 
GitLab