mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
input/IME: Defer the emit of the "commit" signal
On Windows, when IME is used, each keystroke results in the
WM_IME_COMPOSITION event being sent first. This means that in our case
when one decides on to accept the input that is in the preedit buffer,
we first get from Windows the WM_IME_COMPOSITION event
(where we emit the commit signal), followed by the WM_IME_ENDCOMPOSITION
event (where we emit the pair of preedit-changed and preedit-end
signals).
Since commit f11f989
(GtkEntry: Remove recompute idle), we do the input
recomputation directly, this will cause a pair of "Pango-WARNING:
Assertion failed: (index >= 0 && index <= layout->length)" being shown,
as gtkentry.c's priv->preedit_length and priv->preedit_cursor was unable
to be reset to 0 in time as a result of the recomputation triggered by
the commit being done before the reset of priv->preedit_length and
priv->preedit_cursor (which are no longer valid as we essentially say
that we are done with the preedit buffer).
As we could only acquire the final string that was entered in this
preedit session when we handle the WM_IME_COMPOSITION event, fix this by
saving up the final string we acquire from Windows IME in UTF-8 when we
handle the WM_IME_COMPOSITION event from Windows, and emit the commit
signal with that string after we emit the preedit-changed and
preedit-end signals when we handle the WM_IME_ENDCOMPOSITION event from
Windows, which comes afterwards.
Also fix the formatting of the code around the parts of the files that
was changed.
https://bugzilla.gnome.org/show_bug.cgi?id=787142
This commit is contained in:
parent
916981f66e
commit
64a489adbf
@ -187,6 +187,7 @@ gtk_im_context_ime_init (GtkIMContextIME *context_ime)
|
|||||||
context_ime->cursor_location.y = 0;
|
context_ime->cursor_location.y = 0;
|
||||||
context_ime->cursor_location.width = 0;
|
context_ime->cursor_location.width = 0;
|
||||||
context_ime->cursor_location.height = 0;
|
context_ime->cursor_location.height = 0;
|
||||||
|
context_ime->commit_string = NULL;
|
||||||
|
|
||||||
context_ime->priv = g_malloc0 (sizeof (GtkIMContextIMEPrivate));
|
context_ime->priv = g_malloc0 (sizeof (GtkIMContextIMEPrivate));
|
||||||
context_ime->priv->conversion_mode = 0;
|
context_ime->priv->conversion_mode = 0;
|
||||||
@ -1071,14 +1072,14 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
|
|||||||
gchar *utf8str = NULL;
|
gchar *utf8str = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
len = ImmGetCompositionStringW (himc, GCS_RESULTSTR, NULL, 0);
|
len = ImmGetCompositionStringW (himc, GCS_RESULTSTR, NULL, 0);
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
gpointer buf = g_alloca (len);
|
gpointer buf = g_alloca (len);
|
||||||
ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len);
|
ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len);
|
||||||
len /= 2;
|
len /= 2;
|
||||||
utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
|
context_ime->commit_string = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
g_warning ("%s", error->message);
|
g_warning ("%s", error->message);
|
||||||
@ -1086,12 +1087,8 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utf8str)
|
if (context_ime->commit_string)
|
||||||
{
|
retval = TRUE;
|
||||||
g_signal_emit_by_name (context, "commit", utf8str);
|
|
||||||
g_free (utf8str);
|
|
||||||
retval = TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context_ime->use_preedit)
|
if (context_ime->use_preedit)
|
||||||
@ -1111,6 +1108,14 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
|
|||||||
context_ime->preediting = FALSE;
|
context_ime->preediting = FALSE;
|
||||||
g_signal_emit_by_name (context, "preedit-changed");
|
g_signal_emit_by_name (context, "preedit-changed");
|
||||||
g_signal_emit_by_name (context, "preedit-end");
|
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)
|
if (context_ime->use_preedit)
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -45,6 +45,7 @@ struct _GtkIMContextIME
|
|||||||
guint opened : 1;
|
guint opened : 1;
|
||||||
guint focus : 1;
|
guint focus : 1;
|
||||||
GdkRectangle cursor_location;
|
GdkRectangle cursor_location;
|
||||||
|
gchar *commit_string;
|
||||||
|
|
||||||
GtkIMContextIMEPrivate *priv;
|
GtkIMContextIMEPrivate *priv;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user