aboutsummaryrefslogtreecommitdiffstats
path: root/src/cocoa_bridge.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-09-01 22:18:46 +0200
committerTeddy Wing2018-09-01 22:18:46 +0200
commit4f9fd0cfa94ee4f61b47cb725c2ed7620921086d (patch)
treea08983906394b6d861e0c8682e390a79f8f169b0 /src/cocoa_bridge.rs
parent81848e3a556a11576543fddb7939e2532cb8a34d (diff)
downloaddome-key-map-4f9fd0cfa94ee4f61b47cb725c2ed7620921086d.tar.bz2
run_key_action_for_mode(): Return `KeyActionResult` for mode
When `trigger` is a mode instead of a map, return a `KeyActionResult` with the `in_mode` field set to `trigger`. The `MapKind` enum didn't really fit with the mode here. I couldn't use `MapKind::{Map,Command}` for this `KeyActionResult` because the trigger is for a mode, which is neither of those two. At first I tried to add `Mode` as an option on `MapKind`, but that would have caused problems. We'd be required to add `MapKind::Mode` as an additional match arm in the two places we match against the kind in `run_key_action_for_mode()`, and in that match arm we'd just have to log an error because a `Mode` kind should never occur in those cases. Instead of having a useless match arm that only serves to log an error, I'd much rather not allow it in the first place. Leaving `MapKind` the same allows us to keep our existing code the way it is without adding unnecessary functionality. In order to be able to declare a type of "Mode", though, I ended up creating a new type that replicates `MapKind` (since I can't just extend the enum to a new type) and adds a `Mode` option. This `ActionKind` is only used for `KeyActionResult`, and `MapKind` is used for `Map`s and `MapAction`s.
Diffstat (limited to 'src/cocoa_bridge.rs')
-rw-r--r--src/cocoa_bridge.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index 54f7904..1717b57 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -48,14 +48,21 @@ pub struct Trigger {
}
#[repr(C)]
+pub enum ActionKind {
+ Map,
+ Command,
+ Mode,
+}
+
+#[repr(C)]
pub struct KeyActionResult<'a> {
pub action: Option<CString>,
- pub kind: MapKind,
+ pub kind: ActionKind,
pub in_mode: Option<&'a [HeadphoneButton]>,
}
impl<'a> KeyActionResult<'a> {
- fn new(kind: MapKind) -> Self {
+ fn new(kind: ActionKind) -> Self {
KeyActionResult {
action: None,
kind: kind,
@@ -78,7 +85,7 @@ impl<'a> KeyActionResult<'a> {
#[repr(C)]
pub struct CKeyActionResult {
pub action: *const c_char,
- pub kind: *const MapKind,
+ pub kind: *const ActionKind,
}
#[no_mangle]
@@ -154,14 +161,14 @@ map <play><down> works!
return match map.kind {
MapKind::Map => {
Some(
- KeyActionResult::new(MapKind::Map)
+ KeyActionResult::new(ActionKind::Map)
.with_action(&map.action)
.in_mode(trigger)
)
},
MapKind::Command => {
Some(
- KeyActionResult::new(MapKind::Command)
+ KeyActionResult::new(ActionKind::Command)
.in_mode(trigger)
)
},
@@ -174,19 +181,27 @@ map <play><down> works!
return match map.kind {
MapKind::Map => {
Some(
- KeyActionResult::new(MapKind::Map)
+ KeyActionResult::new(ActionKind::Map)
.with_action(&map.action)
)
},
MapKind::Command => {
Some(
- KeyActionResult::new(MapKind::Command)
+ KeyActionResult::new(ActionKind::Command)
)
},
+ // MapKind::Mode => {
+ // TODO: Maybe make a new type just for KeyActionResult that
+ // combines regular MapKinds and Mode
+ // },
}
}
if let Some(mode) = mode {
+ return Some(
+ KeyActionResult::new(ActionKind::Mode)
+ .in_mode(trigger)
+ )
}
// match map_group.get(trigger) {