core: config: add extra_keys property

According to the layout XML format, keys prefixed with "loc " should
have an option to hide or show them. Add a property to facilitate this
configuration. Keep the array sorted so it can be binary searched for
the existence of an element.
This commit is contained in:
Richard Acayan 2024-11-07 18:17:01 -05:00
parent 14cd2d930b
commit d9956baffa
No known key found for this signature in database
GPG key ID: 0346F4894879DB73

View file

@ -15,6 +15,7 @@ pub struct Configuration {
longpress: u64, longpress: u64,
repeat: u64, repeat: u64,
layout: String, layout: String,
extra_keys: Vec<String>,
wayland_height: i32, wayland_height: i32,
wayland_im_enable: bool, wayland_im_enable: bool,
} }
@ -46,6 +47,7 @@ impl Configuration {
longpress: 600, longpress: 600,
repeat: 25, repeat: 25,
layout: String::from("latn_qwerty_us.xml"), layout: String::from("latn_qwerty_us.xml"),
extra_keys: vec![ String::from("alt"), String::from("meta") ],
wayland_height: 185, wayland_height: 185,
wayland_im_enable: true, wayland_im_enable: true,
}; };
@ -80,6 +82,13 @@ impl Configuration {
cfg.layout = layout.to_string(); cfg.layout = layout.to_string();
} }
let keys = yaml.get(&Yaml::String(String::from("extra_keys")));
if let Some(keys) = keys {
let keys = keys.as_vec().expect("Extra keys should be a list");
cfg.extra_keys = keys.iter().map(|y| String::from(y.as_str().unwrap())).collect();
cfg.extra_keys.sort_unstable();
}
let wl = yaml.get(&Yaml::String(String::from("wayland"))); let wl = yaml.get(&Yaml::String(String::from("wayland")));
if let Some(wl) = wl { if let Some(wl) = wl {
let wl = wl.as_hash().expect("Wayland configuration should be a YAML mapping"); let wl = wl.as_hash().expect("Wayland configuration should be a YAML mapping");
@ -108,6 +117,12 @@ impl Configuration {
&self.layout &self.layout
} }
#[inline(always)]
pub fn extra_keys(&self) -> &Vec<String>
{
&self.extra_keys
}
#[inline(always)] #[inline(always)]
pub fn wayland_height(&self) -> i32 pub fn wayland_height(&self) -> i32
{ {