summaryrefslogtreecommitdiff
path: root/users/pcoves/tapDance.c
blob: 05b451f02e3f7c3354313330de289401b32c3d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "tapDance.h"

#include "quantum.h"

void left(qk_tap_dance_state_t* state, void* user_data) {
    switch (state->count) {
        case 1:
            if (state->pressed)
                tap_code16(S(KC_LEFT_BRACKET));
            else
                tap_code16(S(KC_9));
            break;
        case 2:
            if (state->pressed)
                tap_code16(S(KC_COMM));
            else
                tap_code(KC_LEFT_BRACKET);
            break;
        default:
            reset_tap_dance(state);
    }
}

void right(qk_tap_dance_state_t* state, void* user_data) {
    switch (state->count) {
        case 1:
            if (state->pressed)
                tap_code16(S(KC_RIGHT_BRACKET));
            else
                tap_code16(S(KC_0));
            break;
        case 2:
            if (state->pressed)
                tap_code16(S(KC_DOT));
            else
                tap_code(KC_RIGHT_BRACKET);
            break;
        default:
            reset_tap_dance(state);
    }
}

enum { REST, HOLD1, HOLD2, HOLD3 };

static int Alt = REST;
void       altFinish(qk_tap_dance_state_t* state, void* user_data) {
    switch (state->count) {
        case 1:
            if (state->pressed) {
                register_code(KC_LALT);
                Alt = HOLD1;
            }
            break;
        case 2:
            if (state->pressed) {
                register_code(KC_RALT);
                Alt = HOLD2;
            }
            break;
        case 3:
            if (state->pressed) {
                register_code(KC_RALT);
                register_code(KC_RSFT);
                Alt = HOLD3;
            }
            break;
        default:
            reset_tap_dance(state);
    }
}

void altReset(qk_tap_dance_state_t* state, void* user_data) {
    switch (Alt) {
        case HOLD1:
            unregister_code(KC_LALT);
            break;
        case HOLD2:
            unregister_code(KC_RALT);
            break;
        case HOLD3:
            unregister_code(KC_RSFT);
            unregister_code(KC_RALT);
            break;
    }
    Alt = REST;
}

static int Ctrl = REST;
void       ctrlFinish(qk_tap_dance_state_t* state, void* user_data) {
    switch (state->count) {
        case 1:
            if (state->pressed) {
                register_code(KC_LCTL);
                Ctrl = HOLD1;
            } else {
                tap_code(KC_ESC);
            }
            break;
        case 2:
            if (state->pressed) {
                register_code(KC_LGUI);
                Ctrl = HOLD2;
            }
            break;
        default:
            reset_tap_dance(state);
    }
}

void ctrlReset(qk_tap_dance_state_t* state, void* user_data) {
    switch (Ctrl) {
        case HOLD1:
            unregister_code(KC_LCTL);
            break;
        case HOLD2:
            unregister_code(KC_LGUI);
            break;
    }
    Ctrl = REST;
}

qk_tap_dance_action_t tap_dance_actions[] = {
    [ALT]   = ACTION_TAP_DANCE_FN_ADVANCED(NULL, altFinish, altReset),
    [CTRL]  = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ctrlFinish, ctrlReset),
    [LEFT]  = ACTION_TAP_DANCE_FN(left),
    [RIGHT] = ACTION_TAP_DANCE_FN(right),
};