#keymap #wayland #xkbcommon #xkb #libxkbcommon

xkbcommon-rs

a port of libxkbcommon in safe Rust

3 releases

0.1.2 Feb 28, 2025
0.1.1 Feb 28, 2025
0.1.0 Jun 7, 2024

#705 in GUI

Download history 7/week @ 2024-11-17 1/week @ 2024-11-24 2/week @ 2024-12-01 22/week @ 2024-12-08 4/week @ 2024-12-15 16/week @ 2024-12-29 11/week @ 2025-01-05 9/week @ 2025-01-12 5/week @ 2025-01-19 4/week @ 2025-01-26 15/week @ 2025-02-02 18/week @ 2025-02-09 15/week @ 2025-02-16 261/week @ 2025-02-23 88/week @ 2025-03-02

385 downloads per month

Custom license

1MB
19K SLoC

xkbcommon-rs

Crates.io docs.rs

A port of libxkbcommon in safe Rust. Notably, this crate provides Send + Sync types for Keymap and State.

This safe Rust port intends to provide an alternative to the existing C bindings crates, e.g. for projects that are built entirely in safe Rust. It aims to release versions that match the releases of the original libxkbcommon.

In Cargo.toml:

xkbcommon-rs = "0.1.2"

Use in Wayland client application

The Keymap and State provided by this crate can be used to represent keyboard state in a Wayland client. For example, xkbcommon-rs can be used in combination with Smithay's wayland-client crate.

Setting up the keymap and the state

use xkbcommon_rs::*;

let keymap = Keymap::new_from_string(
    Context::new(0).unwrap(),
    string, /* Read from the OwnedFd provided by the Wayland compositor */
    KeymapFormat::TextV1,
    0).unwrap();

let mut state = State::new(keymap);

Getting keyboard symbols and updating the state

// Get syms before updating state
let sym = state.key_get_one_sym(keycode)?;

// Update state with the parameters provided by the wl_keyboard::Event::Modifiers{..} event
state.update_mask(
    mods_depressed, mods_latched, mods_locked,
    0, 0, group as usize);

For more information on using State::update_mask() in a Wayland client, see https://wayland-book.com/seat/keyboard.html.

Info

This crate is intended for use in a Wayland client. Compositor-side functionality is also provided.

The current version corresponds to libxkbcommon version 1.7.0. Version 1.8.0 is currently under development.

This crate strives to be as close a reimplementation of the original libxkbcommon library as possible, although some features are not implemented yet.

Contributing

Feedback and PRs are welcome.

Version table

xkbcommon-rs version libxkbcommon version
0.2.0 (unreleased) 1.8.0
0.1.2 1.7.0
0.1.1 1.7.0
0.1.0 1.7.0

Dependencies

~8–11MB
~173K SLoC