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

@@ -18,7 +18,6 @@
#include <zmk/events/position_state_changed.h>
#include <zmk/events/keycode_state_changed.h>
#include <zmk/behavior.h>
#include <zmk/keymap.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
@@ -77,6 +76,7 @@ struct behavior_hold_tap_data {
// this data is specific for each hold-tap
struct active_hold_tap {
int32_t position;
uint8_t source;
uint32_t param_hold;
uint32_t param_tap;
int64_t timestamp;
@@ -250,14 +250,16 @@ static struct active_hold_tap *find_hold_tap(uint32_t position) {
return NULL;
}
static struct active_hold_tap *store_hold_tap(uint32_t position, uint32_t param_hold,
uint32_t param_tap, int64_t timestamp,
static struct active_hold_tap *store_hold_tap(uint32_t position, uint8_t source,
uint32_t param_hold, uint32_t param_tap,
int64_t timestamp,
const struct behavior_hold_tap_config *config) {
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_HELD; i++) {
if (active_hold_taps[i].position != ZMK_BHV_HOLD_TAP_POSITION_NOT_USED) {
continue;
}
active_hold_taps[i].position = position;
active_hold_taps[i].source = source;
active_hold_taps[i].status = STATUS_UNDECIDED;
active_hold_taps[i].config = config;
active_hold_taps[i].param_hold = param_hold;
@@ -400,45 +402,49 @@ static int press_hold_binding(struct active_hold_tap *hold_tap) {
struct zmk_behavior_binding_event event = {
.position = hold_tap->position,
.timestamp = hold_tap->timestamp,
.source = hold_tap->source,
};
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev,
.param1 = hold_tap->param_hold};
return behavior_keymap_binding_pressed(&binding, event);
return zmk_behavior_invoke_binding(&binding, event, true);
}
static int press_tap_binding(struct active_hold_tap *hold_tap) {
struct zmk_behavior_binding_event event = {
.position = hold_tap->position,
.timestamp = hold_tap->timestamp,
.source = hold_tap->source,
};
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev,
.param1 = hold_tap->param_tap};
store_last_hold_tapped(hold_tap);
return behavior_keymap_binding_pressed(&binding, event);
return zmk_behavior_invoke_binding(&binding, event, true);
}
static int release_hold_binding(struct active_hold_tap *hold_tap) {
struct zmk_behavior_binding_event event = {
.position = hold_tap->position,
.timestamp = hold_tap->timestamp,
.source = hold_tap->source,
};
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev,
.param1 = hold_tap->param_hold};
return behavior_keymap_binding_released(&binding, event);
return zmk_behavior_invoke_binding(&binding, event, false);
}
static int release_tap_binding(struct active_hold_tap *hold_tap) {
struct zmk_behavior_binding_event event = {
.position = hold_tap->position,
.timestamp = hold_tap->timestamp,
.source = hold_tap->source,
};
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev,
.param1 = hold_tap->param_tap};
return behavior_keymap_binding_released(&binding, event);
return zmk_behavior_invoke_binding(&binding, event, false);
}
static int press_binding(struct active_hold_tap *hold_tap) {
@@ -597,8 +603,8 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
return ZMK_BEHAVIOR_OPAQUE;
}
struct active_hold_tap *hold_tap =
store_hold_tap(event.position, binding->param1, binding->param2, event.timestamp, cfg);
struct active_hold_tap *hold_tap = store_hold_tap(event.position, event.source, binding->param1,
binding->param2, event.timestamp, cfg);
if (hold_tap == NULL) {
LOG_ERR("unable to store hold-tap info, did you press more than %d hold-taps?",
ZMK_BHV_HOLD_TAP_MAX_HELD);