diff options
| author | Teddy Wing | 2018-08-24 09:30:59 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-08-24 09:36:00 +0200 |
| commit | 1c17300098dc23ade1e4e4c10dc819ea762dabe7 (patch) | |
| tree | 08a636683011d9b9530d77b879adc745c9f01daf | |
| parent | 691250a8334b21f96f7252c07122ff2ae4fe9822 (diff) | |
| download | dome-key-map-1c17300098dc23ade1e4e4c10dc819ea762dabe7.tar.bz2 | |
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.
| -rw-r--r-- | src/cocoa_bridge.rs | 17 | ||||
| -rw-r--r-- | src/lib.rs | 2 |
2 files changed, 17 insertions, 2 deletions
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 <down> 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::*; @@ -6,4 +6,4 @@ extern crate combine; mod cocoa_bridge; mod parser; -use parser::MapGroup; +use parser::{HeadphoneButton, MapGroup, MapKind}; |
