aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-08-24 15:35:04 +0200
committerTeddy Wing2018-08-24 15:35:04 +0200
commit8fdb86c6c8dbf0adfa2d9af9e756843eb3622a8a (patch)
treedbb96fadd7fc96f5a740c1f0e85b6fbf0acbb2b4
parent1c17300098dc23ade1e4e4c10dc819ea762dabe7 (diff)
downloaddome-key-map-8fdb86c6c8dbf0adfa2d9af9e756843eb3622a8a.tar.bz2
run_key_action(): Approach for handling actions for different MapKinds
Work out the essential body of the function, which necessitates looking inside a `MapGroup` and finding a `MapAction` corresponding to the `Trigger` given in the function argument. The function will then perform whatever action it can and return a `KeyActionResult` struct, allowing callers to pick up the baton.
-rw-r--r--src/cocoa_bridge.rs50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index d57e5ee..97f741f 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -44,11 +44,53 @@ pub struct KeyActionResult<'a> {
pub extern "C" fn run_key_action(
trigger: &[HeadphoneButton]
-) -> KeyActionResult {
- KeyActionResult {
- action: None,
- kind: MapKind::Map,
+) -> Option<KeyActionResult> {
+ let sample_maps = "map <up> k
+map <down> j";
+
+ // Figure out how to persist this without re-parsing
+ let map_group = MapGroup::parse(sample_maps).unwrap();
+
+ let map = map_group.maps.get(trigger);
+ let mode = map_group.modes.get(trigger);
+
+ if let Some(map) = map {
+ return match map.kind {
+ MapKind::Map => {
+ Some(KeyActionResult {
+ action: None, //Some(m.action.as_str()),
+ kind: MapKind::Map,
+ })
+ },
+ MapKind::Command => {
+ Some(KeyActionResult {
+ action: None,
+ kind: MapKind::Command,
+ })
+ },
+ }
}
+
+ if let Some(mode) = mode {
+ }
+
+ // match map_group.get(trigger) {
+ // Some(map_action) => {
+ // Some(KeyActionResult {
+ // action: map_action.action,
+ // kind: MapKind::Map,
+ // })
+ // },
+ // None => {
+ // // TODO: Figure out how to error
+ // None
+ // },
+ // }
+
+ None
+}
+
+fn run_command(command: Action) -> Result {
}