diff options
| author | Teddy Wing | 2018-08-29 14:06:02 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-08-29 14:06:02 +0200 | 
| commit | d027ea9e6425fa485dd6f32d414f4ab848b48c9a (patch) | |
| tree | e524c923b4f6379fb195d154e1fb30bb956505ec | |
| parent | b8b09aa2ef1e945aaf7283de63d1d1f57585373b (diff) | |
| download | dome-key-map-d027ea9e6425fa485dd6f32d414f4ab848b48c9a.tar.bz2 | |
c_run_key_action(): Add `mode` argument
Add a nullable `mode` argument like `trigger`. Change `trigger` to make
it non-nullable again.
We can now pass a mode trigger in from FFI and handle it in our Rust
function.
| -rw-r--r-- | dome_key_map.h | 2 | ||||
| -rw-r--r-- | includer.c | 2 | ||||
| -rw-r--r-- | src/cocoa_bridge.rs | 22 | 
3 files changed, 19 insertions, 7 deletions
| diff --git a/dome_key_map.h b/dome_key_map.h index c6bf4c1..88f7abf 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -27,4 +27,4 @@ typedef struct {    size_t length;  } Trigger; -const CKeyActionResult *c_run_key_action(const Trigger *trigger); +const CKeyActionResult *c_run_key_action(Trigger trigger, const Trigger *mode); @@ -9,7 +9,7 @@ int main() {  		.buttons = buttons,  		.length = SIZE  	}; -	const CKeyActionResult *result = c_run_key_action(&trigger); +	const CKeyActionResult *result = c_run_key_action(trigger, NULL);  	printf("%s", result->action);  	return 0; diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 4d63c44..b329ae8 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -61,16 +61,28 @@ pub struct CKeyActionResult {  #[no_mangle]  pub extern "C" fn c_run_key_action( -    trigger: *const Trigger, +    trigger: Trigger, +    mode: *const Trigger,  ) -> *const CKeyActionResult {      let trigger = unsafe { -        assert!(!trigger.is_null()); -        assert!(!(*trigger).buttons.is_null()); +        assert!(!trigger.buttons.is_null()); -        slice::from_raw_parts((*trigger).buttons, (*trigger).length as usize) +        slice::from_raw_parts(trigger.buttons, trigger.length as usize)      }; -    let result = match run_key_action_for_mode(trigger, None) { +    let mode = unsafe { +        if mode.is_null() { +            None +        } else { +            assert!(!(*mode).buttons.is_null()); + +            Some( +                slice::from_raw_parts((*mode).buttons, (*mode).length as usize) +            ) +        } +    }; + +    let result = match run_key_action_for_mode(trigger, mode) {          Some(k) => {              match k.action {                  Some(a) => { | 
