fix NULL typecheck and add documentation note about tapping-term

This commit is contained in:
jmding@gmail.com 2021-09-13 02:20:17 +00:00
parent 6edeefa5aa
commit 67db38efb4

View file

@ -361,8 +361,10 @@ static int release_binding(struct active_hold_tap *hold_tap) {
return behavior_keymap_binding_released(&binding, event); return behavior_keymap_binding_released(&binding, event);
} }
static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_moment decision_moment, static void
int32_t other_key_down_position) { decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_moment decision_moment,
int32_t other_key_down_position // use -1 if decision_moment != HT_OTHER_KEY_DOWN
) {
if (hold_tap->status != STATUS_UNDECIDED) { if (hold_tap->status != STATUS_UNDECIDED) {
return; return;
} }
@ -466,7 +468,7 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
undecided_hold_tap = hold_tap; undecided_hold_tap = hold_tap;
if (is_quick_tap(hold_tap)) { if (is_quick_tap(hold_tap)) {
decide_hold_tap(hold_tap, HT_QUICK_TAP, NULL); decide_hold_tap(hold_tap, HT_QUICK_TAP, -1);
} }
// if this behavior was queued we have to adjust the timer to only // if this behavior was queued we have to adjust the timer to only
@ -489,10 +491,10 @@ static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding,
// We insert a timer event before the TH_KEY_UP event to verify. // We insert a timer event before the TH_KEY_UP event to verify.
int work_cancel_result = k_delayed_work_cancel(&hold_tap->work); int work_cancel_result = k_delayed_work_cancel(&hold_tap->work);
if (event.timestamp > (hold_tap->timestamp + hold_tap->config->tapping_term_ms)) { if (event.timestamp > (hold_tap->timestamp + hold_tap->config->tapping_term_ms)) {
decide_hold_tap(hold_tap, HT_TIMER_EVENT, NULL); decide_hold_tap(hold_tap, HT_TIMER_EVENT, -1);
} }
decide_hold_tap(hold_tap, HT_KEY_UP, NULL); decide_hold_tap(hold_tap, HT_KEY_UP, -1);
decide_retro_tap(hold_tap); decide_retro_tap(hold_tap);
release_binding(hold_tap); release_binding(hold_tap);
@ -539,7 +541,7 @@ static int position_state_changed_listener(const zmk_event_t *eh) {
// have run out. // have run out.
if (ev->timestamp > if (ev->timestamp >
(undecided_hold_tap->timestamp + undecided_hold_tap->config->tapping_term_ms)) { (undecided_hold_tap->timestamp + undecided_hold_tap->config->tapping_term_ms)) {
decide_hold_tap(undecided_hold_tap, HT_TIMER_EVENT, NULL); decide_hold_tap(undecided_hold_tap, HT_TIMER_EVENT, -1);
} }
if (!ev->state && find_captured_keydown_event(ev->position) == NULL) { if (!ev->state && find_captured_keydown_event(ev->position) == NULL) {
@ -554,7 +556,7 @@ static int position_state_changed_listener(const zmk_event_t *eh) {
ev->state ? "down" : "up"); ev->state ? "down" : "up");
capture_event(eh); capture_event(eh);
decide_hold_tap(undecided_hold_tap, ev->state ? HT_OTHER_KEY_DOWN : HT_OTHER_KEY_UP, decide_hold_tap(undecided_hold_tap, ev->state ? HT_OTHER_KEY_DOWN : HT_OTHER_KEY_UP,
ev->state ? ev->position : NULL); ev->state ? ev->position : -1);
return ZMK_EV_EVENT_CAPTURED; return ZMK_EV_EVENT_CAPTURED;
} }
@ -600,7 +602,7 @@ void behavior_hold_tap_timer_work_handler(struct k_work *item) {
if (hold_tap->work_is_cancelled) { if (hold_tap->work_is_cancelled) {
clear_hold_tap(hold_tap); clear_hold_tap(hold_tap);
} else { } else {
decide_hold_tap(hold_tap, HT_TIMER_EVENT, NULL); decide_hold_tap(hold_tap, HT_TIMER_EVENT, -1);
} }
} }