diff options
author | Drashna Jaelre <drashna@live.com> | 2019-09-21 11:22:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-21 11:22:27 -0700 |
commit | f069e9fc09859baf03d940b6db47e95c50a24936 (patch) | |
tree | 429cd294d22c0a9af6965af68f047e9482fc0cef | |
parent | 63a0b1241d204873cd5156a959e913c602b0c386 (diff) | |
download | qmk_firmware-f069e9fc09859baf03d940b6db47e95c50a24936.tar.gz qmk_firmware-f069e9fc09859baf03d940b6db47e95c50a24936.zip |
Generalize Tap Dance Layer functions (#6629)
* made tapdance dual_role general
* updated original dual_role functionality
* added toggling layer example
* Fix dual role and add alias
* Update docs about new layer tap dances
* Fix up based on feedback
-rw-r--r-- | .vscode/settings.json | 12 | ||||
-rw-r--r-- | docs/feature_tap_dance.md | 4 | ||||
-rw-r--r-- | quantum/process_keycode/process_tap_dance.c | 2 | ||||
-rw-r--r-- | quantum/process_keycode/process_tap_dance.h | 10 |
4 files changed, 20 insertions, 8 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index ba5b56aa4..e5089a55b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json | |||
@@ -8,10 +8,12 @@ | |||
8 | "**/*.hex": true | 8 | "**/*.hex": true |
9 | }, | 9 | }, |
10 | "files.associations": { | 10 | "files.associations": { |
11 | "*.h": "c", | 11 | "*.h": "c", |
12 | "*.c": "c", | 12 | "*.c": "c", |
13 | "*.cpp": "cpp", | 13 | "*.cpp": "cpp", |
14 | "*.hpp": "cpp", | 14 | "*.hpp": "cpp", |
15 | "xstddef": "c" | 15 | "xstddef": "c", |
16 | "type_traits": "c", | ||
17 | "utility": "c" | ||
16 | } | 18 | } |
17 | } | 19 | } |
diff --git a/docs/feature_tap_dance.md b/docs/feature_tap_dance.md index 73e0471a0..e381c2af0 100644 --- a/docs/feature_tap_dance.md +++ b/docs/feature_tap_dance.md | |||
@@ -30,7 +30,9 @@ Next, you will want to define some tap-dance keys, which is easiest to do with t | |||
30 | After this, you'll want to use the `tap_dance_actions` array to specify what actions shall be taken when a tap-dance key is in action. Currently, there are five possible options: | 30 | After this, you'll want to use the `tap_dance_actions` array to specify what actions shall be taken when a tap-dance key is in action. Currently, there are five possible options: |
31 | 31 | ||
32 | * `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise. When the key is held, the appropriate keycode is registered: `kc1` when pressed and held, `kc2` when tapped once, then pressed and held. | 32 | * `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise. When the key is held, the appropriate keycode is registered: `kc1` when pressed and held, `kc2` when tapped once, then pressed and held. |
33 | * `ACTION_TAP_DANCE_DUAL_ROLE(kc, layer)`: Sends the `kc` keycode when tapped once, or moves to `layer`. (this functions like the `TO` layer keycode). | 33 | * `ACTION_TAP_DANCE_LAYER_MOVE(kc, layer)`: Sends the `kc` keycode when tapped once, or moves to `layer`. (this functions like the `TO` layer keycode). |
34 | * This is the same as `ACTION_TAP_DANCE_DUAL_ROLE`, but renamed to something that is clearer about its functionality. Both names will work. | ||
35 | * `ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer)`: Sends the `kc` keycode when tapped once, or toggles the state of `layer`. (this functions like the `TG` layer keycode). | ||
34 | * `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the final tap count of the tap dance action. | 36 | * `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the final tap count of the tap dance action. |
35 | * `ACTION_TAP_DANCE_FN_ADVANCED(on_each_tap_fn, on_dance_finished_fn, on_dance_reset_fn)`: Calls the first specified function - defined in the user keymap - on every tap, the second function when the dance action finishes (like the previous option), and the last function when the tap dance action resets. | 37 | * `ACTION_TAP_DANCE_FN_ADVANCED(on_each_tap_fn, on_dance_finished_fn, on_dance_reset_fn)`: Calls the first specified function - defined in the user keymap - on every tap, the second function when the dance action finishes (like the previous option), and the last function when the tap dance action resets. |
36 | * `ACTION_TAP_DANCE_FN_ADVANCED_TIME(on_each_tap_fn, on_dance_finished_fn, on_dance_reset_fn, tap_specific_tapping_term)`: This functions identically to the `ACTION_TAP_DANCE_FN_ADVANCED` function, but uses a custom tapping term for it, instead of the predefined `TAPPING_TERM`. | 38 | * `ACTION_TAP_DANCE_FN_ADVANCED_TIME(on_each_tap_fn, on_dance_finished_fn, on_dance_reset_fn, tap_specific_tapping_term)`: This functions identically to the `ACTION_TAP_DANCE_FN_ADVANCED` function, but uses a custom tapping term for it, instead of the predefined `TAPPING_TERM`. |
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index c27fe4834..16756e59c 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c | |||
@@ -71,7 +71,7 @@ void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_dat | |||
71 | if (state->count == 1) { | 71 | if (state->count == 1) { |
72 | register_code16(pair->kc); | 72 | register_code16(pair->kc); |
73 | } else if (state->count == 2) { | 73 | } else if (state->count == 2) { |
74 | layer_move(pair->layer); | 74 | pair->layer_function(pair->layer); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index b2d0cb829..8d227dfd7 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h | |||
@@ -56,13 +56,19 @@ typedef struct { | |||
56 | typedef struct { | 56 | typedef struct { |
57 | uint16_t kc; | 57 | uint16_t kc; |
58 | uint8_t layer; | 58 | uint8_t layer; |
59 | void (*layer_function)(uint8_t); | ||
59 | } qk_tap_dance_dual_role_t; | 60 | } qk_tap_dance_dual_role_t; |
60 | 61 | ||
61 | # define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ | 62 | # define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ |
62 | { .fn = {qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset}, .user_data = (void *)&((qk_tap_dance_pair_t){kc1, kc2}), } | 63 | { .fn = {qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset}, .user_data = (void *)&((qk_tap_dance_pair_t){kc1, kc2}), } |
63 | 64 | ||
64 | # define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \ | 65 | # define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \ |
65 | { .fn = {qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset}, .user_data = (void *)&((qk_tap_dance_dual_role_t){kc, layer}), } | 66 | { .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_move }), } |
67 | |||
68 | # define ACTION_TAP_DANCE_TOGGLE_LAYER(kc, layer) \ | ||
69 | { .fn = { NULL, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_invert }), } | ||
70 | |||
71 | # define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) | ||
66 | 72 | ||
67 | # define ACTION_TAP_DANCE_FN(user_fn) \ | 73 | # define ACTION_TAP_DANCE_FN(user_fn) \ |
68 | { .fn = {NULL, user_fn, NULL}, .user_data = NULL, } | 74 | { .fn = {NULL, user_fn, NULL}, .user_data = NULL, } |
@@ -73,6 +79,8 @@ typedef struct { | |||
73 | # define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) \ | 79 | # define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) \ |
74 | { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, .custom_tapping_term = tap_specific_tapping_term, } | 80 | { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, .custom_tapping_term = tap_specific_tapping_term, } |
75 | 81 | ||
82 | |||
83 | |||
76 | extern qk_tap_dance_action_t tap_dance_actions[]; | 84 | extern qk_tap_dance_action_t tap_dance_actions[]; |
77 | 85 | ||
78 | /* To be used internally */ | 86 | /* To be used internally */ |