Crossplatform Input Method implementation
https://github.com/SergioRibera/imekit.git
A cross-platform Rust library for implementing Input Method Engines (IME) using native protocols.
imekit provides native protocol implementations for creating input methods:
zwp_input_method_v2 and zwp_text_input_v3 protocols| Feature | Description |
|---|---|
log | Enable logging via the log crate |
tracing | Enable logging via the tracing crate |
ibus | Enable IBus support for Linux (via zbus D-Bus interface) |
| Platform | Protocol | Status |
|---|---|---|
| Linux/Wayland | zwp_input_method_v2 | โ Full support |
| Linux/Wayland | zwp_text_input_v3 | โ Full support |
| Linux/X11 | XIM | โ Full support |
| Linux/IBus | D-Bus | โ
Full support (with ibus feature) |
| Windows | TSF (Text Services Framework) | โ Full support |
| macOS | CGEvent/NSTextInputClient | โ Full support |
| Compositor | Support |
|---|---|
| sway | โ Full support |
| Hyprland | โ Full support |
| KDE Plasma | โ Good support |
| GNOME/Mutter | โ ๏ธ Uses IBus (enable ibus feature) |
| wlroots-based | โ Generally supported |
Add to your Cargo.toml:
[dependencies]
imekit = "0.1"
# Optional: Enable logging
imekit = { version = "0.1", features = ["log"] }
# Optional: Enable IBus fallback for GNOME/Mutter
imekit = { version = "0.1", features = ["ibus"] }
use imekit::{InputMethod, InputMethodEvent};
fn main() -> Result<(), imekit::Error> {
// Auto-detects Wayland vs X11 on Linux
// Falls back to IBus if Wayland protocol unavailable (with `ibus` feature)
let mut im = InputMethod::new()?;
loop {
while let Some(event) = im.next_event() {
match event {
InputMethodEvent::Activate { serial } => {
println!("IME activated");
// Commit text when activated
im.commit_string("Hello! ๐")?;
im.commit(serial)?;
}
InputMethodEvent::SurroundingText { text, cursor, anchor } => {
println!("Context: {} (cursor: {})", text, cursor);
}
InputMethodEvent::Deactivate => {
println!("IME deactivated");
}
_ => {}
}
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
}
use imekit::wayland_impl::{TextInput, TextInputEvent};
fn main() -> Result<(), imekit::Error> {
let mut ti = TextInput::new()?;
ti.enable();
ti.commit();
loop {
while let Some(event) = ti.next_event() {
match event {
TextInputEvent::CommitString { text } => {
if let Some(text) = text {
println!("Received: {}", text);
}
}
TextInputEvent::PreeditString { text, .. } => {
if let Some(text) = text {
println!("Composing: {}", text);
}
}
_ => {}
}
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
}
#[cfg(feature = "ibus")]
use imekit::ibus_impl::IBusInputMethod;
fn main() -> Result<(), imekit::Error> {
#[cfg(feature = "ibus")]
{
// Create IBus input method directly
let im = IBusInputMethod::new()?;
// Use im...
}
Ok(())
}
zwp_input_method_v2 supportlibwayland-dev for Wayland client librarieslibx11-dev and libxtst-dev for X11 librariesibus feature)Licensed under either of: