From 604d2e413459b5410458a58b868def84e7ad9af7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 6 Nov 2025 20:07:16 +0100 Subject: [PATCH] add xdg configs --- Cargo.toml | 1 + src/core/config.rs | 11 ++++++++++- src/core/layout.rs | 18 +++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 58e207b..087c9c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ libc = "0.2" linux-raw-sys = { version = "0.9", features = ["ioctl"] } memmap2 = "0.9" polling = "3" +xdg = "2.5.2" reis = "0.4" rgb = "0.8" signal-hook = "0.3" diff --git a/src/core/config.rs b/src/core/config.rs index 2e04d17..e9c66c5 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -68,6 +68,15 @@ pub struct Configuration { } impl Configuration { + fn get_configuration_file() -> Result> + { + let xdg_dirs = xdg::BaseDirectories::new()?; + let config_file = xdg_dirs.find_config_file("unfettered-keyboard.yaml") + .ok_or(std::io::Error::new(std::io::ErrorKind::NotFound, "Config file not found"))?; + println!("test{:?}",config_file); + Ok(File::open(config_file)?) + } + fn load_evfb(&mut self, yaml: &Hash) { let height = yaml.get(&Yaml::String(String::from("height"))); @@ -154,7 +163,7 @@ impl Configuration { colors: KeyboardColors::default(), }; - if let Ok(file) = File::open("/etc/unfettered-keyboard.yaml") { + if let Ok(file) = Self::get_configuration_file() { let yaml = YamlDecoder::read(file).decode()?; let yaml = yaml[0].as_hash().expect("Top-level configuration should be a YAML mapping"); diff --git a/src/core/layout.rs b/src/core/layout.rs index 57238a3..ee964df 100644 --- a/src/core/layout.rs +++ b/src/core/layout.rs @@ -19,6 +19,7 @@ use std::os::raw::c_char; use std::os::raw::c_void; use std::path::Path; use std::ptr; +use xdg::BaseDirectories; use xkeysym::Keysym; unsafe extern "C" fn start_elem(data: *mut c_void, @@ -725,18 +726,25 @@ impl Layout { pub fn load(cfg: &Configuration) -> Result { let extra_keys = cfg.extra_keys(); - let dir = Path::new("/usr/share/unfettered-keyboard/layouts"); - let path = dir.join(cfg.layout()); + let base_dirs = BaseDirectories::with_prefix("unfettered-keyboard/layouts")?; + println!("{:?}",base_dirs); + + let path = base_dirs.find_config_file(cfg.layout()) + .ok_or(Error::new(ErrorKind::NotFound, "Main layout file not found"))?; + let main_layout = LayoutLoader::load(path, extra_keys)?; - let path = dir.join("numeric.xml"); + let path = base_dirs.find_config_file("numeric.xml") + .ok_or(Error::new(ErrorKind::NotFound, "Numeric layout file not found"))?; let numeric = LayoutLoader::load(path, extra_keys)?; - let path = dir.join("greekmath.xml"); + let path = base_dirs.find_config_file("greekmath.xml") + .ok_or(Error::new(ErrorKind::NotFound, "Greekmath layout file not found"))?; let greekmath = LayoutLoader::load(path, extra_keys)?; - let path = dir.join("bottom_row.xml"); + let path = base_dirs.find_config_file("bottom_row.xml") + .ok_or(Error::new(ErrorKind::NotFound, "Bottom row layout file not found"))?; let bottom_row = LayoutLoader::load(path, extra_keys)?; let mut layout = Layout {