diff options
author | Pete Johanson <[email protected]> | 2020-12-29 00:19:25 -0500 |
---|---|---|
committer | Pete Johanson <[email protected]> | 2021-01-04 13:02:38 -0500 |
commit | a55b1397c9558cead989dfc5920b162f7c8b4c8b (patch) | |
tree | 1bb0fa6086ea8e8f76d330549c9028bac3850268 /app/src/keymap.c | |
parent | 74b397ab9136ba23b96e1fd8120bd7e32a1944af (diff) | |
download | zmk-a55b1397c9558cead989dfc5920b162f7c8b4c8b.tar.gz zmk-a55b1397c9558cead989dfc5920b162f7c8b4c8b.zip |
feat(keymap): API for retrieving label for a layer
Diffstat (limited to 'app/src/keymap.c')
-rw-r--r-- | app/src/keymap.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/src/keymap.c b/app/src/keymap.c index 786a177364..322a936976 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -59,6 +59,8 @@ static uint8_t _zmk_keymap_layer_default = 0; #endif /* ZMK_KEYMAP_HAS_SENSORS */ +#define LAYER_LABEL(node) COND_CODE_0(DT_NODE_HAS_PROP(node, label), (NULL), (DT_LABEL(node))), + // State // When a behavior handles a key position "down" event, we record the layer state @@ -69,6 +71,9 @@ static uint32_t zmk_keymap_active_behavior_layer[ZMK_KEYMAP_LEN]; static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = { DT_INST_FOREACH_CHILD(0, TRANSFORMED_LAYER)}; +static const char *zmk_keymap_layer_names[ZMK_KEYMAP_LAYERS_LEN] = { + DT_INST_FOREACH_CHILD(0, LAYER_LABEL)}; + #if ZMK_KEYMAP_HAS_SENSORS static struct zmk_behavior_binding zmk_sensor_keymap[ZMK_KEYMAP_LAYERS_LEN] @@ -143,6 +148,18 @@ int zmk_keymap_layer_to(uint8_t layer) { return 0; } +bool is_active_layer(uint8_t layer, zmk_keymap_layers_state_t layer_state) { + return (layer_state & BIT(layer)) == BIT(layer) || layer == _zmk_keymap_layer_default; +} + +const char *zmk_keymap_layer_label(uint8_t layer) { + if (layer >= ZMK_KEYMAP_LAYERS_LEN) { + return NULL; + } + + return zmk_keymap_layer_names[layer]; +} + int zmk_keymap_apply_position_state(int layer, uint32_t position, bool pressed, int64_t timestamp) { struct zmk_behavior_binding *binding = &zmk_keymap[layer][position]; const struct device *behavior; |