summaryrefslogtreecommitdiff
path: root/keyboards/h0oni/deskpad/keymaps/via/keymap.c
blob: c3eba7c4a9c4798ae3c2caab18579e924ac53dbc (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* Copyright 2021 Hydrogen BD <support@hgenbd.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include QMK_KEYBOARD_H

typedef enum {
    TD_NONE,
    TD_UNKNOWN,
    TD_SINGLE_TAP,
    TD_SINGLE_HOLD,
    TD_DOUBLE_TAP,
    TD_DOUBLE_HOLD,
    TD_DOUBLE_SINGLE_TAP, // Send two single taps
} td_state_t;

typedef struct {
    bool is_press_action;
    td_state_t state;
} td_tap_t;

enum custom_keycodes {
    TD_CUT_REDO,
    TD_PLAY_PAUSE_MUTE,
    TD_MNXT_RIGHT,
    TD_MPRV_LEFT,
    TD_SEARCH_REFRESH,
    QUAD_LAYER_SWITCH,
    QUAD_CVXA,
    YOUTUBE = SAFE_RANGE,
    FACEBOOK,
    DISCORD,
    VALORANT,
    VSCODE,
};

td_state_t cur_dance(tap_dance_state_t *state);

/* Quad layer switching */
void layer_finished(tap_dance_state_t *state, void *user_data);
void layer_reset(tap_dance_state_t *state, void *user_data);

/* Copy, paste, select all, cut */
void cvxa_finished(tap_dance_state_t *state, void *user_data);
void cvxa_reset(tap_dance_state_t *state, void *user_data);

static td_tap_t layerTap_state = {
    .is_press_action = true,
    .state = TD_NONE
};

static td_tap_t cvxa_state = {
    .is_press_action = true,
    .state = TD_NONE
};

// Determine the current tap dance state
td_state_t cur_dance(tap_dance_state_t *state) {
    if (state->count == 1) {
        if (state->interrupted || !state->pressed) return TD_SINGLE_TAP;
        // Key has not been interrupted, but the key is still held. Means you want to send a 'HOLD'.
        else return TD_SINGLE_HOLD;
    } else if (state->count == 2) {
        if (state->interrupted) return TD_DOUBLE_SINGLE_TAP;
        else if (state->pressed) return TD_DOUBLE_HOLD;
        else return TD_DOUBLE_TAP;
    } else return TD_UNKNOWN;
}

void layer_finished(tap_dance_state_t *state, void *user_data) {
    layerTap_state.state = cur_dance(state);
    layer_off(get_highest_layer(layer_state));
    switch (layerTap_state.state) {
        case TD_SINGLE_TAP: layer_on(0); break;
        case TD_SINGLE_HOLD: layer_on(1); break;
        case TD_DOUBLE_TAP: layer_on(2); break;
        case TD_DOUBLE_HOLD: layer_on(3); break;
        default: layer_on(0);
    }
}

void layer_reset(tap_dance_state_t *state, void *user_data) {
    layerTap_state.state = TD_NONE;
}

void cvxa_finished(tap_dance_state_t *state, void *user_data) {
    cvxa_state.state = cur_dance(state);
    register_mods(MOD_BIT(KC_LCTL));
    switch (cvxa_state.state) {
        case TD_SINGLE_TAP: tap_code(KC_V); break;
        case TD_SINGLE_HOLD: tap_code(KC_A); break;
        case TD_DOUBLE_TAP: tap_code(KC_C); break;
        case TD_DOUBLE_HOLD: tap_code(KC_X); break;
        default: tap_code(KC_V);
    }
    unregister_mods(MOD_BIT(KC_LCTL));
}

void cvxa_reset(tap_dance_state_t *state, void *user_data) {
    cvxa_state.state = TD_NONE;
}

// Tap Dance definitions
tap_dance_action_t tap_dance_actions[] = {
    [TD_CUT_REDO] = ACTION_TAP_DANCE_DOUBLE(C(KC_Z), S(C(KC_Z))),
    [TD_PLAY_PAUSE_MUTE] = ACTION_TAP_DANCE_DOUBLE(KC_MPLY, KC_MUTE),
    [TD_MNXT_RIGHT] = ACTION_TAP_DANCE_DOUBLE(KC_MNXT, KC_RIGHT),
    [TD_MPRV_LEFT] = ACTION_TAP_DANCE_DOUBLE(KC_MPRV, KC_LEFT),
    [TD_SEARCH_REFRESH] = ACTION_TAP_DANCE_DOUBLE(KC_WREF, KC_WSCH),
    [QUAD_LAYER_SWITCH] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, layer_finished, layer_reset),
    [QUAD_CVXA] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, cvxa_finished, cvxa_reset)
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch(keycode) {
        case YOUTUBE:
            if (record->event.pressed) {
                tap_code16(C(KC_L));
                SEND_STRING("https://www.youtube.com/");
            } else {
                tap_code(KC_ENT);
            }
            break;
        case FACEBOOK:
            if (record->event.pressed) {
                tap_code16(C(KC_L));
                SEND_STRING("https://www.facebook.com/");
            } else {
                tap_code(KC_ENT);
            }
            break;
        case VALORANT:
            if (record->event.pressed) {
                tap_code16(G(KC_S));
                SEND_STRING("valorant");
            } else {
                tap_code(KC_ENT);
            }
            break;
        case DISCORD:
            if (record->event.pressed) {
                tap_code16(G(KC_S));
                SEND_STRING("discord");
            } else {
                tap_code(KC_ENT);
            }
            break;
        case VSCODE:
            if (record->event.pressed) {
                tap_code16(G(KC_S));
                SEND_STRING("vscode");
            } else {
                tap_code(KC_ENT);
            }
            break;
    }
    return true;
}; 

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

  [0] = LAYOUT_all(
      TD(TD_CUT_REDO), TD(TD_MPRV_LEFT), TD(TD_PLAY_PAUSE_MUTE), TD(TD_MNXT_RIGHT), TD(QUAD_CVXA), TD(QUAD_LAYER_SWITCH)
      ),

  [1] = LAYOUT_all(
      YOUTUBE, KC_WBAK, TD(TD_SEARCH_REFRESH), KC_WFWD, FACEBOOK, TD(QUAD_LAYER_SWITCH)
      ),

  [2] = LAYOUT_all(
      A(KC_F4), SGUI(KC_S), KC_MYCM, LCA(KC_DEL), KC_CALC, TD(QUAD_LAYER_SWITCH)
      ),
  
  [3] = LAYOUT_all(
      C(KC_SLSH), VALORANT, VSCODE, DISCORD, LSA(KC_A), TD(QUAD_LAYER_SWITCH)
      ),
};