1
0
Fork 0
forked from wry/wry

kbvm: identify keymaps by their hash

This commit is contained in:
Julian Orth 2025-09-07 12:28:57 +02:00
parent 11c10fde70
commit 6bea5a072c
3 changed files with 25 additions and 7 deletions

20
Cargo.lock generated
View file

@ -173,6 +173,19 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
[[package]]
name = "blake3"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3888aaa89e4b2a40fca9848e400f6a658a5a3978de7be858e209cafa8be9a4a0"
dependencies = [
"arrayref",
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq",
]
[[package]] [[package]]
name = "bstr" name = "bstr"
version = "1.11.3" version = "1.11.3"
@ -295,6 +308,12 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "constant_time_eq"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
[[package]] [[package]]
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.7"
@ -587,6 +606,7 @@ dependencies = [
"ash", "ash",
"backtrace", "backtrace",
"bincode", "bincode",
"blake3",
"bstr", "bstr",
"byteorder", "byteorder",
"cc", "cc",

View file

@ -67,6 +67,7 @@ regex = "1.11.1"
cfg-if = "1.0.0" cfg-if = "1.0.0"
opera = "1.0.1" opera = "1.0.1"
with_builtin_macros = "0.1.0" with_builtin_macros = "0.1.0"
blake3 = "1.8.2"
[build-dependencies] [build-dependencies]
repc = "0.1.1" repc = "0.1.1"

View file

@ -33,21 +33,18 @@ pub enum KbvmError {
pub struct KbvmContext { pub struct KbvmContext {
pub ctx: xkb::Context, pub ctx: xkb::Context,
pub ids: KbvmMapIds,
} }
impl Default for KbvmContext { impl Default for KbvmContext {
fn default() -> Self { fn default() -> Self {
let mut ctx = xkb::Context::builder(); let mut ctx = xkb::Context::builder();
ctx.enable_environment(true); ctx.enable_environment(true);
Self { Self { ctx: ctx.build() }
ctx: ctx.build(),
ids: Default::default(),
}
} }
} }
linear_ids!(KbvmMapIds, KbvmMapId, u64); #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct KbvmMapId([u8; 32]);
pub struct KbvmMap { pub struct KbvmMap {
pub id: KbvmMapId, pub id: KbvmMapId,
@ -90,7 +87,7 @@ impl KbvmContext {
.map_err(KbvmError::CouldNotParseKeymap)?; .map_err(KbvmError::CouldNotParseKeymap)?;
let builder = map.to_builder(); let builder = map.to_builder();
Ok(Rc::new(KbvmMap { Ok(Rc::new(KbvmMap {
id: self.ids.next(), id: KbvmMapId(*blake3::hash(keymap).as_bytes()),
state_machine: builder.build_state_machine(), state_machine: builder.build_state_machine(),
map: create_keymap_memfd(&map, false).map_err(KbvmError::KeymapMemfd)?, map: create_keymap_memfd(&map, false).map_err(KbvmError::KeymapMemfd)?,
xwayland_map: create_keymap_memfd(&map, true).map_err(KbvmError::KeymapMemfd)?, xwayland_map: create_keymap_memfd(&map, true).map_err(KbvmError::KeymapMemfd)?,