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



commit 01606be05a398833154b459b6d0dcd3a46f56687
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 | 60 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 53 insertions(+), 7 deletions(-)
---
diff --git a/modules/input/gtkimcontextime.c b/modules/input/gtkimcontextime.c
index c6ce515129..c5063fe4a7 100644
--- a/modules/input/gtkimcontextime.c
+++ b/modules/input/gtkimcontextime.c
@@ -503,6 +503,26 @@ get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret)
                }
            }
        }
+
+  if (context_ime->commit_string)
+    {
+      if (utf8str)
+        {
+          gchar *utf8str_new = g_strdup (utf8str);
+
+          /* Note: We *don't* want to update context_ime->commit_string here!  Otherwise
+                   it will be updated repeatedly, not what we want!*/
+          g_free (utf8str);
+          utf8str = g_strconcat (context_ime->commit_string, utf8str_new, NULL);
+          g_free (utf8str_new);
+          pos += strlen (context_ime->commit_string);
+        }
+      else
+        {
+          utf8str = g_strdup (context_ime->commit_string);
+          pos = strlen (context_ime->commit_string);
+        }
+    }
     }
 
   if (!utf8str)
@@ -997,6 +1017,18 @@ ERROR_OUT:
   ImmReleaseContext (hwnd, himc);
 }
 
+static void
+gtk_im_context_ime_commit_input_string (GtkIMContext *context)
+{
+  GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
+
+  if (context_ime->commit_string == NULL)
+    return;
+
+  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 +1101,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 +1133,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
 
         if (context_ime->use_preedit)
           retval = TRUE;
+
         break;
       }
 
@@ -1099,12 +1150,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
       g_signal_emit_by_name (context, "preedit-changed");
       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]