diff options
| author | Teddy Wing | 2018-09-02 10:59:11 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-09-02 10:59:11 +0200 |
| commit | 69352361515b16c1ed9646b891ba61ed1781a7a7 (patch) | |
| tree | f3f4bd80dfaa3b697d4bbeac7158d8b26fa9cd7d | |
| parent | 4f9fd0cfa94ee4f61b47cb725c2ed7620921086d (diff) | |
| download | dome-key-map-69352361515b16c1ed9646b891ba61ed1781a7a7.tar.bz2 | |
Add `in_mode` to `CKeyActionResult`
Add a new field for `in_mode` to the result struct. Return it if
`run_key_action_for_mode()` gives us a `Some` value for it. Removed the
`match` on `action` now that we have a second `Option` type.
| -rw-r--r-- | dome_key_map.h | 1 | ||||
| -rw-r--r-- | src/cocoa_bridge.rs | 28 |
2 files changed, 16 insertions, 13 deletions
diff --git a/dome_key_map.h b/dome_key_map.h index 4ee30c3..76b5f1c 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -26,6 +26,7 @@ typedef enum { typedef struct { const char *action; const ActionKind *kind; + const HeadphoneButton *in_mode; } CKeyActionResult; typedef struct { diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 1717b57..920ea02 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -86,6 +86,7 @@ impl<'a> KeyActionResult<'a> { pub struct CKeyActionResult { pub action: *const c_char, pub kind: *const ActionKind, + pub in_mode: *const HeadphoneButton, } #[no_mangle] @@ -113,25 +114,26 @@ pub extern "C" fn c_run_key_action( let result = match run_key_action_for_mode(trigger, mode) { Some(k) => { - match k.action { - Some(a) => { - CKeyActionResult { - action: a.into_raw(), // memory leak, must be freed from Rust - kind: &k.kind, - } - }, - None => { - CKeyActionResult { - action: ptr::null(), - kind: &k.kind, - } - }, + let action = k.action.map_or_else( + || ptr::null(), + |a| a.into_raw(), + ); + let in_mode = k.in_mode.map_or_else( + || ptr::null(), + |m| m.as_ptr(), + ); + + CKeyActionResult { + action: action, // memory leak, must be freed from Rust + kind: &k.kind, + in_mode: in_mode, } }, None => { CKeyActionResult { action: ptr::null(), kind: ptr::null(), + in_mode: ptr::null(), } } }; |
