aboutsummaryrefslogtreecommitdiff
path: root/users/jdelkins/jdelkins.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/jdelkins/jdelkins.c')
-rw-r--r--users/jdelkins/jdelkins.c274
1 files changed, 274 insertions, 0 deletions
diff --git a/users/jdelkins/jdelkins.c b/users/jdelkins/jdelkins.c
new file mode 100644
index 000000000..7577512ec
--- /dev/null
+++ b/users/jdelkins/jdelkins.c
@@ -0,0 +1,274 @@
1/*
2 Copyright 2020 Joel Elkins <joel@elkins.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "jdelkins.h"
19#include "version.h"
20
21#ifdef DO_SECRETS
22# include "secrets.h"
23#else
24# ifndef NO_SECRETS
25# pragma message("Warning: secrets.h not found")
26# endif
27#endif
28
29user_config_t user_config;
30
31__attribute__ ((weak))
32bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
33 return true;
34}
35
36void send_secret_string(uint8_t n) {
37#ifdef DO_SECRETS
38 send_string(secret[n]);
39#else
40 SEND_STRING("");
41#endif
42}
43
44#ifdef TAP_DANCE_ENABLE
45
46// To activate SINGLE_HOLD, you will need to hold for 200ms first.
47// This tap dance favors keys that are used frequently in typing like 'f'
48int cur_dance(qk_tap_dance_state_t *state) {
49 if (state->count == 1) {
50 // If count = 1, and it has been interrupted - it doesn't matter if it
51 // is pressed or not: Send SINGLE_TAP
52 if (state->interrupted) {
53 // if (!state->pressed) return SINGLE_TAP;
54 // need "permissive hold" here.
55 // else return SINsGLE_HOLD;
56 // If the interrupting key is released before the tap-dance key,
57 // then it is a single HOLD However, if the tap-dance key is
58 // released first, then it is a single TAP But how to get access to
59 // the state of the interrupting key????
60 return SINGLE_TAP;
61 } else {
62 if (!state->pressed)
63 return SINGLE_TAP;
64 else
65 return SINGLE_HOLD;
66 }
67 }
68 // If count = 2, and it has been interrupted - assume that user is trying to
69 // type the letter associated with single tap.
70 else if (state->count == 2) {
71 if (state->interrupted)
72 return DOUBLE_SINGLE_TAP;
73 else if (state->pressed)
74 return DOUBLE_HOLD;
75 else
76 return DOUBLE_TAP;
77 } else if ((state->count == 3) && ((state->interrupted) || (!state->pressed)))
78 return TRIPLE_TAP;
79 else if (state->count == 3)
80 return TRIPLE_HOLD;
81 else
82 return 8; // magic number. At some point this method will expand to work for more presses
83}
84
85// This works well if you want this key to work as a "fast modifier". It favors
86// being held over being tapped.
87int hold_cur_dance(qk_tap_dance_state_t *state) {
88 if (state->count == 1) {
89 if (state->interrupted) {
90 if (!state->pressed)
91 return SINGLE_TAP;
92 else
93 return SINGLE_HOLD;
94 } else {
95 if (!state->pressed)
96 return SINGLE_TAP;
97 else
98 return SINGLE_HOLD;
99 }
100 }
101 // If count = 2, and it has been interrupted - assume that user is trying to
102 // type the letter associated with single tap.
103 else if (state->count == 2) {
104 if (state->pressed)
105 return DOUBLE_HOLD;
106 else
107 return DOUBLE_TAP;
108 } else if (state->count == 3) {
109 if (!state->pressed)
110 return TRIPLE_TAP;
111 else
112 return TRIPLE_HOLD;
113 } else
114 return 8; // magic number. At some point this method will expand to work for more presses
115}
116
117#endif // TAP_DANCE_ENABLE
118
119__attribute__ ((weak))
120void keyboard_post_init_keymap(void) {
121}
122
123void keyboard_post_init_user(void) {
124 user_config.raw = eeconfig_read_user();
125 keyboard_post_init_keymap();
126}
127
128void eeconfig_init_user(void) {
129 user_config.raw = 0;
130 user_config.system_mac = false;
131 eeconfig_update_user(user_config.raw);
132}
133
134bool process_record_user(uint16_t keycode, keyrecord_t *record) {
135 static uint32_t boot_timer;
136
137 if (!process_record_keymap(keycode, record)) {
138 return false;
139 }
140
141 switch (keycode) {
142 case FW_WRD:
143 do_mac_key(LCTL(KC_RIGHT), ROPT(KC_RIGHT), record);
144 break;
145
146 case BK_WRD:
147 do_mac_key(LCTL(KC_LEFT), ROPT(KC_LEFT), record);
148 break;
149
150 case KB_BOL:
151 do_mac_key(KC_HOME, RCMD(KC_LEFT), record);
152 break;
153
154 case KB_EOL:
155 do_mac_key(KC_END, RCMD(KC_RIGHT), record);
156 break;
157
158 case TG_SYS:
159 if (record->event.pressed) {
160 user_config.system_mac ^= 1;
161 eeconfig_update_user(user_config.raw);
162 }
163 break;
164
165 case KB_COPY:
166 do_mac_key(LCTL(KC_INS), RCMD(KC_C), record);
167 break;
168
169 case KB_PASTE:
170 do_mac_key(LSFT(KC_INS), RCMD(KC_V), record);
171 break;
172
173 case MY_GUI:
174 do_mac_key(KC_LGUI, KC_LOPT, record);
175 break;
176
177 case MY_ALT:
178 do_mac_key(KC_LALT, KC_LCMD, record);
179 break;
180
181 case MY_RGUI:
182 do_mac_key(KC_RGUI, KC_ROPT, record);
183 break;
184
185 case MY_RALT:
186 do_mac_key(KC_RALT, KC_RCMD, record);
187 break;
188
189 case MY_CALC:
190 do_mac_key(KC_CALC, KC_F14, record);
191 break;
192
193 case KB_MAKE:
194 if (!get_mods()) {
195 if (!record->event.pressed)
196 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP SS_TAP(X_ENTER));
197 return false;
198 }
199 break;
200
201 case KB_VRSN:
202 if (!get_mods()) {
203 if (!record->event.pressed) {
204 if (user_config.system_mac) {
205 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION " (mac mode)");
206 } else {
207 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION " (non-mac mode)");
208 }
209 }
210 return false;
211 }
212 break;
213
214 case KB_BOOT:
215 if (!get_mods()) {
216 if (record->event.pressed) {
217 boot_timer = timer_read32();
218 } else {
219 if (timer_elapsed32(boot_timer) >= 500) {
220 reset_keyboard();
221 }
222 }
223 return false;
224 }
225 break;
226
227 case KB_FLSH:
228 if (!get_mods()) {
229 if (!record->event.pressed) {
230 SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP ":flash\n");
231 reset_keyboard();
232 }
233 return false;
234 }
235 break;
236
237#ifdef DO_SECRETS
238 case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
239 if (!record->event.pressed) {
240 clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
241 send_secret_string(keycode - KC_SECRET_1);
242 }
243 return false;
244 break;
245#endif
246 }
247
248 return true;
249}
250
251__attribute__ ((weak))
252void matrix_init_keymap(void) {
253}
254
255void matrix_init_user(void) {
256 matrix_init_keymap();
257}
258
259__attribute__ ((weak))
260void matrix_scan_keymap(void) {
261}
262
263void matrix_scan_user(void) {
264 matrix_scan_keymap();
265}
266
267__attribute__ ((weak))
268layer_state_t layer_state_set_keymap(layer_state_t state) {
269 return state;
270}
271
272layer_state_t layer_state_set_user(layer_state_t state) {
273 return layer_state_set_keymap(state);
274}