From 4b31eb9b8412e429949aca73ef475787910e4b0b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Sep 2018 14:12:56 +0200 Subject: Test mode finder Add a new `moder.c` based on `includer.c` to test getting a mode and then getting an action for a mode mapping. Doesn't completely work currently. Right now all I get is this output: $ ./moder 2 Segmentation fault: 11 Clearly I'm messing up something with the pointer in `c_run_key_action()`. Not sure what it is yet. Changed `CKeyActionResult.in_mode` to be a `Trigger` instead of a `HeadphoneButton` list. That allows us to pass it directly into the second argument of `c_run_key_action()` without converting. But maybe the pointer value isn't living long enough? Not sure what the problem is yet. --- src/cocoa_bridge.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 920ea02..15cee95 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -86,7 +86,7 @@ impl<'a> KeyActionResult<'a> { pub struct CKeyActionResult { pub action: *const c_char, pub kind: *const ActionKind, - pub in_mode: *const HeadphoneButton, + pub in_mode: *const Trigger, } #[no_mangle] @@ -120,7 +120,14 @@ pub extern "C" fn c_run_key_action( ); let in_mode = k.in_mode.map_or_else( || ptr::null(), - |m| m.as_ptr(), + |m| { + let trigger = Trigger { + buttons: m.as_ptr(), + length: m.len(), + }; + + &trigger + }, ); CKeyActionResult { @@ -149,6 +156,9 @@ pub extern "C" fn run_key_action_for_mode<'a>( let sample_maps = "map k map j map works! +mode { + map hello +} "; // Figure out how to persist this without re-parsing -- cgit v1.2.3