aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--dome_key_map.h2
-rw-r--r--src/cocoa_bridge.rs17
-rw-r--r--src/lib.rs1
4 files changed, 21 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index dca6231..2c2176e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,6 +5,7 @@ version = "0.0.1"
[dependencies]
cocoa = "0.18.0"
combine = "3.4.0"
+libc = "0.2.43"
[build-dependencies]
cbindgen = "0.6.2"
diff --git a/dome_key_map.h b/dome_key_map.h
index 473d2f0..d128979 100644
--- a/dome_key_map.h
+++ b/dome_key_map.h
@@ -20,3 +20,5 @@ typedef struct {
Option_CString action;
MapKind kind;
} KeyActionResult;
+
+const KeyActionResult *c_run_key_action(const HeadphoneButton *trigger, size_t length);
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index d4749f0..d98701f 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -1,7 +1,9 @@
use std::ffi::CString;
+use std::slice;
use cocoa::base::nil;
use cocoa::foundation::{NSArray, NSAutoreleasePool, NSDictionary};
+use libc::size_t;
use {HeadphoneButton, MapGroup, MapKind};
@@ -45,6 +47,21 @@ pub struct KeyActionResult {
}
#[no_mangle]
+pub extern "C" fn c_run_key_action(
+ trigger: *const HeadphoneButton,
+ length: size_t,
+) -> *const KeyActionResult {
+ let trigger = unsafe {
+ assert!(!trigger.is_null());
+
+ slice::from_raw_parts(trigger, length as usize)
+ };
+
+ let result = run_key_action(trigger).unwrap();
+ &result as *const KeyActionResult
+}
+
+#[no_mangle]
pub extern "C" fn run_key_action(
trigger: &[HeadphoneButton]
) -> Option<KeyActionResult> {
diff --git a/src/lib.rs b/src/lib.rs
index db113dc..cf7dd1e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,6 +2,7 @@ extern crate cocoa;
#[macro_use]
extern crate combine;
+extern crate libc;
mod cocoa_bridge;
mod parser;