Consider the following application, using https://crates.io/crates/xkbcommon, that simulates the communication between a wayland compositor and a client using xkbcommon:
use xkbcommon::xkb::{
Context, KeyDirection, Keycode, Keymap, State, KEYMAP_FORMAT_TEXT_V1, STATE_LAYOUT_EFFECTIVE,
STATE_MODS_DEPRESSED, STATE_MODS_EFFECTIVE, STATE_MODS_LATCHED, STATE_MODS_LOCKED,
};
const KEYMAP: &str = r#"
xkb_keymap {
xkb_keycodes {
<shift> = 50;
<a> = 38;
};
xkb_types {
virtual_modifiers X = 0x200;
virtual_modifiers Y = Shift;
type "X" {
modifiers = Shift;
map[Shift] = Level2;
};
};
xkb_compat { };
xkb_symbols {
key <shift> {
[ Shift_L ],
[ SetMods(mods = X) ]
};
key <a> {
type = "X",
[ a, A ]
};
};
};
"#;
fn main() {
let ctx = Context::new(0);
let keymap =
Keymap::new_from_string(&ctx, KEYMAP.to_string(), KEYMAP_FORMAT_TEXT_V1, 0).unwrap();
// compositor
let mut server_state = State::new(&keymap);
server_state.update_key(Keycode::new(50), KeyDirection::Down);
dbg!(server_state.serialize_mods(STATE_MODS_EFFECTIVE));
dbg!(server_state.key_get_one_sym(Keycode::new(38)));
// client
let mut client_state = State::new(&keymap);
client_state.update_mask(
server_state.serialize_mods(STATE_MODS_DEPRESSED),
server_state.serialize_mods(STATE_MODS_LATCHED),
server_state.serialize_mods(STATE_MODS_LOCKED),
0,
0,
server_state.serialize_layout(STATE_LAYOUT_EFFECTIVE),
);
dbg!(client_state.serialize_mods(STATE_MODS_EFFECTIVE));
dbg!(client_state.key_get_one_sym(Keycode::new(38)));
}
The client should get the same keysym, but it does not. The output is
[src/main.rs:46:5] server_state.serialize_mods(STATE_MODS_EFFECTIVE) = 512
[src/main.rs:47:5] server_state.key_get_one_sym(Keycode::new(38)) = XK_a
[src/main.rs:58:5] client_state.serialize_mods(STATE_MODS_EFFECTIVE) = 513
[src/main.rs:59:5] client_state.key_get_one_sym(Keycode::new(38)) = XK_A
Consider the following application, using https://crates.io/crates/xkbcommon, that simulates the communication between a wayland compositor and a client using xkbcommon:
The client should get the same keysym, but it does not. The output is