diff options
| author | Teddy Wing | 2018-09-22 01:40:35 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-09-22 01:40:35 +0200 | 
| commit | 457b2796e6fc268074b87d36c9f9a2c25eb4b5af (patch) | |
| tree | 24b97e3ce4aeb926d1c0467c059d5751e80e244e | |
| parent | ce1eca32e2249a72692c6eb01052361d98af29c3 (diff) | |
| download | dome-key-map-457b2796e6fc268074b87d36c9f9a2c25eb4b5af.tar.bz2 | |
Add a `State` struct
The plan is to use this as an opaque pointer to be passed between the
Objective-C code and Rust code. It will contain the current mode (if in
a mode) and the parsed `MapGroup` definitions.
For now just some code inspired by the Rust FFI Omnibus
(http://jakegoulding.com/rust-ffi-omnibus/objects/) to create and free a
`State`.
| -rw-r--r-- | dome_key_map.h | 6 | ||||
| -rw-r--r-- | src/cocoa_bridge.rs | 16 | 
2 files changed, 22 insertions, 0 deletions
| diff --git a/dome_key_map.h b/dome_key_map.h index 7bd77ca..633e9b3 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -23,6 +23,8 @@ typedef enum {    MapKind_Command,  } MapKind; +typedef struct State State; +  typedef struct {    const HeadphoneButton *buttons;    size_t length; @@ -35,3 +37,7 @@ typedef struct {  } CKeyActionResult;  const CKeyActionResult *c_run_key_action(Trigger trigger, const Trigger *mode); + +void state_free(State *ptr); + +State *state_new(void); diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index e860d24..a864e13 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -92,6 +92,22 @@ pub struct CKeyActionResult {      pub in_mode: *const Trigger,  } +#[derive(Default)] +pub struct State { +    in_mode: Option<Vec<HeadphoneButton>>, +} + +#[no_mangle] +pub extern "C" fn state_new() -> *mut State { +    Box::into_raw(Box::new(State::default())) +} + +#[no_mangle] +pub extern "C" fn state_free(ptr: *mut State) { +    if ptr.is_null() { return } +    unsafe { Box::from_raw(ptr); } +} +  #[no_mangle]  pub extern "C" fn c_run_key_action(      trigger: Trigger, | 
