Overwriting ctx->hWnd with the current focus window breaks the relationship between the HIMC handle and its associated window. This direct assignment does not update the corresponding state in the wine server, leading to inconsistencies between client and server.
Signed-off-by: chenzhengyong chenzhengyong@uniontech.com
-- v5: imm32: Do not overwrite input context window with GetFocus() in ime_ui_update_window.
From: chenzhengyong chenzhengyong@uniontech.com
Overwriting ctx->hWnd with the current focus window breaks the relationship between the HIMC handle and its associated window. This direct assignment does not update the corresponding state in the wine server, leading to inconsistencies between client and server.
Signed-off-by: chenzhengyong chenzhengyong@uniontech.com --- dlls/imm32/ime.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/dlls/imm32/ime.c b/dlls/imm32/ime.c index 1487c847e00..3f51cea3dbf 100644 --- a/dlls/imm32/ime.c +++ b/dlls/imm32/ime.c @@ -318,6 +318,8 @@ static void ime_ui_update_window( INPUTCONTEXT *ctx, HWND hwnd ) { WCHAR *str; UINT len; + DWORD ui_thread; + DWORD current_thread;
if (!(str = input_context_get_comp_str( ctx, FALSE, &len )) || !*str) ShowWindow( hwnd, SW_HIDE ); @@ -328,7 +330,12 @@ static void ime_ui_update_window( INPUTCONTEXT *ctx, HWND hwnd ) } free( str );
- ctx->hWnd = GetFocus(); + /* Only update ctx->hWnd when called from the same UI thread. */ + ui_thread = GetWindowThreadProcessId(ctx->hWnd, NULL); + current_thread = GetCurrentThreadId(); + + if (ui_thread == current_thread) + ctx->hWnd = GetFocus(); }
static void ime_ui_composition( HIMC himc, HWND hwnd, LPARAM lparam )
In CEF-based applications, ime_ui_update_window may be called from a different thread or process than the UI thread owning the input context. Directly modifying ctx->hWnd in such cases breaks the association between the HIMC handle and its window, which causes subsequent composition string retrieval (CompStr) to fail.
This change restricts ctx->hWnd updates to the UI thread to keep the input context consistent across threads and processes.