summaryrefslogtreecommitdiff
path: root/users/scotto/tap_dance.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/scotto/tap_dance.c')
-rw-r--r--users/scotto/tap_dance.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/users/scotto/tap_dance.c b/users/scotto/tap_dance.c
new file mode 100644
index 0000000000..e618384334
--- /dev/null
+++ b/users/scotto/tap_dance.c
@@ -0,0 +1,154 @@
1/*
2Copyright 2023 Joe Scotto
3This program is free software: you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation, either version 2 of the License, or
6(at your option) any later version.
7This program is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY; without even the implied warranty of
9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10GNU General Public License for more details.
11You should have received a copy of the GNU General Public License
12along with this program. If not, see <http://www.gnu.org/licenses/>.
13*/
14
15#include "tap_dance.h"
16#include "scotto.h"
17
18// Create an instance of 'td_tap_t' for the 'x' tap dance.
19static td_tap_t xtap_state = {
20 .is_press_action = true,
21 .state = TD_NONE
22};
23
24td_state_t cur_dance(tap_dance_state_t *state) {
25 if (state->count == 1) {
26 if (state->interrupted || !state->pressed) {
27 return TD_SINGLE_TAP;
28 } else {
29 return TD_SINGLE_HOLD;
30 }
31 } else if (state->count == 2) {
32 if (state->interrupted || !state->pressed) {
33 return TD_DOUBLE_TAP;
34 } else {
35 return TD_DOUBLE_HOLD;
36 }
37 } else if (state->count == 3) {
38 if (state->interrupted || !state->pressed) {
39 return TD_TRIPLE_TAP;
40 } else {
41 return TD_TRIPLE_HOLD;
42 }
43 }
44
45 return TD_UNKNOWN;
46}
47
48void td_esc_lalt_lctl_spotlight_emoji_finished(tap_dance_state_t *state, void *user_data) {
49 xtap_state.state = cur_dance(state);
50 switch (xtap_state.state) {
51 case TD_SINGLE_TAP: tap_code(KC_ESC); break;
52 case TD_SINGLE_HOLD: register_code(KC_LALT); break;
53 case TD_DOUBLE_HOLD: register_code(KC_LCTL); break;
54 case TD_DOUBLE_TAP: tap_code16(G(KC_SPC)); break;
55 case TD_TRIPLE_TAP: tap_code16(C(G(KC_SPC))); break;
56 default: break;
57 }
58}
59
60void td_esc_lalt_lctl_spotlight_emoji_reset(tap_dance_state_t *state, void *user_data) {
61 switch (xtap_state.state) {
62 case TD_SINGLE_TAP: unregister_code(KC_ESC); break;
63 case TD_SINGLE_HOLD: unregister_code(KC_LALT); break;
64 case TD_DOUBLE_HOLD: unregister_code(KC_LCTL); break;
65 default: break;
66 }
67 xtap_state.state = TD_NONE;
68}
69
70void td_esc_lctl_lalt_windows_emoji_finished(tap_dance_state_t *state, void *user_data) {
71 xtap_state.state = cur_dance(state);
72 switch (xtap_state.state) {
73 case TD_SINGLE_TAP: tap_code16(KC_ESC); break;
74 case TD_SINGLE_HOLD: register_code(KC_LCTL); break;
75 case TD_DOUBLE_HOLD: register_code(KC_LALT); break;
76 case TD_DOUBLE_TAP: tap_code(KC_LGUI); break;
77 case TD_TRIPLE_TAP: tap_code16(G(KC_DOT)); break;
78 default: break;
79 }
80}
81
82void td_esc_lctl_lalt_windows_emoji_reset(tap_dance_state_t *state, void *user_data) {
83 switch (xtap_state.state) {
84 case TD_SINGLE_TAP: unregister_code(KC_ESC); break;
85 case TD_SINGLE_HOLD: unregister_code(KC_LCTL); break;
86 case TD_DOUBLE_HOLD: unregister_code(KC_LALT); break;
87 default: break;
88 }
89 xtap_state.state = TD_NONE;
90}
91
92void td_lalt_esc_windowr_emoji_finished(tap_dance_state_t *state, void *user_data) {
93 xtap_state.state = cur_dance(state);
94 switch (xtap_state.state) {
95 case TD_SINGLE_TAP: register_code(KC_ESC); break;
96 case TD_SINGLE_HOLD: register_code(KC_LALT); break;
97 case TD_DOUBLE_TAP: tap_code(KC_LGUI); break;
98 case TD_TRIPLE_TAP: tap_code16(G(KC_DOT)); break;
99 default: break;
100 }
101}
102
103void td_lalt_esc_windowr_emoji_reset(tap_dance_state_t *state, void *user_data) {
104 switch (xtap_state.state) {
105 case TD_SINGLE_TAP: unregister_code(KC_ESC); break;
106 case TD_SINGLE_HOLD: unregister_code(KC_LALT); break;
107 default: break;
108 }
109 xtap_state.state = TD_NONE;
110}
111
112void td_lctl_esc_spotlight_emoji_finished(tap_dance_state_t *state, void *user_data) {
113 xtap_state.state = cur_dance(state);
114 switch (xtap_state.state) {
115 case TD_SINGLE_TAP: register_code(KC_ESC); break;
116 case TD_SINGLE_HOLD: register_code(KC_LCTL); break;
117 case TD_DOUBLE_TAP: tap_code16(G(KC_SPC)); break;
118 case TD_TRIPLE_TAP: tap_code16(C(G(KC_SPC))); break;
119 default: break;
120 }
121}
122
123void td_lctl_esc_spotlight_emoji_reset(tap_dance_state_t *state, void *user_data) {
124 switch (xtap_state.state) {
125 case TD_SINGLE_TAP: unregister_code(KC_ESC); break;
126 case TD_SINGLE_HOLD: unregister_code(KC_LCTL); break;
127 default: break;
128 }
129 xtap_state.state = TD_NONE;
130}
131
132 // Tap Dance definitions
133tap_dance_action_t tap_dance_actions[] = {
134 [TD_LCTL_ESC_SPOTLIGHT_EMOJI] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, td_lctl_esc_spotlight_emoji_finished, td_lctl_esc_spotlight_emoji_reset),
135 [TD_LALT_ESC_WINDOWS_EMOJI] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, td_lalt_esc_windowr_emoji_finished, td_lalt_esc_windowr_emoji_reset),
136 [TD_ESC_LALT_LCTL_SPOTLIGHT_EMOJI] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, td_esc_lalt_lctl_spotlight_emoji_finished, td_esc_lalt_lctl_spotlight_emoji_reset),
137 [TD_ESC_LCTL_LALT_WINDOWS_EMOJI] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, td_esc_lctl_lalt_windows_emoji_finished, td_esc_lctl_lalt_windows_emoji_reset),
138};
139
140uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
141 switch (keycode) {
142 case TD(TD_LCTL_ESC_SPOTLIGHT_EMOJI) :
143 case TD(TD_LALT_ESC_WINDOWS_EMOJI) :
144 case TD(TD_ESC_LALT_LCTL_SPOTLIGHT_EMOJI) :
145 case TD(TD_ESC_LCTL_LALT_WINDOWS_EMOJI) :
146 case LGUI_T(KC_SPC) :
147 case LT(1, KC_SPC) :
148 case LT(1, KC_TAB) :
149 case LT(2, KC_ENT) :
150 return 200;
151 default:
152 return TAPPING_TERM;
153 }
154};