feat(split): Make locality work nested behavior invocations

Co-authored-by: Tokazio <tokazio@hotmail.com>
This commit is contained in:
Cem Aksoylar 2023-01-17 19:05:04 +01:00 committed by Pete Johanson
parent 11f600d9e5
commit 9e36ebd525
13 changed files with 146 additions and 105 deletions

View file

@ -35,6 +35,7 @@ struct active_tap_dance {
// Tap Dance Data
int counter;
uint32_t position;
uint8_t source;
uint32_t param1;
uint32_t param2;
bool is_pressed;
@ -59,13 +60,15 @@ static struct active_tap_dance *find_tap_dance(uint32_t position) {
return NULL;
}
static int new_tap_dance(uint32_t position, const struct behavior_tap_dance_config *config,
static int new_tap_dance(uint32_t position, uint8_t source,
const struct behavior_tap_dance_config *config,
struct active_tap_dance **tap_dance) {
for (int i = 0; i < ZMK_BHV_TAP_DANCE_MAX_HELD; i++) {
struct active_tap_dance *const ref_dance = &active_tap_dances[i];
if (ref_dance->position == ZMK_BHV_TAP_DANCE_POSITION_FREE) {
ref_dance->counter = 0;
ref_dance->position = position;
ref_dance->source = source;
ref_dance->config = config;
ref_dance->release_at = 0;
ref_dance->is_pressed = true;
@ -108,8 +111,9 @@ static inline int press_tap_dance_behavior(struct active_tap_dance *tap_dance, i
struct zmk_behavior_binding_event event = {
.position = tap_dance->position,
.timestamp = timestamp,
.source = tap_dance->source,
};
return behavior_keymap_binding_pressed(&binding, event);
return zmk_behavior_invoke_binding(&binding, event, true);
}
static inline int release_tap_dance_behavior(struct active_tap_dance *tap_dance,
@ -118,9 +122,10 @@ static inline int release_tap_dance_behavior(struct active_tap_dance *tap_dance,
struct zmk_behavior_binding_event event = {
.position = tap_dance->position,
.timestamp = timestamp,
.source = tap_dance->source,
};
clear_tap_dance(tap_dance);
return behavior_keymap_binding_released(&binding, event);
return zmk_behavior_invoke_binding(&binding, event, false);
}
static int on_tap_dance_binding_pressed(struct zmk_behavior_binding *binding,
@ -130,7 +135,7 @@ static int on_tap_dance_binding_pressed(struct zmk_behavior_binding *binding,
struct active_tap_dance *tap_dance;
tap_dance = find_tap_dance(event.position);
if (tap_dance == NULL) {
if (new_tap_dance(event.position, cfg, &tap_dance) == -ENOMEM) {
if (new_tap_dance(event.position, event.source, cfg, &tap_dance) == -ENOMEM) {
LOG_ERR("Unable to create new tap dance. Insufficient space in active_tap_dances[].");
return ZMK_BEHAVIOR_OPAQUE;
}
@ -261,4 +266,4 @@ static int behavior_tap_dance_init(const struct device *dev) {
DT_INST_FOREACH_STATUS_OKAY(KP_INST)
#endif
#endif