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
|
#include QMK_KEYBOARD_H
#include "quad_tapdance.h"
#include "layer_dance.h"
//
// Definition for the layer key
//
// The only one usage is to activate the layer over the keyboard, but there is
// two way of doing it:
//
// The first mode, when hold, is to activate the layer as long as the key is
// pressed.
// The second one is to switch in the layer mode when tapped, in this mode,
// you can go back into the normal layer by a single press on the key.
//
static td_tap_t keypad_tap_state = {
.state = TD_NONE
};
// Functions that control what our tap dance key does
void keypad_finished(tap_dance_state_t *state, void *user_data) {
keypad_tap_state.state = cur_dance(state);
switch (keypad_tap_state.state) {
// Remove the layer with a single tap, this way I always have a key to
// remove the the layer, without knowing the previous state I had.
//
// Here, we control both the keypad or the arrow layers
case TD_SINGLE_TAP:
if (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) ) {
layer_clear();
} else {
layer_on(LAYER_KEYPAD);
}
break;
case TD_SINGLE_HOLD: layer_on(LAYER_KEYPAD); break;
default: break;
}
}
void keypad_reset(tap_dance_state_t *state, void *user_data) {
// If the key was held down and now is released then switch off the layer
if (keypad_tap_state.state == TD_SINGLE_HOLD) {
layer_clear();
}
keypad_tap_state.state = TD_NONE;
}
// Do the same for the arrow layer.
static td_tap_t arrow_tap_state = {
.state = TD_NONE
};
// Functions that control what our tap dance key does
void arrow_finished(tap_dance_state_t *state, void *user_data) {
arrow_tap_state.state = cur_dance(state);
switch (arrow_tap_state.state) {
// Remove the layer with a single tap, this way I always have a key to
// remove the the layer, without knowing the previous state I had.
case TD_SINGLE_TAP:
if (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) ) {
layer_clear();
} else {
layer_on(LAYER_ARROW);
}
break;
case TD_SINGLE_HOLD: layer_on(LAYER_ARROW); break;
default: break;
}
}
void arrow_reset(tap_dance_state_t *state, void *user_data) {
// If the key was held down and now is released then switch off the layer
if (arrow_tap_state.state == TD_SINGLE_HOLD) {
layer_clear();
}
arrow_tap_state.state = TD_NONE;
}
|