[gtk/unintrusive-compose-preedit: 8/8] imwayland: Tweak preedit text
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/unintrusive-compose-preedit: 8/8] imwayland: Tweak preedit text
- Date: Thu, 18 Feb 2021 16:44:22 +0000 (UTC)
commit d84a028455cadbf146e4cd234f57dc1df2e69cd6
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Feb 18 11:31:04 2021 -0500
imwayland: Tweak preedit text
Tweak the preedit text we get from IBus (via the compositor) to
match what GtkIMContextSimple produces for Compose sequences now.
This provides a unified experience.
gtk/gtkimcontextwayland.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkimcontextwayland.c b/gtk/gtkimcontextwayland.c
index 915ad9e854..397909064d 100644
--- a/gtk/gtkimcontextwayland.c
+++ b/gtk/gtkimcontextwayland.c
@@ -570,6 +570,38 @@ gtk_im_context_wayland_set_client_widget (GtkIMContext *context,
}
}
+/* We want a unified experience between GtkIMContextSimple and IBus / Wayland
+ * when it comes to Compose sequences. IBus initial implementation of preedit
+ * for Compose sequences shows U+2384, which has been described as 'distracting'.
+ * This function tries to detect this case, and tweaks the text to match what
+ * GtkIMContextSimple produces.
+ */
+static char *
+tweak_preedit (const char *text)
+{
+ GString *s;
+ guint len;
+
+ s = g_string_new ("");
+
+ len = g_utf8_strlen (text, -1);
+
+ for (const char *p = text; *p; p = g_utf8_next_char (p))
+ {
+ gunichar ch = g_utf8_get_char (p);
+
+ if (ch == 0x2384)
+ {
+ if (len == 1 || p > text)
+ g_string_append (s, "ยท");
+ }
+ else
+ g_string_append_unichar (s, ch);
+ }
+
+ return g_string_free (s, FALSE);
+}
+
static void
gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
char **str,
@@ -599,7 +631,7 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
context_wayland->current_preedit.text ? context_wayland->current_preedit.text : "";
if (str)
- *str = g_strdup (preedit_str);
+ *str = tweak_preedit (preedit_str);
if (cursor_pos)
*cursor_pos = g_utf8_strlen (preedit_str,
context_wayland->current_preedit.cursor_begin);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]