[gtk/gtk-3-24.win.updated: 94/94] gtkimcontextime.c: Fix Korean input



commit cfee4e48199178da0d6f4ebf5ab443d267889282
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Sep 25 16:50:36 2018 +0800

    gtkimcontextime.c: Fix Korean input
    
    Commit c255ba68 inadvertently introduced a regression that broke Korean
    text input because the changes there resulted that only the last input
    string that we have from ImmGetCompositionStringW() for each time the
    commit signal is emitted is kept, and also as a result the final Korean
    character that is input by hitting space is also lost as a result, as we
    didn't check for whether we are done with preediting.
    
    Fix these issues by doing the following when we receive the
    WM_IME_COMPOSITION message with GCS_RESULTSTR from Windows:
    -Append to the string to commit, rather than replacing that string, if
     that string already has something in it (i.e. we did not receive the
     WM_IME_ENDCOMPOSITION from Windows IME yet).
    -Emit the commit signal immediately if we are already done with
     preediting, without waiting for the WM_IME_ENDCOMPOSITION message.
    
    Fixes issue #1350.

 modules/input/gtkimcontextime.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/modules/input/gtkimcontextime.c b/modules/input/gtkimcontextime.c
index c6ce515129..3d0c1cfc6f 100644
--- a/modules/input/gtkimcontextime.c
+++ b/modules/input/gtkimcontextime.c
@@ -997,6 +997,15 @@ ERROR_OUT:
   ImmReleaseContext (hwnd, himc);
 }
 
+static void
+gtk_im_context_ime_commit_input_string (GtkIMContext *context)
+{
+  GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
+
+  g_signal_emit_by_name (context, "commit", context_ime->commit_string);
+  g_free (context_ime->commit_string);
+  context_ime->commit_string = NULL;
+}
 
 static GdkFilterReturn
 gtk_im_context_ime_message_filter (GdkXEvent *xevent,
@@ -1069,12 +1078,30 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
                 gpointer buf = g_alloca (len);
                 ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len);
                 len /= 2;
-                context_ime->commit_string = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
+                if (context_ime->commit_string == NULL)
+                  context_ime->commit_string = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
+                else
+                  {
+                    gchar *tmp_commit_string = g_strdup (context_ime->commit_string);
+                    gchar *utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
+
+                    g_free (context_ime->commit_string);
+                    context_ime->commit_string = g_strconcat (context_ime->commit_string, utf8str, NULL);
+                    g_free (tmp_commit_string);
+                    g_free (utf8str);
+                  }
+
                 if (error)
                   {
                     g_warning ("%s", error->message);
                     g_error_free (error);
                   }
+
+                if (!context_ime->preediting)
+                  {
+                    gtk_im_context_ime_commit_input_string (context);
+                    retval = TRUE;
+                  }
               }
 
             if (context_ime->commit_string)
@@ -1083,6 +1110,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
 
         if (context_ime->use_preedit)
           retval = TRUE;
+
         break;
       }
 
@@ -1100,11 +1128,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
       g_signal_emit_by_name (context, "preedit-end");
 
       if (context_ime->commit_string)
-        {
-          g_signal_emit_by_name (context, "commit", context_ime->commit_string);
-          g_free (context_ime->commit_string);
-          context_ime->commit_string = NULL;
-        }
+        gtk_im_context_ime_commit_input_string (context);
 
       if (context_ime->use_preedit)
         retval = TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]