From beea50b6c0b30b40abd292a11ded570ec50228a4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Aug 2018 21:02:51 +0200 Subject: c_run_key_action(): Change signature to take a `Trigger` Our new `Trigger` type groups together the two arguments this function used to take into a single type. --- dome_key_map.h | 7 ++++++- includer.c | 8 ++++++-- src/cocoa_bridge.rs | 7 +++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dome_key_map.h b/dome_key_map.h index 6066da0..f3c3f68 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -22,4 +22,9 @@ typedef struct { const MapKind *kind; } CKeyActionResult; -const CKeyActionResult *c_run_key_action(const HeadphoneButton *trigger, size_t length); +typedef struct { + const HeadphoneButton *buttons; + size_t length; +} Trigger; + +const CKeyActionResult *c_run_key_action(Trigger trigger); diff --git a/includer.c b/includer.c index 92a48cd..2c89064 100644 --- a/includer.c +++ b/includer.c @@ -4,8 +4,12 @@ #define SIZE 2 int main() { - HeadphoneButton trigger[SIZE] = {HeadphoneButton_Play, HeadphoneButton_Down}; - const CKeyActionResult *result = c_run_key_action(trigger, SIZE); + HeadphoneButton buttons[SIZE] = {HeadphoneButton_Play, HeadphoneButton_Down}; + Trigger trigger = { + .buttons = buttons, + .length = SIZE + }; + const CKeyActionResult *result = c_run_key_action(trigger); printf("%s", result->action); return 0; diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 12b2b62..12b0095 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -61,13 +61,12 @@ pub struct CKeyActionResult { #[no_mangle] pub extern "C" fn c_run_key_action( - trigger: *const HeadphoneButton, - length: size_t, + trigger: Trigger, ) -> *const CKeyActionResult { let trigger = unsafe { - assert!(!trigger.is_null()); + assert!(!trigger.buttons.is_null()); - slice::from_raw_parts(trigger, length as usize) + slice::from_raw_parts(trigger.buttons, trigger.length as usize) }; let result = match run_key_action(trigger) { -- cgit v1.2.3