summaryrefslogtreecommitdiff
path: root/app/src/keymap.c
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2021-01-20 11:00:38 -0500
committerPete Johanson <peter@peterjohanson.com>2021-02-09 01:27:50 -0500
commite6f168d6dfe0a27407a7229a549f2dbab37b0f2d (patch)
treed3a8a7c27e52f9a91f583cd34d4a81fca2f85160 /app/src/keymap.c
parentbb2c478af915616640d78ae9ba984fbf1f817185 (diff)
refactor(behaviors): Convert state dependent params.
* Allow each behavior to map a relative binding, e.g. "toggle", to an absolute one, e.g. "on", before being invoked.
Diffstat (limited to 'app/src/keymap.c')
-rw-r--r--app/src/keymap.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/app/src/keymap.c b/app/src/keymap.c
index 75ec6bf..1643f64 100644
--- a/app/src/keymap.c
+++ b/app/src/keymap.c
@@ -153,7 +153,9 @@ const char *zmk_keymap_layer_label(uint8_t 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];
+ // We want to make a copy of this, since it may be converted from
+ // relative to absolute before being invoked
+ struct zmk_behavior_binding binding = zmk_keymap[layer][position];
const struct device *behavior;
struct zmk_behavior_binding_event event = {
.layer = layer,
@@ -162,19 +164,25 @@ int zmk_keymap_apply_position_state(int layer, uint32_t position, bool pressed,
};
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position,
- log_strdup(binding->behavior_dev));
+ log_strdup(binding.behavior_dev));
- behavior = device_get_binding(binding->behavior_dev);
+ behavior = device_get_binding(binding.behavior_dev);
if (!behavior) {
LOG_DBG("No behavior assigned to %d on layer %d", position, layer);
return 1;
}
+ int err = behavior_keymap_binding_convert_central_state_dependent_params(&binding, event);
+ if (err) {
+ LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err);
+ return err;
+ }
+
if (pressed) {
- return behavior_keymap_binding_pressed(binding, event);
+ return behavior_keymap_binding_pressed(&binding, event);
} else {
- return behavior_keymap_binding_released(binding, event);
+ return behavior_keymap_binding_released(&binding, event);
}
}