[gtk/gtk-3-24.win.updated] gtkimcontextime.c: Fix Korean input
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-3-24.win.updated] gtkimcontextime.c: Fix Korean input
- Date: Mon, 1 Oct 2018 04:57:06 +0000 (UTC)
commit 18648120f89ba827c7e758e9a3da99da385955be
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 | 109 +++++++++++++++++++++++++++++-----------
1 file changed, 79 insertions(+), 30 deletions(-)
---
diff --git a/modules/input/gtkimcontextime.c b/modules/input/gtkimcontextime.c
index c6ce515129..79d6c3cf78 100644
--- a/modules/input/gtkimcontextime.c
+++ b/modules/input/gtkimcontextime.c
@@ -479,30 +479,53 @@ get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret)
len = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
if (len > 0)
- {
- GError *error = NULL;
- gpointer buf = g_alloca (len);
-
- ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
- len /= 2;
- utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ {
+ GError *error = NULL;
+ gpointer buf = g_alloca (len);
+
+ ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
+ len /= 2;
+ utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
+ if (error)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
- if (pos_ret)
- {
- pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
- if (pos < 0 || len < pos)
- {
- g_warning ("ImmGetCompositionString: "
- "Invalid cursor position!");
- pos = 0;
- }
- }
- }
+ if (pos_ret)
+ {
+ pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
+ if (pos < 0 || len < pos)
+ {
+ g_warning ("ImmGetCompositionString: "
+ "Invalid cursor position!");
+ pos = 0;
+ }
+ }
+ }
+
+ 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 +1020,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 +1104,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 +1136,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
if (context_ime->use_preedit)
retval = TRUE;
+
break;
}
@@ -1099,12 +1153,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]