add xdg configs
This commit is contained in:
parent
136dad885e
commit
604d2e4134
3 changed files with 24 additions and 6 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -68,6 +68,15 @@ pub struct Configuration {
|
|||
}
|
||||
|
||||
impl Configuration {
|
||||
fn get_configuration_file() -> Result<File, Box<dyn std::error::Error>>
|
||||
{
|
||||
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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Self, Error>
|
||||
{
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue