korean-input / issues

한국어 입력 이슈 트래커
90 stars 0 forks source link

[패치] Linux에서 Wine을 한글 입력 시에 발생하는 글자 밀림 버그 #14

Open emotionbug opened 2 years ago

emotionbug commented 2 years ago

문제가 있는 프로그램

프로그램 : Wine IME : inputstyle=root 가 아닌 입력기를 사용하는 경우

환경

요약

Linux의 Wine에서 XIM을 사용했을 경우 발생하는 글자 밀림 현상

재현방법

wineuseXIM flag 활성화 ( 기본 TRUE )

참고자료

이에 대한 Patch를 첨부합니다. ( https://www.winehq.org/pipermail/wine-devel/2022-March/211134.html )

From 99fee48cf686d5fd5580fd902f9cdb3b63799ec8 Mon Sep 17 00:00:00 2001
From: Alex Kwak <take-me-home@kakao.com>
Date: Wed, 16 Mar 2022 16:02:30 +0900
Subject: [PATCH] dlls: Flush CompositionString after X11DRV_XIMLookupChars.

There is no flushing after X11DRV_XIMLookupChars on wine11xdrv. for
this reason, the characters of the GUI are not updated.

In addition, in IME_SetResultString on wine11xdrv, the bInComposition
flag is not deactivated after generating WM_IME_ENDCOMPOSITION, so that
the WM_IME_STARTCOMPOSITION message is not generated in the next
composition.

Also, when WM_IME_COMPOSITION is processed in editor_handle_message on
riched20, the existing selection is removed and the characters being
entered disappear.
WM_IME_STARTCOMPOSITION occurs when attempting to input after full
selection, and ME_DeleteSelection is called, which causes the exact
location of the cursor to be lost.

Signed-off-by: Alex Kwak <take-me-home@kakao.com>
---
 dlls/riched20/editor.c | 3 +--
 dlls/winex11.drv/ime.c | 5 ++---
 dlls/winex11.drv/xim.c | 8 ++++++++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index a8cf3175591..33437a6d6e3 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4097,8 +4097,8 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
     return 0;
   case WM_IME_STARTCOMPOSITION:
   {
-    editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
     ME_DeleteSelection(editor);
+    editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
     ME_CommitUndo(editor);
     ME_UpdateRepaint(editor, FALSE);
     return 0;
@@ -4109,7 +4109,6 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,

     ME_Style *style = style_get_insert_style( editor, editor->pCursors );
     hIMC = ITextHost_TxImmGetContext(editor->texthost);
-    ME_DeleteSelection(editor);
     ME_SaveTempStyle(editor, style);
     if (lParam & (GCS_RESULTSTR|GCS_COMPSTR))
     {
diff --git a/dlls/winex11.drv/ime.c b/dlls/winex11.drv/ime.c
index c1584930861..db2ff5d85cc 100644
--- a/dlls/winex11.drv/ime.c
+++ b/dlls/winex11.drv/ime.c
@@ -1049,10 +1049,9 @@ void IME_SetResultString(LPWSTR lpResult, DWORD dwResultLen)
     GenerateIMEMessage(imc, WM_IME_COMPOSITION, 0, GCS_COMPSTR);
     GenerateIMEMessage(imc, WM_IME_COMPOSITION, lpResult[0], GCS_RESULTSTR|GCS_RESULTCLAUSE);
     GenerateIMEMessage(imc, WM_IME_ENDCOMPOSITION, 0, 0);
+    myPrivate->bInComposition = FALSE;

-    if (!inComp)
-        ImmSetOpenStatus(imc, FALSE);
-
+    ImmSetOpenStatus(imc, FALSE);
     ImmUnlockIMC(imc);
 }

diff --git a/dlls/winex11.drv/xim.c b/dlls/winex11.drv/xim.c
index 3994c2106cc..5ce6f7e5e95 100644
--- a/dlls/winex11.drv/xim.c
+++ b/dlls/winex11.drv/xim.c
@@ -117,6 +117,14 @@ void X11DRV_XIMLookupChars( const char *str, DWORD count )

     IME_SetResultString(wcOutput, dwOutput);
     HeapFree(GetProcessHeap(), 0, wcOutput);
+
+    // After then if `CompositionString` is remaining, flushing it.
+    // i.e., Korean
+    if (CompositionString)
+    {
+        IME_SetCompositionString(SCS_SETSTR, CompositionString,
+                                 dwCompStringLength, NULL, 0);
+    }
 }

 static BOOL XIMPreEditStateNotifyCallback(XIC xic, XPointer p, XPointer data)
-- 
2.32.0
emotionbug commented 2 years ago

[PATCH v3] winex11.drv: call XIMReset on CPS_COMPLETE

https://source.winehq.org/patches/data/231261

[PATCH v2] riched20: Send CPS_COMPLETE from mouse click event.

https://source.winehq.org/patches/data/231251

[PATCH v2] winex11.drv: Call ImeSetCompositionString after IME_SetResultString

https://source.winehq.org/patches/data/231236

[PATCH v2] riched20: Handle GCS_COMPSTR, GCS_CURSORPOS on WM_IME_COMPOSITION.

https://source.winehq.org/patches/data/231055

emotionbug commented 2 years ago

근데, XmbResetIC 를 호출 했을 경우 ibus-hangul 에서 쓰레기 이벤트를 발생시키네요 -_-;; 중국어도 일본어도 아무런 메세지가 안오는데 이상하게 한국어만 이벤트가 발생하네요;;

OctopusET commented 2 years ago

저도 태스트해보고 공유 드리겠습니다

emotionbug commented 2 years ago

https://hamonikr.org/hamoni_board/91167

이전에 하모니카에서 이런 글이 있었는데, ibus-hangul이나 ibus 자체에서 끝 글자 버그를 해결하려고 뭔가 작업한게 있는 것 같은데 잘 모르겠네요.

KeyEvent로 Release, 이외 대부분 값은 0으로 전달됩니다.