-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On-each-release tap dance function #20255
Changes from all commits
0bf417b
6378c85
78cb4cd
3ac6107
dc0da95
c213430
29b3589
1313404
29ac6ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -95,6 +95,10 @@ static inline void process_tap_dance_action_on_each_tap(tap_dance_action_t *acti | |||||||||||
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static inline void process_tap_dance_action_on_each_release(tap_dance_action_t *action) { | ||||||||||||
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_release); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static inline void process_tap_dance_action_on_reset(tap_dance_action_t *action) { | ||||||||||||
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_reset); | ||||||||||||
del_weak_mods(action->state.weak_mods); | ||||||||||||
|
@@ -158,8 +162,12 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||||||||||
process_tap_dance_action_on_each_tap(action); | ||||||||||||
active_td = action->state.finished ? 0 : keycode; | ||||||||||||
} else { | ||||||||||||
process_tap_dance_action_on_each_release(action); | ||||||||||||
if (action->state.finished) { | ||||||||||||
process_tap_dance_action_on_reset(action); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect that the following change would be needed to fix the corner case when the
Suggested change
But I don't have time to test this just now (this would probably need another test to make sure that there are no superfluous And using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added your change and another test function that verifies the expected behavior. Let me know if there are any other cases you think should be added. |
||||||||||||
if (active_td == keycode) { | ||||||||||||
active_td = 0; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ typedef struct { | |
tap_dance_user_fn_t on_each_tap; | ||
tap_dance_user_fn_t on_dance_finished; | ||
tap_dance_user_fn_t on_reset; | ||
tap_dance_user_fn_t on_each_release; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this at the end so existing user code that uses positional initialization doesn't break. For example, the following will still compile even though only three of the four arguments are provided:
|
||
} fn; | ||
void *user_data; | ||
} tap_dance_action_t; | ||
|
@@ -56,19 +57,22 @@ typedef struct { | |
} tap_dance_dual_role_t; | ||
|
||
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ | ||
{ .fn = {tap_dance_pair_on_each_tap, tap_dance_pair_finished, tap_dance_pair_reset}, .user_data = (void *)&((tap_dance_pair_t){kc1, kc2}), } | ||
{ .fn = {tap_dance_pair_on_each_tap, tap_dance_pair_finished, tap_dance_pair_reset, NULL}, .user_data = (void *)&((tap_dance_pair_t){kc1, kc2}), } | ||
|
||
#define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) \ | ||
{ .fn = {tap_dance_dual_role_on_each_tap, tap_dance_dual_role_finished, tap_dance_dual_role_reset}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_move}), } | ||
{ .fn = {tap_dance_dual_role_on_each_tap, tap_dance_dual_role_finished, tap_dance_dual_role_reset, NULL}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_move}), } | ||
|
||
#define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \ | ||
{ .fn = {NULL, tap_dance_dual_role_finished, tap_dance_dual_role_reset}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_invert}), } | ||
{ .fn = {NULL, tap_dance_dual_role_finished, tap_dance_dual_role_reset, NULL}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_invert}), } | ||
|
||
#define ACTION_TAP_DANCE_FN(user_fn) \ | ||
{ .fn = {NULL, user_fn, NULL}, .user_data = NULL, } | ||
{ .fn = {NULL, user_fn, NULL, NULL}, .user_data = NULL, } | ||
|
||
#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \ | ||
{ .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, } | ||
{ .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, NULL}, .user_data = NULL, } | ||
|
||
#define ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(user_fn_on_each_tap, user_fn_on_each_release, user_fn_on_dance_finished, user_fn_on_dance_reset) \ | ||
{ .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, user_fn_on_each_release}, .user_data = NULL, } | ||
|
||
#define TD(n) (QK_TAP_DANCE | TD_INDEX(n)) | ||
#define TD_INDEX(code) ((code)&0xFF) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ enum { | |
CT_FLSH, | ||
CT_CLN, | ||
X_CTL, | ||
TD_RELEASE, | ||
TD_RELEASE_AND_FINISH, | ||
}; | ||
|
||
#ifdef __cplusplus | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function checks if
on_each_release
is null btw (see here)