Fix bug where keymap behavior params were modified by invocation
This commit is contained in:
parent
9ccf174dda
commit
950c2d48d7
2 changed files with 17 additions and 15 deletions
|
@ -28,7 +28,7 @@ const char *zmk_keymap_layer_name(uint8_t layer);
|
||||||
int zmk_keymap_position_state_changed(uint8_t source, uint32_t position, bool pressed,
|
int zmk_keymap_position_state_changed(uint8_t source, uint32_t position, bool pressed,
|
||||||
int64_t timestamp);
|
int64_t timestamp);
|
||||||
|
|
||||||
int zmk_invoke_behavior_binding(struct zmk_behavior_binding *binding,
|
int zmk_invoke_behavior_binding(const struct zmk_behavior_binding *src_binding,
|
||||||
struct zmk_behavior_binding_event event, bool pressed);
|
struct zmk_behavior_binding_event event, bool pressed);
|
||||||
|
|
||||||
#define ZMK_KEYMAP_EXTRACT_BINDING(idx, drv_inst) \
|
#define ZMK_KEYMAP_EXTRACT_BINDING(idx, drv_inst) \
|
||||||
|
|
|
@ -174,9 +174,7 @@ int invoke_locally(struct zmk_behavior_binding *binding, struct zmk_behavior_bin
|
||||||
|
|
||||||
int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position, bool pressed,
|
int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position, bool pressed,
|
||||||
int64_t timestamp) {
|
int64_t timestamp) {
|
||||||
// We want to make a copy of this, since it may be converted from
|
struct zmk_behavior_binding *binding = &zmk_keymap[layer][position];
|
||||||
// relative to absolute before being invoked
|
|
||||||
struct zmk_behavior_binding binding = zmk_keymap[layer][position];
|
|
||||||
struct zmk_behavior_binding_event event = {
|
struct zmk_behavior_binding_event event = {
|
||||||
.layer = layer,
|
.layer = layer,
|
||||||
.position = position,
|
.position = position,
|
||||||
|
@ -184,21 +182,25 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
||||||
.source = source,
|
.source = source,
|
||||||
};
|
};
|
||||||
|
|
||||||
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position, binding.behavior_dev);
|
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position, binding->behavior_dev);
|
||||||
|
|
||||||
return zmk_invoke_behavior_binding(&binding, event, pressed);
|
return zmk_invoke_behavior_binding(binding, event, pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmk_invoke_behavior_binding(struct zmk_behavior_binding *binding,
|
int zmk_invoke_behavior_binding(const struct zmk_behavior_binding *src_binding,
|
||||||
struct zmk_behavior_binding_event event, bool pressed) {
|
struct zmk_behavior_binding_event event, bool pressed) {
|
||||||
const struct device *behavior = zmk_behavior_get_binding(binding->behavior_dev);
|
// 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 = *src_binding;
|
||||||
|
|
||||||
|
const struct device *behavior = zmk_behavior_get_binding(binding.behavior_dev);
|
||||||
|
|
||||||
if (!behavior) {
|
if (!behavior) {
|
||||||
LOG_WRN("No behavior assigned to %d on layer %d", event.position, event.layer);
|
LOG_WRN("No behavior assigned to %d on layer %d", event.position, event.layer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = behavior_keymap_binding_convert_central_state_dependent_params(binding, event);
|
int err = behavior_keymap_binding_convert_central_state_dependent_params(&binding, event);
|
||||||
if (err) {
|
if (err) {
|
||||||
LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err);
|
LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err);
|
||||||
return err;
|
return err;
|
||||||
|
@ -213,24 +215,24 @@ int zmk_invoke_behavior_binding(struct zmk_behavior_binding *binding,
|
||||||
|
|
||||||
switch (locality) {
|
switch (locality) {
|
||||||
case BEHAVIOR_LOCALITY_CENTRAL:
|
case BEHAVIOR_LOCALITY_CENTRAL:
|
||||||
return invoke_locally(binding, event, pressed);
|
return invoke_locally(&binding, event, pressed);
|
||||||
case BEHAVIOR_LOCALITY_EVENT_SOURCE:
|
case BEHAVIOR_LOCALITY_EVENT_SOURCE:
|
||||||
#if ZMK_BLE_IS_CENTRAL
|
#if ZMK_BLE_IS_CENTRAL
|
||||||
if (event.source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
|
if (event.source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
|
||||||
return invoke_locally(binding, event, pressed);
|
return invoke_locally(&binding, event, pressed);
|
||||||
} else {
|
} else {
|
||||||
return zmk_split_bt_invoke_behavior(event.source, binding, event, pressed);
|
return zmk_split_bt_invoke_behavior(event.source, &binding, event, pressed);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return invoke_locally(binding, event, pressed);
|
return invoke_locally(&binding, event, pressed);
|
||||||
#endif
|
#endif
|
||||||
case BEHAVIOR_LOCALITY_GLOBAL:
|
case BEHAVIOR_LOCALITY_GLOBAL:
|
||||||
#if ZMK_BLE_IS_CENTRAL
|
#if ZMK_BLE_IS_CENTRAL
|
||||||
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
|
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
|
||||||
zmk_split_bt_invoke_behavior(i, binding, event, pressed);
|
zmk_split_bt_invoke_behavior(i, &binding, event, pressed);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return invoke_locally(binding, event, pressed);
|
return invoke_locally(&binding, event, pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
|
Loading…
Add table
Reference in a new issue