diff options
| -rw-r--r-- | dome_key_map.h | 6 | ||||
| -rw-r--r-- | src/cocoa_bridge.rs | 31 | 
2 files changed, 37 insertions, 0 deletions
| diff --git a/dome_key_map.h b/dome_key_map.h index e3dcf60..39ba298 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -17,6 +17,8 @@ typedef enum {    MapKind_Command,  } MapKind; +typedef struct Config Config; +  typedef struct State State;  typedef struct { @@ -26,8 +28,12 @@ typedef struct {  void c_run_key_action(State *state, Trigger trigger, const Trigger *mode); +void config_free(Config *ptr); +  void logger_init(void); +const Config *parse_args(const char *args, size_t length); +  void state_free(State *ptr);  void state_load_map_group(State *ptr); diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 1b07ed0..f572c37 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -14,6 +14,7 @@ use stderrlog;  use xdg;  use {Action, HeadphoneButton, MapAction, MapGroup, MapKind}; +use config::{self, Config};  #[repr(C)]  struct renameMeMapGroup { @@ -297,6 +298,36 @@ fn run_action(map_action: &MapAction) {  // fn run_command(command: Action) -> Result {  // } +#[no_mangle] +pub extern "C" fn parse_args( +    args: *const c_char, +    length: size_t, +) -> *const Config { +    let args = unsafe { +        assert!(!args.is_null()); + +        let args = slice::from_raw_parts(args, length as usize); + +        args +            .iter() +            .map(|s| +                CStr::from_ptr(s) +                    .to_string_lossy() +                    .into_owned()) +            .collect::<Vec<String>>() +    }; + +    let config = config::parse_args(&args); + +    Box::into_raw(Box::new(config)) as *const Config +} + +#[no_mangle] +pub extern "C" fn config_free(ptr: *mut Config) { +    if ptr.is_null() { return } +    unsafe { Box::from_raw(ptr); } +} +  mod tests {      use super::*; | 
