wkb — Wayland Keyboard
A lightweight, pure Rust keyboard handling library for Wayland. WKB is a
drop-in alternative to xkbcommon that compiles XKB keymaps, tracks modifier
and compose state, and maps evdev key codes to characters — all without C
dependencies.
Features
- XKB keymap import — parse keymap strings received from Wayland
compositors via
wl_keyboard. - XKB keymap export — serialize keymaps back to XKB v1 text format via
as_xkb_string(). - Full modifier support — Shift, Ctrl, Alt, AltGr, Caps Lock, Num Lock, Scroll Lock, and multi-level keys.
- Compose sequences — built-in compose key and automatic compose handling.
- LED state — query Caps/Num/Scroll Lock indicator state.
- Repeat info — query whether a key repeats.
- Lightweight — no C FFI, no
unsafe, minimal dependencies.
Quick Start
use ;
// Build from an XKB keymap string (e.g. received from a Wayland compositor)
let keymap_string = read_to_string.unwrap;
let mut wkb = WKBnew_from_string;
// Process a key press (evdev code 38 = 'a' on US layout)
let = wkb.key;
assert_eq!;
Feature Flags
| Flag | Default | Description |
|---|---|---|
xkb |
yes | XKB keymap compilation via the xkb-core crate |
compose |
yes | Compose-key / dead-key sequence support |
testing |
no | Exposes internal helpers for integration tests (not public API) |
Benchmarks
Benchmarks are generated automatically by CI. Run cargo bench locally or push to main to update.
Scope and Limitations
WKB targets the subset of XKB used by Wayland clients and compositors. Geometry descriptions and other X11-only features are intentionally out of scope. A future native keyboard format (TOML/RON) is planned but not yet available.
License
MIT