cli: allow setting keymaps from RMLVO names
This commit is contained in:
parent
0dfa6bc74b
commit
eedec24e88
5 changed files with 148 additions and 2 deletions
|
|
@ -16,6 +16,7 @@ use {
|
|||
utils::errorfmt::ErrorFmt,
|
||||
wire::{JayInputId, jay_input::*},
|
||||
},
|
||||
kbvm::xkb::rmlvo::Group,
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
uapi::OwnedFd,
|
||||
|
|
@ -212,6 +213,44 @@ impl JayInput {
|
|||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn set_keymap_from_names_impl<F>(
|
||||
&self,
|
||||
rules: Option<&str>,
|
||||
model: Option<&str>,
|
||||
layout: Option<&str>,
|
||||
variant: Option<&str>,
|
||||
options: Option<&str>,
|
||||
f: F,
|
||||
) -> Result<(), JayInputError>
|
||||
where
|
||||
F: FnOnce(&Rc<KbvmMap>) -> Result<(), JayInputError>,
|
||||
{
|
||||
self.or_error(|| {
|
||||
let mut groups = None::<Vec<_>>;
|
||||
if layout.is_some() || variant.is_some() {
|
||||
groups = Some(
|
||||
Group::from_layouts_and_variants(
|
||||
layout.unwrap_or_default(),
|
||||
variant.unwrap_or_default(),
|
||||
)
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
let mut options_vec = None::<Vec<_>>;
|
||||
if let Some(options) = options {
|
||||
options_vec = Some(options.split(",").collect());
|
||||
}
|
||||
let keymap = self.client.state.kb_ctx.keymap_from_names(
|
||||
rules,
|
||||
model,
|
||||
groups.as_deref(),
|
||||
options_vec.as_deref(),
|
||||
)?;
|
||||
f(&keymap)?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl JayInputRequestHandler for JayInput {
|
||||
|
|
@ -539,6 +578,44 @@ impl JayInputRequestHandler for JayInput {
|
|||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn set_keymap_from_names(
|
||||
&self,
|
||||
req: SetKeymapFromNames<'_>,
|
||||
_slf: &Rc<Self>,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.set_keymap_from_names_impl(
|
||||
req.rules,
|
||||
req.model,
|
||||
req.layout,
|
||||
req.variant,
|
||||
req.options,
|
||||
|map| {
|
||||
let seat = self.seat(req.seat)?;
|
||||
seat.set_seat_keymap(&map);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn set_device_keymap_from_names(
|
||||
&self,
|
||||
req: SetDeviceKeymapFromNames<'_>,
|
||||
_slf: &Rc<Self>,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.set_keymap_from_names_impl(
|
||||
req.rules,
|
||||
req.model,
|
||||
req.layout,
|
||||
req.variant,
|
||||
req.options,
|
||||
|map| {
|
||||
let dev = self.device(req.id)?;
|
||||
dev.set_keymap(Some(map.clone()));
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue