From 117673ffe8bd5a8aae060307bcf6af83b4da011e Mon Sep 17 00:00:00 2001
From: Gijs Vermeulen <gijsvrm@gmail.com>
Date: Mon, 17 Dec 2018 11:49:26 +1100
Subject: [PATCH] imm32: Only generate 'WM_IME_SETCONTEXT' message if window
 has focus

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=31157
---
 dlls/imm32/imm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c
index 28eb00f..4255e98 100644
--- a/dlls/imm32/imm.c
+++ b/dlls/imm32/imm.c
@@ -608,9 +608,12 @@ HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
     if (!hIMC)
         return old;
 
-    SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
-    data->IMC.hWnd = hWnd;
-    SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
+    if(GetActiveWindow() == data->IMC.hWnd)
+    {
+        SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
+        data->IMC.hWnd = hWnd;
+        SendMessageW(data->IMC.hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
+    }
 
     return old;
 }
-- 
1.9.1

