diff --git a/Cargo.lock b/Cargo.lock index 526f14c..928f53e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,12 @@ version = "0.2.111" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e167738f1866a7ec625567bae89ca0d44477232a4f7c52b1c7f2adc2c98804f" +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + [[package]] name = "memoffset" version = "0.6.5" @@ -110,4 +116,14 @@ version = "0.1.0" dependencies = [ "evdev", "libc", + "yaml-rust", +] + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", ] diff --git a/Cargo.toml b/Cargo.toml index 7045724..9b954e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] evdev = "0.11.3" libc = "0.2" +yaml-rust = "0.4" diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..e76f590 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,24 @@ +use std::error::Error; +use std::fs; + +pub fn load_config(filename: &str) -> Result> { + let yaml = fs::read_to_string(&filename).unwrap(); + println!("{}", yaml.len()); + return Ok(Config { modmap: vec![], keymap: vec![] }) +} + +#[derive(Debug)] +pub struct Config { + pub modmap: Vec, + pub keymap: Vec, +} + +#[derive(Debug)] +pub struct Modmap { + // TODO +} + +#[derive(Debug)] +pub struct Keymap { + // TODO +} diff --git a/src/main.rs b/src/main.rs index 7ea6fc9..7d0bc37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,13 @@ use evdev::{Device, EventType}; use std::error::Error; +use std::env; +use std::process::exit; mod input; mod output; mod select; mod transform; +mod config; fn event_loop(input_device: &mut Device) -> Result<(), Box> { let mut output_device = output::build_device(input_device).unwrap(); @@ -24,6 +27,22 @@ fn event_loop(input_device: &mut Device) -> Result<(), Box> { } fn main() -> Result<(), Box> { + let filename = match env::args().nth(1) { + Some(filename) => filename, + None => { + println!("Usage: xremap "); + exit(1); + }, + }; + let config = match config::load_config(&filename) { + Ok(config) => config, + Err(e) => { + println!("Failed to load config '{}': {}", filename, e); + exit(1); + }, + }; + println!("{:?}", config); + let mut device = input::select_device(); device.grab()?; event_loop(&mut device)?;