1
0
Fork 0
forked from wry/wry

config: Add keymap_from_names for RMLVO keymaps

This commit is contained in:
khyperia 2025-12-26 13:19:23 +01:00 committed by Julian Orth
parent bc9f2aef69
commit 0dfa6bc74b
5 changed files with 135 additions and 4 deletions

View file

@ -65,7 +65,7 @@ use {
CLICK_METHOD_BUTTON_AREAS, CLICK_METHOD_CLICKFINGER, CLICK_METHOD_NONE, ClickMethod,
},
},
keyboard::{Keymap, mods::Modifiers, syms::KeySym},
keyboard::{Group, Keymap, mods::Modifiers, syms::KeySym},
logging::LogLevel,
theme::{BarPosition, colors::Colorable, sized::Resizable},
timer::Timer as JayTimer,
@ -316,6 +316,39 @@ impl ConfigProxyHandler {
res
}
fn handle_keymap_from_names(
&self,
rules: Option<&str>,
model: Option<&str>,
groups: Option<Vec<Group<'_>>>,
options: Option<Vec<&str>>,
) -> Result<(), CphError> {
let kbvm_groups = groups.map(|groups| {
groups
.iter()
.map(|g| kbvm::xkb::rmlvo::Group {
layout: g.layout,
variant: g.variant,
})
.collect::<Vec<_>>()
});
let (keymap, res) = match self.state.kb_ctx.keymap_from_names(
rules,
model,
kbvm_groups.as_deref(),
options.as_deref(),
) {
Ok(keymap) => {
let id = Keymap(self.id());
self.keymaps.set(id, keymap);
(id, Ok(()))
}
Err(e) => (Keymap::INVALID, Err(CphError::ParseKeymapError(e))),
};
self.respond(Response::KeymapFromNames { keymap });
res
}
fn handle_get_connectors(
&self,
dev: Option<DrmDevice>,
@ -3332,6 +3365,14 @@ impl ConfigProxyHandler {
} => self
.handle_connector_set_use_native_gamut(connector, use_native_gamut)
.wrn("connector_set_use_native_gamut")?,
ClientMessage::KeymapFromNames {
rules,
model,
groups,
options,
} => self
.handle_keymap_from_names(rules, model, groups, options)
.wrn("keymap_from_names")?,
}
Ok(())
}

View file

@ -92,6 +92,25 @@ impl KbvmContext {
.ctx
.keymap_from_bytes(WriteToLog, None, keymap)
.map_err(KbvmError::CouldNotParseKeymap)?;
let id = KbvmMapId(*blake3::hash(keymap).as_bytes());
self.create_keymap(id, map)
}
pub fn keymap_from_names(
&self,
rules: Option<&str>,
model: Option<&str>,
groups: Option<&[xkb::rmlvo::Group<'_>]>,
options: Option<&[&str]>,
) -> Result<Rc<KbvmMap>, KbvmError> {
let map = self
.ctx
.keymap_from_names(WriteToLog, rules, model, groups, options);
let id = KbvmMapId(*blake3::hash(map.format().to_string().as_bytes()).as_bytes());
self.create_keymap(id, map)
}
fn create_keymap(&self, id: KbvmMapId, map: Keymap) -> Result<Rc<KbvmMap>, KbvmError> {
let mut has_indicators = false;
let mut num_lock = None;
let mut caps_lock = None;
@ -111,7 +130,7 @@ impl KbvmContext {
}
let builder = map.to_builder();
Ok(Rc::new(KbvmMap {
id: KbvmMapId(*blake3::hash(keymap).as_bytes()),
id,
state_machine: builder.build_state_machine(),
map: create_keymap_memfd(&map, false).map_err(KbvmError::KeymapMemfd)?,
xwayland_map: create_keymap_memfd(&map, true).map_err(KbvmError::KeymapMemfd)?,