summaryrefslogtreecommitdiffstats
path: root/users/muppetjones/features/dancelayers.h
blob: 23defcca92dfdb6f45ba1114531862472e0056d8 (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
/* Copyright 2020 Stephen J. Bush
 *
 * 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/>.
 */

#pragma once
#ifdef TAP_DANCE_ENABLE
#    include QMK_KEYBOARD_H

/*
 * TAP DANCE
 * https://docs.qmk.fm/#/feature_tap_dance
 */

// Define a type for as many tap dance states as you need
typedef enum {
    TD_NONE = 0,
    TD_UNKNOWN,
    TD_1X_TAP,
    TD_1X_HOLD,
    TD_2X_TAP,
    TD_3X_TAP,
    TD_4X_TAP,
} td_state_t;

// Our custom tap dance key; add any other tap dance keys to this enum
enum {
    TD_LAYERS = 0,  // NOTE: Start at 0 as this is also an array index
};
#    define TD_LAYR TD(TD_LAYERS)

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

// Declare the functions to be used with your tap dance key(s)

/* @brief Determine the current tap dance state
 * @param A tap dance state struct.
 * @return A struct.
 */
td_state_t cur_dance(qk_tap_dance_state_t *state);

// Functions associated with individual tap dances

/* @brief Associate tap actions with layers.
 *
 * NOTE: Weak attribute. Can (and should) be defined in keymap.c
 *
 * @param state Pointer to a tap dance state object.
 * @param user_data Pointer to user data.
 * @return None.
 */
void td_layer_finished(qk_tap_dance_state_t *state, void *user_data);

/* @brief Reset tap dance actions.
 *
 * NOTE: Weak attribute. Can (and should) be defined in keymap.c
 *
 * @param state Pointer to a tap dance state object.
 * @param user_data Pointer to user data.
 * @return None.
 */
void td_layer_reset(qk_tap_dance_state_t *state, void *user_data);

/* Define tap dance actions.
 */
__attribute__((weak))
qk_tap_dance_action_t tap_dance_actions[1] = {[TD_LAYERS] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_layer_finished, td_layer_reset, 275)};
#endif