Skip to content

Commit 9f9728a

Browse files
committed
Use IBus semantic preedit hints API for Wayland support
Fix an issue where preedit decoration in ibus-mozc was missing under Wayland. This is because Wayland protocols do not support specifying arbitrary RGB colors for preedit styling. Address this limitation by adopting new IBus semantic preedit hints API, which has been available since 1.5.33. Fixes: #1484
1 parent 0c8acf4 commit 9f9728a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/unix/ibus/preedit_handler.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,23 @@ IbusTextWrapper ComposePreeditText(const commands::Preedit& preedit) {
5252
int end = 0;
5353
for (int i = 0; i < preedit.segment_size(); ++i) {
5454
const commands::Preedit::Segment& segment = preedit.segment(i);
55+
#if IBUS_CHECK_VERSION(1, 5, 33)
56+
// IBus's semantic pre-edit style name is since 1.5.33, which is necessary
57+
// to use pre-edit style under Wayland session.
58+
IBusAttrPreedit hint = IBUS_ATTR_PREEDIT_WHOLE;
59+
#else // libibus (>=1.5.33)
5560
IBusAttrUnderline attr = IBUS_ATTR_UNDERLINE_ERROR;
61+
#endif // !libibus (>=1.5.33)
5662
switch (segment.annotation()) {
63+
#if IBUS_CHECK_VERSION(1, 5, 33)
64+
case commands::Preedit::Segment::NONE:
65+
case commands::Preedit::Segment::UNDERLINE:
66+
// Do nothing; use IBUS_ATTR_PREEDIT_WHOLE.
67+
break;
68+
case commands::Preedit::Segment::HIGHLIGHT:
69+
hint = IBUS_ATTR_PREEDIT_SELECTION;
70+
break;
71+
#else // libibus (>=1.5.33)
5772
case commands::Preedit::Segment::NONE:
5873
attr = IBUS_ATTR_UNDERLINE_NONE;
5974
break;
@@ -63,11 +78,15 @@ IbusTextWrapper ComposePreeditText(const commands::Preedit& preedit) {
6378
case commands::Preedit::Segment::HIGHLIGHT:
6479
attr = IBUS_ATTR_UNDERLINE_DOUBLE;
6580
break;
81+
#endif // !libibus (>=1.5.33)
6682
default:
6783
LOG(ERROR) << "unknown annotation:" << segment.annotation();
6884
break;
6985
}
7086
end += segment.value_length();
87+
#if IBUS_CHECK_VERSION(1, 5, 33)
88+
text.AppendAttribute(IBUS_ATTR_TYPE_HINT, hint, start, end);
89+
#else // libibus (>=1.5.33)
7190
text.AppendAttribute(IBUS_ATTR_TYPE_UNDERLINE, attr, start, end);
7291

7392
// Many applications show a single underline regardless of using
@@ -84,6 +103,7 @@ IbusTextWrapper ComposePreeditText(const commands::Preedit& preedit) {
84103
text.AppendAttribute(IBUS_ATTR_TYPE_FOREGROUND, kForegroundColor, start,
85104
end);
86105
}
106+
#endif // !libibus (>=1.5.33)
87107
start = end;
88108
}
89109

0 commit comments

Comments
 (0)