Wubi’s “dead key passthrough” and wbpy’s dual-buffer synchronization design philosophy.


This is part 5/8 of the TUX IM Dev Log: From Zero to 0.1 series.
Part 5 · Wubi and Mixed Input: Wubi + Wbpy — Two Philosophies
Pinyin is a “stream” — a string of letters corresponds to a list of candidates. Wubi is a “code” — a set of letters directly maps to a Chinese character. The data flow direction of these two input methods is completely different. This post covers how TUX IM accommodates both philosophies with the same InputMode protocol, and the tricky aspects of mixed (Wbpy) mode.
Wubi: Every Keypress is a Commitment
Wubi 86 works like this:
- User presses 1-4 letters, forming a code (e.g.,
ycfgcorresponds to the character “主”). - Candidate list pops up with candidate characters.
- Press number keys to select a candidate.
Core difficulty: How to determine when the user has finished inputting?
- Pinyin: the longer the buffer, the better — you can type continuously.
- Wubi: when the buffer reaches the deepest level of the current trie, force commit.
Dead Key Passthrough: Now ‘J’ Can Be Output
User feedback: pressing j alone produces no response — no candidate appears, and the letter doesn’t reach the application.
Reason: Wubi mode consumes every keypress (handled=True), so a single letter j in Wubi mode finds no candidate and the letter doesn’t pass through to the application.
Fix (commit 1dbecf0): check if the new buffer is a prefix of any Wubi code. If not, pass the character through as a Latin letter.
The philosophy behind this fix: Wubi mode should not “kidnap” the user’s keyboard. If the typed letter is not a prefix of any code, the user presumably wants to type an English letter — so just pass it through to the application.
Mixed Wbpy: Two Engines in Parallel
Wbpy = Wubi + Pinyin. Users can have both Wubi codes and Pinyin letters in the same input segment — the engine automatically determines which each segment belongs to.
Design approach: Run two engines in parallel, feed keypresses to both, see which produces candidates.
Comments