]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/333fred/333fred.c
333fred layout update (#1971)
[qmk_firmware.git] / users / 333fred / 333fred.c
1 #include "333fred.h"
2 #include "quantum.h"
3 #include "action.h"
4
5 typedef enum {
6     SINGLE_TAP, SINGLE_HOLD, DOUBLE
7 } tap_dance_state_enum;
8
9 static tap_dance_state_enum tap_dance_state;
10 static bool tap_dance_active = false;
11
12 void tap_dance_layer_finished(qk_tap_dance_state_t *state, void *user_data) {
13     // Determine the current state
14     if (state->count == 1) {
15         if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP;
16         else tap_dance_state = SINGLE_HOLD;
17     } else {
18         // Handle any number of other taps as a VIM movement hold
19         tap_dance_state = DOUBLE;
20     }
21
22     switch (tap_dance_state) {
23         case SINGLE_TAP:
24             if (tap_dance_active) {
25                 reset_oneshot_layer();
26                 tap_dance_active = false;
27             } else {
28                 set_oneshot_layer(SYMB, ONESHOT_START);
29                 tap_dance_active = true;
30             }
31             break;
32         case SINGLE_HOLD:
33             layer_on(SYMB);
34             break;
35         case DOUBLE:
36             layer_on(VIM);
37     }
38 }
39
40
41 void tap_dance_layer_reset(qk_tap_dance_state_t *state, void *user_data) {
42     switch(tap_dance_state) {
43         case SINGLE_TAP:
44             clear_oneshot_layer_state(ONESHOT_PRESSED);
45             break;
46         case SINGLE_HOLD:
47             layer_off(SYMB);
48             break;
49         case DOUBLE:
50             layer_off(VIM);
51             break;
52     }
53 }
54
55 qk_tap_dance_action_t tap_dance_actions[] = {
56     [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_layer_finished, tap_dance_layer_reset)
57 };
58
59 void tap_dance_process_record(uint16_t keycode) {
60     if (tap_dance_state == SINGLE_TAP && keycode != TD(TD_SYM_VIM)) {
61         tap_dance_active = false;
62     }
63 }