MPSEMI 是一個以 Rust 為核心、透過 C/C++ 與 Fcitx 5 整合的輸入法引擎最小實作,示範如何將自訂文字處理流程包裝成 Fcitx 外掛。
- 提供混合注音與英文輸入流程的原型,核心維護預編輯緩衝與候選列表。
- 透過穩定的 C ABI (
mpsemi_*) 暴露引擎操作介面,方便跨語言整合。 - C++ 外掛利用 Fcitx5 API 取得按鍵事件、更新預編輯與候選窗。
share/內含 addon 與 input method 設定檔,可直接部署或打包。
rust/:輸入法核心(Rust 靜態函式庫與 C ABI)。cpp/:Fcitx5 外掛,連結 Rust 核心。share/:Fcitx addon/inputmethod 描述檔。CMakeLists.txt:頂層建置腳本,協調 C++ 與 Rust。RENAME.md:繁體中文與英文的額外說明。
- Rust 工具鏈(支援
edition = 2024,穩定版需使用最新版本或改用 nightly)。 - CMake 3.16 以上。
- 支援 C++17 的編譯器(GCC 10+、Clang 12+ 等)。
- Fcitx 5 Core 開發套件(通常為
fcitx5-devel或同名套件)。
mkdir -p build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$HOME/.local
cmake --build build以上指令會:
- 透過
cargo以 Release 模式編譯rust/的靜態函式庫。 - 編譯
cpp/mpsemi_engine.cpp並連結libmpsemi_core.a。 - 產生
mpsemi共用函式庫。
若需單獨驗證 Rust 核心,可執行:
cargo check --manifest-path rust/Cargo.toml
cargo build --manifest-path rust/Cargo.toml --release-
安裝至自訂路徑(以下示範
~/.local):cmake --install build --prefix $HOME/.local -
確認 Fcitx 5 搜尋路徑包含該 prefix(預設會包含
~/.local)。 -
使用
fcitx5-configtool在輸入法列表加入MPSEMI,或直接編輯~/.config/fcitx5/profile。 -
切換至 MPSEMI 即可測試:輸入會累積在預編輯區,空白或 Enter 會提交候選詞。
mpsemi_engine_new()/mpsemi_engine_free():建立與釋放引擎實例。mpsemi_process_utf8(ptr, s):傳入 UTF-8 字串,更新狀態並回傳是否已處理。mpsemi_preedit(ptr):取得預編輯字串(需以mpsemi_free_cstr釋放)。mpsemi_candidate_count(ptr)、mpsemi_candidate_at(ptr, idx):查詢候選筆數與內容。mpsemi_commit(ptr):取得要提交的字串並重置內部狀態。mpsemi_free_cstr(s):釋放由核心回傳的字串。
- Rust 端建議搭配
cargo fmt、cargo check、cargo clippy維持程式品質。 - C++ 端可利用
cmake --build build --target mpsemi快速增量建置。 - 需要偵錯時,可在 Rust 使用
dbg!,在 C++ 使用std::cerr。 - 若新增 Fcitx metadata,請同步調整
share/與對應的安裝路徑。
本專案以 MIT License 發佈,詳見 LICENSE。
MPSEMI is a minimal input method engine with a Rust core linked into Fcitx 5 via C/C++. It showcases how to wrap custom text-processing logic as an Fcitx plug-in.
- Prototype of a mixed Zhuyin/English flow that keeps a preedit buffer and candidate list in Rust.
- Stable C ABI (
mpsemi_*) makes the engine consumable from other languages. - C++ plug-in demonstrates handling key events and Fcitx5 UI updates.
- Metadata in
share/can be deployed or packaged directly.
rust/: Rust core producing a static library with a C ABI.cpp/: Fcitx5 plug-in that links against the Rust core.share/: Addon and input method descriptors.CMakeLists.txt: Top-level build script coordinating both components.RENAME.md: Additional bilingual project notes.
- Rust toolchain with support for edition 2024 (use the latest stable or switch to nightly).
- CMake 3.16 or newer.
- A C++17-capable compiler (GCC 10+, Clang 12+, etc.).
- Fcitx 5 Core development headers/libraries (
fcitx5-develor similar).
mkdir -p build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$HOME/.local
cmake --build buildThese commands:
- Compile the Rust static library in
rust/viacargo(Release mode). - Build
cpp/mpsemi_engine.cppand link againstlibmpsemi_core.a. - Produce the
mpsemishared library.
To verify the Rust core independently:
cargo check --manifest-path rust/Cargo.toml
cargo build --manifest-path rust/Cargo.toml --release-
Install to a prefix (example uses
~/.local):cmake --install build --prefix $HOME/.local -
Ensure Fcitx 5 searches the chosen prefix (it includes
~/.localby default). -
Use
fcitx5-configtoolto addMPSEMI, or edit~/.config/fcitx5/profilemanually. -
Switch to MPSEMI to test: visible characters accumulate in preedit, Space/Enter commits the candidate.
mpsemi_engine_new()/mpsemi_engine_free(): create and destroy engine instances.mpsemi_process_utf8(ptr, s): feed UTF-8 text, update state, return whether the event was consumed.mpsemi_preedit(ptr): fetch the current preedit (release withmpsemi_free_cstr).mpsemi_candidate_count(ptr),mpsemi_candidate_at(ptr, idx): inspect candidate list size and entries.mpsemi_commit(ptr): obtain the commit string and reset internal buffers.mpsemi_free_cstr(s): release strings returned by the core.
- Run
cargo fmt,cargo check, andcargo clippyon Rust changes. - Rebuild the C++ plug-in incrementally with
cmake --build build --target mpsemi. - Add debug output via
dbg!in Rust orstd::cerrin C++ as needed. - Keep
share/and install paths in sync when adding new Fcitx metadata.
Distributed under the MIT License. See LICENSE for details.