From d9956baffa5f57c5fdac03604e90470c0f0ef7d9 Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Thu, 7 Nov 2024 18:17:01 -0500 Subject: [PATCH] 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. --- src/core/config.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/config.rs b/src/core/config.rs index f2421fc..4fd5755 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -15,6 +15,7 @@ pub struct Configuration { longpress: u64, repeat: u64, layout: String, + extra_keys: Vec, wayland_height: i32, wayland_im_enable: bool, } @@ -46,6 +47,7 @@ impl Configuration { longpress: 600, repeat: 25, layout: String::from("latn_qwerty_us.xml"), + extra_keys: vec![ String::from("alt"), String::from("meta") ], wayland_height: 185, wayland_im_enable: true, }; @@ -80,6 +82,13 @@ impl Configuration { 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"))); if let Some(wl) = wl { let wl = wl.as_hash().expect("Wayland configuration should be a YAML mapping"); @@ -108,6 +117,12 @@ impl Configuration { &self.layout } + #[inline(always)] + pub fn extra_keys(&self) -> &Vec + { + &self.extra_keys + } + #[inline(always)] pub fn wayland_height(&self) -> i32 {