feat(keymap): API for retrieving label for a layer

This commit is contained in:
Pete Johanson 2020-12-29 00:19:25 -05:00
parent 74b397ab91
commit a55b1397c9
2 changed files with 18 additions and 0 deletions

View file

@ -16,5 +16,6 @@ int zmk_keymap_layer_activate(uint8_t layer);
int zmk_keymap_layer_deactivate(uint8_t layer);
int zmk_keymap_layer_toggle(uint8_t layer);
int zmk_keymap_layer_to(uint8_t layer);
const char *zmk_keymap_layer_label(uint8_t layer);
int zmk_keymap_position_state_changed(uint32_t position, bool pressed, int64_t timestamp);

View file

@ -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;