Skip to content
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

Align location of tap dance keycode #22742

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/feature_tap_dance.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {

switch (keycode) {
case TD(CT_CLN): // list all tap dance keycodes with tap-hold configurations
action = &tap_dance_actions[TD_INDEX(keycode)];
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)];
if (!record->event.pressed && action->state.count && !action->state.finished) {
tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data;
tap_code16(tap_hold->tap);
Expand Down
6 changes: 3 additions & 3 deletions quantum/process_keycode/process_tap_dance.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {

if (!active_td || keycode == active_td) return false;

action = &tap_dance_actions[TD_INDEX(active_td)];
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(active_td)];
action->state.interrupted = true;
action->state.interrupting_keycode = keycode;
process_tap_dance_action_on_dance_finished(action);
Expand All @@ -154,7 +154,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {

switch (keycode) {
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
action = &tap_dance_actions[TD_INDEX(keycode)];
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)];

action->state.pressed = record->event.pressed;
if (record->event.pressed) {
Expand Down Expand Up @@ -182,7 +182,7 @@ void tap_dance_task(void) {

if (!active_td || timer_elapsed(last_tap_time) <= GET_TAPPING_TERM(active_td, &(keyrecord_t){})) return;

action = &tap_dance_actions[TD_INDEX(active_td)];
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(active_td)];
if (!action->state.interrupted) {
process_tap_dance_action_on_dance_finished(action);
}
Expand Down
4 changes: 2 additions & 2 deletions quantum/process_keycode/process_tap_dance.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
#include "quantum_keycodes.h"

typedef struct {
uint16_t interrupting_keycode;
Expand Down Expand Up @@ -74,8 +75,7 @@ typedef struct {
#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)
#define TD_INDEX(code) QK_TAP_DANCE_GET_INDEX(code)
#define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions)

extern tap_dance_action_t tap_dance_actions[];
Expand Down
4 changes: 4 additions & 0 deletions quantum/quantum_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
#define SH_T(kc) (QK_SWAP_HANDS | ((kc)&0xFF))
#define QK_SWAP_HANDS_GET_TAP_KEYCODE(kc) ((kc)&0xFF)

// Tap dance
#define TD(i) (QK_TAP_DANCE | ((i)&0xFF))
#define QK_TAP_DANCE_GET_INDEX(kc) ((kc)&0xFF)

// MIDI aliases
#define MIDI_TONE_MIN QK_MIDI_NOTE_C_0
#define MIDI_TONE_MAX QK_MIDI_NOTE_B_5
Expand Down
2 changes: 1 addition & 1 deletion tests/tap_dance/examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {

switch (keycode) {
case TD(CT_CLN):
action = &tap_dance_actions[TD_INDEX(keycode)];
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)];
if (!record->event.pressed && action->state.count && !action->state.finished) {
tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data;
tap_code16(tap_hold->tap);
Expand Down