From 472ecc8088233168b25f60a100403d9c4ab832b1 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Thu, 19 Jan 2023 01:44:16 +0200
Subject: [PATCH] SL-18999 IME disabling should be called in window's thread

For some reason positioning IME window works fine, but disabling and enabling ime works from window's thread only
---
 indra/llwindow/llwindowwin32.cpp | 76 +++++++++++++++++---------------
 1 file changed, 41 insertions(+), 35 deletions(-)

diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp
index 11a3c943ee2..6f67b131d19 100644
--- a/indra/llwindow/llwindowwin32.cpp
+++ b/indra/llwindow/llwindowwin32.cpp
@@ -3904,42 +3904,48 @@ void LLWindowWin32::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b)
 
 	sLanguageTextInputAllowed = b;
 
-	if ( sLanguageTextInputAllowed )
-	{
-		// Allowing: Restore the previous IME status, so that the user has a feeling that the previous 
-		// text input continues naturally.  Be careful, however, the IME status is meaningful only during the user keeps 
-		// using same Input Locale (aka Keyboard Layout).
-		if (sWinIMEOpened && GetKeyboardLayout(0) == sWinInputLocale)
-		{
-			HIMC himc = LLWinImm::getContext(mWindowHandle);
-			LLWinImm::setOpenStatus(himc, TRUE);
-			LLWinImm::setConversionStatus(himc, sWinIMEConversionMode, sWinIMESentenceMode);
-			LLWinImm::releaseContext(mWindowHandle, himc);
-		}
-	}
-	else
-	{
-		// Disallowing: Turn off the IME so that succeeding key events bypass IME and come to us directly.
-		// However, do it after saving the current IME  status.  We need to restore the status when
-		//   allowing language text input again.
-		sWinInputLocale = GetKeyboardLayout(0);
-		sWinIMEOpened = LLWinImm::isIME(sWinInputLocale);
-		if (sWinIMEOpened)
-		{
-			HIMC himc = LLWinImm::getContext(mWindowHandle);
-			sWinIMEOpened = LLWinImm::getOpenStatus(himc);
-			if (sWinIMEOpened)
-			{
-				LLWinImm::getConversionStatus(himc, &sWinIMEConversionMode, &sWinIMESentenceMode);
+    if (sLanguageTextInputAllowed)
+    {
+        mWindowThread->post([=]()
+        {
+            // Allowing: Restore the previous IME status, so that the user has a feeling that the previous 
+            // text input continues naturally.  Be careful, however, the IME status is meaningful only during the user keeps 
+            // using same Input Locale (aka Keyboard Layout).
+            if (sWinIMEOpened && GetKeyboardLayout(0) == sWinInputLocale)
+            {
+                HIMC himc = LLWinImm::getContext(mWindowHandle);
+                LLWinImm::setOpenStatus(himc, TRUE);
+                LLWinImm::setConversionStatus(himc, sWinIMEConversionMode, sWinIMESentenceMode);
+                LLWinImm::releaseContext(mWindowHandle, himc);
+            }
+        });
+    }
+    else
+    {
+        mWindowThread->post([=]()
+        {
+            // Disallowing: Turn off the IME so that succeeding key events bypass IME and come to us directly.
+            // However, do it after saving the current IME  status.  We need to restore the status when
+            //   allowing language text input again.
+            sWinInputLocale = GetKeyboardLayout(0);
+            sWinIMEOpened = LLWinImm::isIME(sWinInputLocale);
+            if (sWinIMEOpened)
+            {
+                HIMC himc = LLWinImm::getContext(mWindowHandle);
+                sWinIMEOpened = LLWinImm::getOpenStatus(himc);
+                if (sWinIMEOpened)
+                {
+                    LLWinImm::getConversionStatus(himc, &sWinIMEConversionMode, &sWinIMESentenceMode);
 
-				// We need both ImmSetConversionStatus and ImmSetOpenStatus here to surely disable IME's 
-				// keyboard hooking, because Some IME reacts only on the former and some other on the latter...
-				LLWinImm::setConversionStatus(himc, IME_CMODE_NOCONVERSION, sWinIMESentenceMode);
-				LLWinImm::setOpenStatus(himc, FALSE);
-			}
-			LLWinImm::releaseContext(mWindowHandle, himc);
- 		}
-	}
+                    // We need both ImmSetConversionStatus and ImmSetOpenStatus here to surely disable IME's 
+                    // keyboard hooking, because Some IME reacts only on the former and some other on the latter...
+                    LLWinImm::setConversionStatus(himc, IME_CMODE_NOCONVERSION, sWinIMESentenceMode);
+                    LLWinImm::setOpenStatus(himc, FALSE);
+                }
+                LLWinImm::releaseContext(mWindowHandle, himc);
+            }
+        });
+    }
 }
 
 void LLWindowWin32::fillCandidateForm(const LLCoordGL& caret, const LLRect& bounds, 
-- 
GitLab