aboutsummaryrefslogtreecommitdiffstats
path: root/src/cocoa_bridge.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-09-02 10:59:11 +0200
committerTeddy Wing2018-09-02 10:59:11 +0200
commit69352361515b16c1ed9646b891ba61ed1781a7a7 (patch)
treef3f4bd80dfaa3b697d4bbeac7158d8b26fa9cd7d /src/cocoa_bridge.rs
parent4f9fd0cfa94ee4f61b47cb725c2ed7620921086d (diff)
downloaddome-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.
Diffstat (limited to 'src/cocoa_bridge.rs')
-rw-r--r--src/cocoa_bridge.rs28
1 files changed, 15 insertions, 13 deletions
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(),
}
}
};