refactor: Condition source props on CONFIG_ZMK_SPLIT
This commit is contained in:
parent
b249135742
commit
fb18a4d871
11 changed files with 86 additions and 34 deletions
|
|
@ -35,7 +35,9 @@ struct active_tap_dance {
|
|||
// Tap Dance Data
|
||||
int counter;
|
||||
uint32_t position;
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
uint8_t source;
|
||||
#endif
|
||||
uint32_t param1;
|
||||
uint32_t param2;
|
||||
bool is_pressed;
|
||||
|
|
@ -60,15 +62,17 @@ static struct active_tap_dance *find_tap_dance(uint32_t position) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int new_tap_dance(uint32_t position, uint8_t source,
|
||||
static int new_tap_dance(struct zmk_behavior_binding_event *event,
|
||||
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->position = event->position;
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
ref_dance->source = event->source;
|
||||
#endif
|
||||
ref_dance->config = config;
|
||||
ref_dance->release_at = 0;
|
||||
ref_dance->is_pressed = true;
|
||||
|
|
@ -111,7 +115,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,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
.source = tap_dance->source,
|
||||
#endif
|
||||
};
|
||||
return zmk_behavior_invoke_binding(&binding, event, true);
|
||||
}
|
||||
|
|
@ -122,7 +128,9 @@ 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,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
.source = tap_dance->source,
|
||||
#endif
|
||||
};
|
||||
clear_tap_dance(tap_dance);
|
||||
return zmk_behavior_invoke_binding(&binding, event, false);
|
||||
|
|
@ -135,7 +143,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, event.source, cfg, &tap_dance) == -ENOMEM) {
|
||||
if (new_tap_dance(&event, cfg, &tap_dance) == -ENOMEM) {
|
||||
LOG_ERR("Unable to create new tap dance. Insufficient space in active_tap_dances[].");
|
||||
return ZMK_BEHAVIOR_OPAQUE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue