From af3ae201deff5927b3818d5211ec942f5ff76888 Mon Sep 17 00:00:00 2001 From: Fuminobu TAKEYAMA Date: Sat, 25 Apr 2026 15:03:49 +0900 Subject: [PATCH] Fix preedit decoration in ibus-mozc under Wayland Wayland protocols do not support specifying arbitrary RGB colors for preedit styling. This commit switchs preedidt decoration to IBus semantic preedit hints (available since 1.5.33) so that decoration works correctly under Wayland. --- src/unix/ibus/ibus_header.h | 6 +++--- src/unix/ibus/ibus_wrapper.cc | 6 +++--- src/unix/ibus/preedit_handler.cc | 25 +++++-------------------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/unix/ibus/ibus_header.h b/src/unix/ibus/ibus_header.h index 0daa9f1831..11a86005ed 100644 --- a/src/unix/ibus/ibus_header.h +++ b/src/unix/ibus/ibus_header.h @@ -40,8 +40,8 @@ static_assert(std::is_same::value, "guint must be uint."); static_assert(std::is_same::value, "gchar must be char."); static_assert(std::is_same::value, "gboolean must be int."); -#if !IBUS_CHECK_VERSION(1, 5, 4) -#error "ibus-mozc requires IBus>=1.5.4" -#endif // libibus (<1.5.4) +#if !IBUS_CHECK_VERSION(1, 5, 33) +#error "ibus-mozc requires IBus>=1.5.33" +#endif // libibus (<1.5.33) #endif // MOZC_UNIX_IBUS_IBUS_HEADER_H_ diff --git a/src/unix/ibus/ibus_wrapper.cc b/src/unix/ibus/ibus_wrapper.cc index 2c18c004c6..b825a6b408 100644 --- a/src/unix/ibus/ibus_wrapper.cc +++ b/src/unix/ibus/ibus_wrapper.cc @@ -42,9 +42,9 @@ static_assert(std::is_same::value, "gchar must be char."); static_assert(std::is_same::value, "gboolean must be int."); static_assert(std::is_same::value, "gpointer must be void*."); -#if !IBUS_CHECK_VERSION(1, 5, 4) -#error "ibus-mozc requires IBus>=1.5.4" -#endif // libibus (<1.5.4) +#if !IBUS_CHECK_VERSION(1, 5, 33) +#error "ibus-mozc requires IBus>=1.5.33" +#endif // libibus (<1.5.33) namespace mozc { namespace ibus { diff --git a/src/unix/ibus/preedit_handler.cc b/src/unix/ibus/preedit_handler.cc index a04f92f140..681aab5adb 100644 --- a/src/unix/ibus/preedit_handler.cc +++ b/src/unix/ibus/preedit_handler.cc @@ -55,35 +55,20 @@ IbusTextWrapper ComposePreeditText(const commands::Preedit& preedit) { IBusAttrUnderline attr = IBUS_ATTR_UNDERLINE_ERROR; switch (segment.annotation()) { case commands::Preedit::Segment::NONE: - attr = IBUS_ATTR_UNDERLINE_NONE; + // No decoration break; case commands::Preedit::Segment::UNDERLINE: - attr = IBUS_ATTR_UNDERLINE_SINGLE; + text.AppendAttribute(IBUS_ATTR_TYPE_HINT, IBUS_ATTR_PREEDIT_WHOLE, + start, end); break; case commands::Preedit::Segment::HIGHLIGHT: - attr = IBUS_ATTR_UNDERLINE_DOUBLE; + text.AppendAttribute(IBUS_ATTR_TYPE_HINT, IBUS_ATTR_PREEDIT_SELECTION, + start, end); break; default: LOG(ERROR) << "unknown annotation:" << segment.annotation(); break; } - end += segment.value_length(); - text.AppendAttribute(IBUS_ATTR_TYPE_UNDERLINE, attr, start, end); - - // Many applications show a single underline regardless of using - // IBUS_ATTR_UNDERLINE_SINGLE or IBUS_ATTR_UNDERLINE_DOUBLE for some - // reasons. Here we add a background color for the highlighted candidate - // to make it easiliy distinguishable. - if (segment.annotation() == commands::Preedit::Segment::HIGHLIGHT) { - constexpr uint kBackgroundColor = 0xD1EAFF; - text.AppendAttribute(IBUS_ATTR_TYPE_BACKGROUND, kBackgroundColor, start, - end); - // IBUS_ATTR_TYPE_FOREGROUND is necessary to highlight the segment on - // Firefox. - constexpr uint kForegroundColor = 0x000000; - text.AppendAttribute(IBUS_ATTR_TYPE_FOREGROUND, kForegroundColor, start, - end); - } start = end; }