aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/feature_tap_dance.md62
1 files changed, 30 insertions, 32 deletions
diff --git a/docs/feature_tap_dance.md b/docs/feature_tap_dance.md
index e381c2af0..4f98b858e 100644
--- a/docs/feature_tap_dance.md
+++ b/docs/feature_tap_dance.md
@@ -422,7 +422,7 @@ Tap Dance can be used to mimic MO(layer) and TG(layer) functionality. For this e
422 422
423The first step is to include the following code towards the beginning of your `keymap.c`: 423The first step is to include the following code towards the beginning of your `keymap.c`:
424 424
425``` 425```c
426typedef struct { 426typedef struct {
427 bool is_press_action; 427 bool is_press_action;
428 int state; 428 int state;
@@ -452,36 +452,20 @@ void ql_reset (qk_tap_dance_state_t *state, void *user_data);
452int active_layer; 452int active_layer;
453``` 453```
454 454
455The above code is similar to that used in previous examples. The one point to note is that you need to declare a variable to keep track of what layer is currently the active layer. We'll see why shortly.
456
457Towards the bottom of your `keymap.c`, include the following code: 455Towards the bottom of your `keymap.c`, include the following code:
458 456
459``` 457```c
460//Update active_layer
461uint32_t layer_state_set_user(uint32_t state) {
462 switch (biton32(state)) {
463 case 1:
464 active_layer = 1;
465 break;
466 case 2:
467 active_layer = 2;
468 break;
469 case 3:
470 active_layer = 3;
471 break;
472 default:
473 active_layer = 0;
474 break;
475 }
476 return state;
477}
478
479//Determine the current tap dance state 458//Determine the current tap dance state
480int cur_dance (qk_tap_dance_state_t *state) { 459int cur_dance (qk_tap_dance_state_t *state) {
481 if (state->count == 1) { 460 if (state->count == 1) {
482 if (!state->pressed) {return SINGLE_TAP;} 461 if (!state->pressed) {
483 else return SINGLE_HOLD; 462 return SINGLE_TAP;
484 } else if (state->count == 2) {return DOUBLE_TAP;} 463 } else {
464 return SINGLE_HOLD;
465 }
466 } else if (state->count == 2) {
467 return DOUBLE_TAP;
468 }
485 else return 8; 469 else return 8;
486} 470}
487 471
@@ -495,16 +479,30 @@ static tap ql_tap_state = {
495void ql_finished (qk_tap_dance_state_t *state, void *user_data) { 479void ql_finished (qk_tap_dance_state_t *state, void *user_data) {
496 ql_tap_state.state = cur_dance(state); 480 ql_tap_state.state = cur_dance(state);
497 switch (ql_tap_state.state) { 481 switch (ql_tap_state.state) {
498 case SINGLE_TAP: tap_code(KC_QUOT); break; 482 case SINGLE_TAP:
499 case SINGLE_HOLD: layer_on(_MY_LAYER); break; 483 tap_code(KC_QUOT);
484 break;
485 case SINGLE_HOLD:
486 layer_on(_MY_LAYER);
487 break;
500 case DOUBLE_TAP: 488 case DOUBLE_TAP:
501 if (active_layer==_MY_LAYER) {layer_off(_MY_LAYER);} 489 //check to see if the layer is already set
502 else layer_on(_MY_LAYER); 490 if (layer_state_is(_MY_LAYER)) {
491 //if already set, then switch it off
492 layer_off(_MY_LAYER);
493 } else {
494 //if not already set, then switch the layer on
495 layer_on(_MY_LAYER);
496 }
497 break;
503 } 498 }
504} 499}
505 500
506void ql_reset (qk_tap_dance_state_t *state, void *user_data) { 501void ql_reset (qk_tap_dance_state_t *state, void *user_data) {
507 if (ql_tap_state.state==SINGLE_HOLD) {layer_off(_MY_LAYER);} 502 //if the key was held down and now is released then switch off the layer
503 if (ql_tap_state.state==SINGLE_HOLD) {
504 layer_off(_MY_LAYER);
505 }
508 ql_tap_state.state = 0; 506 ql_tap_state.state = 0;
509} 507}
510 508
@@ -514,7 +512,7 @@ qk_tap_dance_action_t tap_dance_actions[] = {
514}; 512};
515``` 513```
516 514
517The is where the real logic of our tap dance key gets worked out. Since `layer_state_set_user()` is called on any layer switch, we use it to update `active_layer`. Our example is assuming that your `keymap.c` includes 4 layers, so adjust the switch statement here to fit your actual number of layers. 515The above code is similar to that used in previous examples. The one point to note is that we need to be able to check which layers are active at any time so we can toggle them if needed. To do this we use the `layer_state_is( layer )` function which returns `true` if the given `layer` is active.
518 516
519The use of `cur_dance()` and `ql_tap_state` mirrors the above examples. 517The use of `cur_dance()` and `ql_tap_state` mirrors the above examples.
520 518