From 4f9fd0cfa94ee4f61b47cb725c2ed7620921086d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 1 Sep 2018 22:18:46 +0200 Subject: 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. --- dome_key_map.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'dome_key_map.h') diff --git a/dome_key_map.h b/dome_key_map.h index 88f7abf..4ee30c3 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -6,6 +6,12 @@ #include #include +typedef enum { + ActionKind_Map, + ActionKind_Command, + ActionKind_Mode, +} ActionKind; + typedef enum { HeadphoneButton_Play, HeadphoneButton_Up, @@ -19,7 +25,7 @@ typedef enum { typedef struct { const char *action; - const MapKind *kind; + const ActionKind *kind; } CKeyActionResult; typedef struct { -- cgit v1.2.3