diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2021-07-26 22:52:18 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2021-07-26 22:52:18 +0900 |
commit | 2fc1a028aa697f1320d85a76548cde12894bf9ab (patch) | |
tree | b27e160a70a4916aae3f0903b51dcb8ca5f81d54 | |
parent | 7e12d589ee4979fdd0f0b08f1bac9049741ec628 (diff) | |
download | ibus-2fc1a028aa697f1320d85a76548cde12894bf9ab.tar.gz |
src/ibusenginesimple: Multi_key to 0xB7
Use · instead of ⎄ to display Multi_key in pre-edit.
BUG=https://gitlab.gnome.org/GNOME/gtk/-/issues/3669
BUG=https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3220
-rw-r--r-- | src/ibuscomposetable.c | 8 | ||||
-rw-r--r-- | src/ibusenginesimple.c | 49 |
2 files changed, 30 insertions, 27 deletions
diff --git a/src/ibuscomposetable.c b/src/ibuscomposetable.c index f85177a6..4ebf119b 100644 --- a/src/ibuscomposetable.c +++ b/src/ibuscomposetable.c @@ -1846,7 +1846,13 @@ ibus_keysym_to_unicode (guint16 keysym, CASE_COMBINE (tilde, 0x0303, 0x007E); CASE_COMBINE (voiced_sound, 0x3099, 0x309B); case IBUS_KEY_Multi_key: - return 0x2384; + /* We only show the Compose key visibly when it is the + * only glyph in the preedit, or when it occurs in the + * middle of the sequence. Sadly, the official character, + * U+2384, COMPOSITION SYMBOL, is bit too distracting, so + * we use U+00B7, MIDDLE DOT. + */ + return 0x00B7; default:; } return 0x0; diff --git a/src/ibusenginesimple.c b/src/ibusenginesimple.c index 4644620b..57ca10c4 100644 --- a/src/ibusenginesimple.c +++ b/src/ibusenginesimple.c @@ -289,32 +289,27 @@ ibus_engine_simple_update_preedit_text (IBusEngineSimple *simple) { IBusEngineSimplePrivate *priv = simple->priv; - gunichar outbuf[COMPOSE_BUFFER_SIZE + 1]; - int len = 0; + GString *s = g_string_new (""); if (priv->in_hex_sequence || priv->in_emoji_sequence) { int hexchars = 0; if (priv->in_hex_sequence) - outbuf[0] = L'u'; + g_string_append_c (s, 'u'); else - outbuf[0] = L'@'; - - len = 1; + g_string_append_c (s, '@'); while (priv->compose_buffer[hexchars] != 0) { - outbuf[len] = ibus_keyval_to_unicode ( - priv->compose_buffer[hexchars]); - ++len; - ++hexchars; + g_string_append_unichar( + s, + ibus_keyval_to_unicode (priv->compose_buffer[hexchars++]) + ); } - - g_assert (len <= COMPOSE_BUFFER_SIZE); } else if (priv->tentative_match) { - outbuf[len++] = priv->tentative_match; + g_string_append_unichar(s, priv->tentative_match); } else if (priv->tentative_emoji && *priv->tentative_emoji) { IBusText *text = ibus_text_new_from_string (priv->tentative_emoji); - len = strlen (priv->tentative_emoji); + int len = strlen (priv->tentative_emoji); ibus_text_append_attribute (text, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, len); ibus_engine_update_preedit_text ((IBusEngine *)simple, text, len, TRUE); @@ -324,31 +319,33 @@ ibus_engine_simple_update_preedit_text (IBusEngineSimple *simple) while (priv->compose_buffer[hexchars] != 0) { guint16 keysym = priv->compose_buffer[hexchars]; gunichar unichar = ibus_keysym_to_unicode (keysym, FALSE); - if (unichar > 0) - outbuf[len] = unichar; - else - outbuf[len] = ibus_keyval_to_unicode (keysym); - if (!outbuf[len]) { + if (unichar > 0) { + g_string_append_unichar(s, unichar); + } else { + unichar = ibus_keyval_to_unicode (keysym); + g_string_append_unichar(s, unichar); + } + if (!unichar) { g_warning ( "Not found alternative character of compose key 0x%X", priv->compose_buffer[hexchars]); } - ++len; ++hexchars; } - g_assert (len <= IBUS_MAX_COMPOSE_LEN); } - outbuf[len] = L'\0'; - if (len == 0) { + if (s->len == 0) { ibus_engine_hide_preedit_text ((IBusEngine *)simple); - } - else { - IBusText *text = ibus_text_new_from_ucs4 (outbuf); + } else if (s->len >= G_MAXINT) { + g_warning ("%s is too long compose length: %lu", s->str, s->len); + } else { + int len = (int)s->len; + IBusText *text = ibus_text_new_from_string (s->str); ibus_text_append_attribute (text, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, len); ibus_engine_update_preedit_text ((IBusEngine *)simple, text, len, TRUE); } + g_string_free (s, TRUE); } |