xkbcommon-rs

Crates.ioxkbcommon-rs
lib.rsxkbcommon-rs
version0.1.0
sourcesrc
created_at2024-06-07 16:54:10.937948
updated_at2024-06-07 16:54:10.937948
descriptiona port of libxkbcommon in safe Rust
homepage
repositoryhttps://github.com/wysiwys/xkbcommon-rs
max_upload_size
id1264989
size868,224
(wysiwys)

documentation

README

xkbcommon-rs

A port of libxkbcommon in safe Rust.

In Cargo.toml:

xkbcommon-rs = "0.1.0"

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.

Corresponds to libxkbcommon version 1.7.0.

Commit count: 88

cargo fmt