diff options
author | LRN <lrn1986@gmail.com> | 2018-10-08 20:04:08 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2018-10-08 20:04:08 +0000 |
commit | caa5ba46ad45c091ca133a4b5ab0dcd00c7c82ae (patch) | |
tree | cda84e2fc07e26f9a24bcdbeeabf0257f2d2afc0 | |
parent | adbaee796de3ccb9b0a95b298fb0bfd00c2fcdd4 (diff) | |
parent | 1ece55620036b41ce1b0fcf434fde78f27af1af1 (diff) | |
download | gtk+-caa5ba46ad45c091ca133a4b5ab0dcd00c7c82ae.tar.gz |
Merge branch 'gtk-3-24.win.updated' into 'gtk-3-24'
gtkimcontextime.c: Fix Korean input
See merge request GNOME/gtk!356
-rw-r--r-- | modules/input/gtkimcontextime.c | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/modules/input/gtkimcontextime.c b/modules/input/gtkimcontextime.c index c6ce515129..2b165e9fcd 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 += g_utf8_strlen (context_ime->commit_string, -1); + } + else + { + utf8str = g_strdup (context_ime->commit_string); + pos = g_utf8_strlen (context_ime->commit_string, -1); + } + } } if (!utf8str) @@ -997,7 +1020,6 @@ ERROR_OUT: ImmReleaseContext (hwnd, himc); } - static GdkFilterReturn gtk_im_context_ime_message_filter (GdkXEvent *xevent, GdkEvent *event, @@ -1070,19 +1092,26 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent, ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len); len /= 2; context_ime->commit_string = g_utf16_to_utf8 (buf, len, NULL, NULL, &error); + if (error) { g_warning ("%s", error->message); g_error_free (error); } - } - if (context_ime->commit_string) - retval = TRUE; + 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; + retval = TRUE; + } + } } if (context_ime->use_preedit) retval = TRUE; + break; } @@ -1099,13 +1128,6 @@ 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; - } - if (context_ime->use_preedit) retval = TRUE; break; |