๐Ÿ“ฆ SergioRibera / imekit

Crossplatform Input Method implementation

โ˜… 4 stars โ‘‚ 0 forks ๐Ÿ‘ 4 watching
๐Ÿ“ฅ Clone https://github.com/SergioRibera/imekit.git
HTTPS git clone https://github.com/SergioRibera/imekit.git
SSH git clone git@github.com:SergioRibera/imekit.git
CLI gh repo clone SergioRibera/imekit
Sergio Ribera Sergio Ribera chore: update crate keywords 65d8ad0 1 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ examples
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ Cargo.toml
๐Ÿ“„ flake.lock
๐Ÿ“„ flake.nix
๐Ÿ“„ README.md
๐Ÿ“„ README.md

imekit

A cross-platform Rust library for implementing Input Method Engines (IME) using native protocols.

Overview

imekit provides native protocol implementations for creating input methods:

  • Linux/Wayland: zwp_input_method_v2 and zwp_text_input_v3 protocols
  • Linux/X11: XIM (X Input Method) protocol
  • Linux/IBus: IBus D-Bus interface (fallback when Wayland protocol unavailable)
  • Windows: Text Services Framework (TSF)
  • macOS: Input Method Kit (IMK)
This is not a text insertion library. It implements the actual IME protocols that allow you to:
  • Register as an input method with the system
  • Receive text input context (surrounding text, content type)
  • Commit text and preedit strings
  • Create popup surfaces for candidate windows

Features

FeatureDescription
logEnable logging via the log crate
tracingEnable logging via the tracing crate
ibusEnable IBus support for Linux (via zbus D-Bus interface)

Platform Support

PlatformProtocolStatus
Linux/Waylandzwp_input_method_v2โœ… Full support
Linux/Waylandzwp_text_input_v3โœ… Full support
Linux/X11XIMโœ… Full support
Linux/IBusD-Busโœ… Full support (with ibus feature)
WindowsTSF (Text Services Framework)โœ… Full support
macOSCGEvent/NSTextInputClientโœ… Full support

Wayland Compositor Support

CompositorSupport
swayโœ… Full support
Hyprlandโœ… Full support
KDE Plasmaโœ… Good support
GNOME/Mutterโš ๏ธ Uses IBus (enable ibus feature)
wlroots-basedโœ… Generally supported

Usage

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"] }

Basic Input Method

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));
    }
}

Text Input Client (receiving IME input)

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));
    }
}

Using IBus Directly

#[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(())
}

Requirements

Linux/Wayland

  • Compositor with zwp_input_method_v2 support
  • libwayland-dev for Wayland client libraries

Linux/X11

  • X11 display server with XTest extension
  • libx11-dev and libxtst-dev for X11 libraries

Linux/IBus (with ibus feature)

  • IBus daemon running
  • D-Bus session bus available

Windows

  • Windows 8+ with TSF support

macOS

  • macOS 10.5+ with Accessibility permissions

License

Licensed under either of:

  • Apache License, Version 2.0
  • MIT license