From 1c17300098dc23ade1e4e4c10dc819ea762dabe7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 24 Aug 2018 09:30:59 +0200 Subject: cocoa_bridge: Idea for black box map run function New `run_key_action()` will be called from Objective C. It will: * Get the action for a `Map` mapping and return it, so that the corresponding keys can be pressed in Cocoa/Carbon * Run a `Command` mapping * Somehow manage mode scoping in conjunction with the Objective C side The new `KeyActionResult` allows us to tell Objective C what type of action should be run (`Map`, `Command`, or `Mode`), along with additional information (for now just the action keys in the case of a `Map` mapping). The question is how to hold on to state, keeping the parsed mappings in memory on the Rust side when called over FFI. --- src/cocoa_bridge.rs | 17 ++++++++++++++++- src/lib.rs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 3ddacc9..d57e5ee 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -1,7 +1,7 @@ use cocoa::base::nil; use cocoa::foundation::{NSArray, NSAutoreleasePool, NSDictionary}; -use MapGroup; +use {HeadphoneButton, MapGroup, MapKind}; #[repr(C)] struct renameMeMapGroup { @@ -36,6 +36,21 @@ map j"; // or run command (from Rust?) // Somehow: switch mode inside Rust +#[repr(C)] +pub struct KeyActionResult<'a> { + pub action: Option<&'a [char]>, + pub kind: MapKind, +} + +pub extern "C" fn run_key_action( + trigger: &[HeadphoneButton] +) -> KeyActionResult { + KeyActionResult { + action: None, + kind: MapKind::Map, + } +} + mod tests { use super::*; diff --git a/src/lib.rs b/src/lib.rs index e6260ed..7fb0b92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,4 +6,4 @@ extern crate combine; mod cocoa_bridge; mod parser; -use parser::MapGroup; +use parser::{HeadphoneButton, MapGroup, MapKind}; -- cgit v1.2.3