diff options
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r-- | tmk_core/common/action.c | 671 |
1 files changed, 343 insertions, 328 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index f47fd20fc..1ba38a285 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c | |||
@@ -29,9 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
29 | #include "wait.h" | 29 | #include "wait.h" |
30 | 30 | ||
31 | #ifdef DEBUG_ACTION | 31 | #ifdef DEBUG_ACTION |
32 | #include "debug.h" | 32 | # include "debug.h" |
33 | #else | 33 | #else |
34 | #include "nodebug.h" | 34 | # include "nodebug.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | int tp_buttons; | 37 | int tp_buttons; |
@@ -41,24 +41,25 @@ int retro_tapping_counter = 0; | |||
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #ifdef FAUXCLICKY_ENABLE | 43 | #ifdef FAUXCLICKY_ENABLE |
44 | #include <fauxclicky.h> | 44 | # include <fauxclicky.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #ifndef TAP_CODE_DELAY | 47 | #ifndef TAP_CODE_DELAY |
48 | # define TAP_CODE_DELAY 0 | 48 | # define TAP_CODE_DELAY 0 |
49 | #endif | 49 | #endif |
50 | #ifndef TAP_HOLD_CAPS_DELAY | 50 | #ifndef TAP_HOLD_CAPS_DELAY |
51 | # define TAP_HOLD_CAPS_DELAY 80 | 51 | # define TAP_HOLD_CAPS_DELAY 80 |
52 | #endif | 52 | #endif |
53 | /** \brief Called to execute an action. | 53 | /** \brief Called to execute an action. |
54 | * | 54 | * |
55 | * FIXME: Needs documentation. | 55 | * FIXME: Needs documentation. |
56 | */ | 56 | */ |
57 | void action_exec(keyevent_t event) | 57 | void action_exec(keyevent_t event) { |
58 | { | ||
59 | if (!IS_NOEVENT(event)) { | 58 | if (!IS_NOEVENT(event)) { |
60 | dprint("\n---- action_exec: start -----\n"); | 59 | dprint("\n---- action_exec: start -----\n"); |
61 | dprint("EVENT: "); debug_event(event); dprintln(); | 60 | dprint("EVENT: "); |
61 | debug_event(event); | ||
62 | dprintln(); | ||
62 | #ifdef RETRO_TAPPING | 63 | #ifdef RETRO_TAPPING |
63 | retro_tapping_counter++; | 64 | retro_tapping_counter++; |
64 | #endif | 65 | #endif |
@@ -80,7 +81,7 @@ void action_exec(keyevent_t event) | |||
80 | } | 81 | } |
81 | #endif | 82 | #endif |
82 | 83 | ||
83 | keyrecord_t record = { .event = event }; | 84 | keyrecord_t record = {.event = event}; |
84 | 85 | ||
85 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 86 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
86 | if (has_oneshot_layer_timed_out()) { | 87 | if (has_oneshot_layer_timed_out()) { |
@@ -96,14 +97,16 @@ void action_exec(keyevent_t event) | |||
96 | #else | 97 | #else |
97 | process_record(&record); | 98 | process_record(&record); |
98 | if (!IS_NOEVENT(record.event)) { | 99 | if (!IS_NOEVENT(record.event)) { |
99 | dprint("processed: "); debug_record(record); dprintln(); | 100 | dprint("processed: "); |
101 | debug_record(record); | ||
102 | dprintln(); | ||
100 | } | 103 | } |
101 | #endif | 104 | #endif |
102 | } | 105 | } |
103 | 106 | ||
104 | #ifdef SWAP_HANDS_ENABLE | 107 | #ifdef SWAP_HANDS_ENABLE |
105 | bool swap_hands = false; | 108 | bool swap_hands = false; |
106 | bool swap_held = false; | 109 | bool swap_held = false; |
107 | 110 | ||
108 | /** \brief Process Hand Swap | 111 | /** \brief Process Hand Swap |
109 | * | 112 | * |
@@ -112,10 +115,9 @@ bool swap_held = false; | |||
112 | void process_hand_swap(keyevent_t *event) { | 115 | void process_hand_swap(keyevent_t *event) { |
113 | static swap_state_row_t swap_state[MATRIX_ROWS]; | 116 | static swap_state_row_t swap_state[MATRIX_ROWS]; |
114 | 117 | ||
115 | keypos_t pos = event->key; | 118 | keypos_t pos = event->key; |
116 | swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col; | 119 | swap_state_row_t col_bit = (swap_state_row_t)1 << pos.col; |
117 | bool do_swap = event->pressed ? swap_hands : | 120 | bool do_swap = event->pressed ? swap_hands : swap_state[pos.row] & (col_bit); |
118 | swap_state[pos.row] & (col_bit); | ||
119 | 121 | ||
120 | if (do_swap) { | 122 | if (do_swap) { |
121 | event->key = hand_swap_config[pos.row][pos.col]; | 123 | event->key = hand_swap_config[pos.row][pos.col]; |
@@ -129,44 +131,36 @@ void process_hand_swap(keyevent_t *event) { | |||
129 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | 131 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
130 | bool disable_action_cache = false; | 132 | bool disable_action_cache = false; |
131 | 133 | ||
132 | void process_record_nocache(keyrecord_t *record) | 134 | void process_record_nocache(keyrecord_t *record) { |
133 | { | ||
134 | disable_action_cache = true; | 135 | disable_action_cache = true; |
135 | process_record(record); | 136 | process_record(record); |
136 | disable_action_cache = false; | 137 | disable_action_cache = false; |
137 | } | 138 | } |
138 | #else | 139 | #else |
139 | void process_record_nocache(keyrecord_t *record) | 140 | void process_record_nocache(keyrecord_t *record) { process_record(record); } |
140 | { | ||
141 | process_record(record); | ||
142 | } | ||
143 | #endif | 141 | #endif |
144 | 142 | ||
145 | __attribute__ ((weak)) | 143 | __attribute__((weak)) bool process_record_quantum(keyrecord_t *record) { return true; } |
146 | bool process_record_quantum(keyrecord_t *record) { | ||
147 | return true; | ||
148 | } | ||
149 | 144 | ||
150 | #ifndef NO_ACTION_TAPPING | 145 | #ifndef NO_ACTION_TAPPING |
151 | /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress. | 146 | /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress. |
152 | * | 147 | * |
153 | * FIXME: Needs documentation. | 148 | * FIXME: Needs documentation. |
154 | */ | 149 | */ |
155 | void process_record_tap_hint(keyrecord_t *record) | 150 | void process_record_tap_hint(keyrecord_t *record) { |
156 | { | ||
157 | action_t action = layer_switch_get_action(record->event.key); | 151 | action_t action = layer_switch_get_action(record->event.key); |
158 | 152 | ||
159 | switch (action.kind.id) { | 153 | switch (action.kind.id) { |
160 | #ifdef SWAP_HANDS_ENABLE | 154 | # ifdef SWAP_HANDS_ENABLE |
161 | case ACT_SWAP_HANDS: | 155 | case ACT_SWAP_HANDS: |
162 | switch (action.swap.code) { | 156 | switch (action.swap.code) { |
163 | case OP_SH_TAP_TOGGLE: | 157 | case OP_SH_TAP_TOGGLE: |
164 | default: | 158 | default: |
165 | swap_hands = !swap_hands; | 159 | swap_hands = !swap_hands; |
166 | swap_held = true; | 160 | swap_held = true; |
167 | } | 161 | } |
168 | break; | 162 | break; |
169 | #endif | 163 | # endif |
170 | } | 164 | } |
171 | } | 165 | } |
172 | #endif | 166 | #endif |
@@ -175,18 +169,21 @@ void process_record_tap_hint(keyrecord_t *record) | |||
175 | * | 169 | * |
176 | * FIXME: Needs documentation. | 170 | * FIXME: Needs documentation. |
177 | */ | 171 | */ |
178 | void process_record(keyrecord_t *record) | 172 | void process_record(keyrecord_t *record) { |
179 | { | 173 | if (IS_NOEVENT(record->event)) { |
180 | if (IS_NOEVENT(record->event)) { return; } | ||
181 | |||
182 | if(!process_record_quantum(record)) | ||
183 | return; | 174 | return; |
175 | } | ||
176 | |||
177 | if (!process_record_quantum(record)) return; | ||
184 | 178 | ||
185 | action_t action = store_or_get_action(record->event.pressed, record->event.key); | 179 | action_t action = store_or_get_action(record->event.pressed, record->event.key); |
186 | dprint("ACTION: "); debug_action(action); | 180 | dprint("ACTION: "); |
181 | debug_action(action); | ||
187 | #ifndef NO_ACTION_LAYER | 182 | #ifndef NO_ACTION_LAYER |
188 | dprint(" layer_state: "); layer_debug(); | 183 | dprint(" layer_state: "); |
189 | dprint(" default_layer_state: "); default_layer_debug(); | 184 | layer_debug(); |
185 | dprint(" default_layer_state: "); | ||
186 | default_layer_debug(); | ||
190 | #endif | 187 | #endif |
191 | dprintln(); | 188 | dprintln(); |
192 | 189 | ||
@@ -197,8 +194,7 @@ void process_record(keyrecord_t *record) | |||
197 | * | 194 | * |
198 | * FIXME: Needs documentation. | 195 | * FIXME: Needs documentation. |
199 | */ | 196 | */ |
200 | void process_action(keyrecord_t *record, action_t action) | 197 | void process_action(keyrecord_t *record, action_t action) { |
201 | { | ||
202 | keyevent_t event = record->event; | 198 | keyevent_t event = record->event; |
203 | #ifndef NO_ACTION_TAPPING | 199 | #ifndef NO_ACTION_TAPPING |
204 | uint8_t tap_count = record->tap.count; | 200 | uint8_t tap_count = record->tap.count; |
@@ -221,131 +217,125 @@ void process_action(keyrecord_t *record, action_t action) | |||
221 | switch (action.kind.id) { | 217 | switch (action.kind.id) { |
222 | /* Key and Mods */ | 218 | /* Key and Mods */ |
223 | case ACT_LMODS: | 219 | case ACT_LMODS: |
224 | case ACT_RMODS: | 220 | case ACT_RMODS: { |
225 | { | 221 | uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : action.key.mods << 4; |
226 | uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : | 222 | if (event.pressed) { |
227 | action.key.mods<<4; | 223 | if (mods) { |
228 | if (event.pressed) { | 224 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { |
229 | if (mods) { | 225 | // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless. |
230 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { | 226 | // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT). |
231 | // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless. | 227 | // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO). |
232 | // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT). | 228 | add_mods(mods); |
233 | // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO). | 229 | } else { |
234 | add_mods(mods); | 230 | add_weak_mods(mods); |
235 | } else { | ||
236 | add_weak_mods(mods); | ||
237 | } | ||
238 | send_keyboard_report(); | ||
239 | } | 231 | } |
240 | register_code(action.key.code); | 232 | send_keyboard_report(); |
241 | } else { | 233 | } |
242 | unregister_code(action.key.code); | 234 | register_code(action.key.code); |
243 | if (mods) { | 235 | } else { |
244 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { | 236 | unregister_code(action.key.code); |
245 | del_mods(mods); | 237 | if (mods) { |
246 | } else { | 238 | if (IS_MOD(action.key.code) || action.key.code == KC_NO) { |
247 | del_weak_mods(mods); | 239 | del_mods(mods); |
248 | } | 240 | } else { |
249 | send_keyboard_report(); | 241 | del_weak_mods(mods); |
250 | } | 242 | } |
243 | send_keyboard_report(); | ||
251 | } | 244 | } |
252 | } | 245 | } |
253 | break; | 246 | } break; |
254 | #ifndef NO_ACTION_TAPPING | 247 | #ifndef NO_ACTION_TAPPING |
255 | case ACT_LMODS_TAP: | 248 | case ACT_LMODS_TAP: |
256 | case ACT_RMODS_TAP: | 249 | case ACT_RMODS_TAP: { |
257 | { | 250 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : action.key.mods << 4; |
258 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : | 251 | switch (action.layer_tap.code) { |
259 | action.key.mods<<4; | 252 | # ifndef NO_ACTION_ONESHOT |
260 | switch (action.layer_tap.code) { | 253 | case MODS_ONESHOT: |
261 | #ifndef NO_ACTION_ONESHOT | 254 | // Oneshot modifier |
262 | case MODS_ONESHOT: | 255 | if (event.pressed) { |
263 | // Oneshot modifier | 256 | if (tap_count == 0) { |
264 | if (event.pressed) { | 257 | dprint("MODS_TAP: Oneshot: 0\n"); |
265 | if (tap_count == 0) { | 258 | register_mods(mods | get_oneshot_mods()); |
266 | dprint("MODS_TAP: Oneshot: 0\n"); | 259 | } else if (tap_count == 1) { |
267 | register_mods(mods | get_oneshot_mods()); | 260 | dprint("MODS_TAP: Oneshot: start\n"); |
268 | } else if (tap_count == 1) { | 261 | set_oneshot_mods(mods | get_oneshot_mods()); |
269 | dprint("MODS_TAP: Oneshot: start\n"); | 262 | # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 |
270 | set_oneshot_mods(mods | get_oneshot_mods()); | 263 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { |
271 | #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 | 264 | dprint("MODS_TAP: Toggling oneshot"); |
272 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { | 265 | clear_oneshot_mods(); |
273 | dprint("MODS_TAP: Toggling oneshot"); | 266 | set_oneshot_locked_mods(mods); |
274 | clear_oneshot_mods(); | 267 | register_mods(mods); |
275 | set_oneshot_locked_mods(mods); | 268 | # endif |
276 | register_mods(mods); | ||
277 | #endif | ||
278 | } else { | ||
279 | register_mods(mods | get_oneshot_mods()); | ||
280 | } | ||
281 | } else { | 269 | } else { |
282 | if (tap_count == 0) { | 270 | register_mods(mods | get_oneshot_mods()); |
283 | clear_oneshot_mods(); | 271 | } |
284 | unregister_mods(mods); | 272 | } else { |
285 | } else if (tap_count == 1) { | 273 | if (tap_count == 0) { |
286 | // Retain Oneshot mods | 274 | clear_oneshot_mods(); |
287 | #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 | 275 | unregister_mods(mods); |
288 | if (mods & get_mods()) { | 276 | } else if (tap_count == 1) { |
289 | clear_oneshot_locked_mods(); | 277 | // Retain Oneshot mods |
290 | clear_oneshot_mods(); | 278 | # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 |
291 | unregister_mods(mods); | 279 | if (mods & get_mods()) { |
292 | } | 280 | clear_oneshot_locked_mods(); |
293 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { | ||
294 | // Toggle Oneshot Layer | ||
295 | #endif | ||
296 | } else { | ||
297 | clear_oneshot_mods(); | 281 | clear_oneshot_mods(); |
298 | unregister_mods(mods); | 282 | unregister_mods(mods); |
299 | } | 283 | } |
284 | } else if (tap_count == ONESHOT_TAP_TOGGLE) { | ||
285 | // Toggle Oneshot Layer | ||
286 | # endif | ||
287 | } else { | ||
288 | clear_oneshot_mods(); | ||
289 | unregister_mods(mods); | ||
300 | } | 290 | } |
301 | break; | 291 | } |
302 | #endif | 292 | break; |
303 | case MODS_TAP_TOGGLE: | 293 | # endif |
304 | if (event.pressed) { | 294 | case MODS_TAP_TOGGLE: |
305 | if (tap_count <= TAPPING_TOGGLE) { | 295 | if (event.pressed) { |
296 | if (tap_count <= TAPPING_TOGGLE) { | ||
297 | register_mods(mods); | ||
298 | } | ||
299 | } else { | ||
300 | if (tap_count < TAPPING_TOGGLE) { | ||
301 | unregister_mods(mods); | ||
302 | } | ||
303 | } | ||
304 | break; | ||
305 | default: | ||
306 | if (event.pressed) { | ||
307 | if (tap_count > 0) { | ||
308 | # ifndef IGNORE_MOD_TAP_INTERRUPT | ||
309 | if (record->tap.interrupted) { | ||
310 | dprint("mods_tap: tap: cancel: add_mods\n"); | ||
311 | // ad hoc: set 0 to cancel tap | ||
312 | record->tap.count = 0; | ||
306 | register_mods(mods); | 313 | register_mods(mods); |
314 | } else | ||
315 | # endif | ||
316 | { | ||
317 | dprint("MODS_TAP: Tap: register_code\n"); | ||
318 | register_code(action.key.code); | ||
307 | } | 319 | } |
308 | } else { | 320 | } else { |
309 | if (tap_count < TAPPING_TOGGLE) { | 321 | dprint("MODS_TAP: No tap: add_mods\n"); |
310 | unregister_mods(mods); | 322 | register_mods(mods); |
311 | } | ||
312 | } | 323 | } |
313 | break; | 324 | } else { |
314 | default: | 325 | if (tap_count > 0) { |
315 | if (event.pressed) { | 326 | dprint("MODS_TAP: Tap: unregister_code\n"); |
316 | if (tap_count > 0) { | 327 | if (action.layer_tap.code == KC_CAPS) { |
317 | #ifndef IGNORE_MOD_TAP_INTERRUPT | 328 | wait_ms(TAP_HOLD_CAPS_DELAY); |
318 | if (record->tap.interrupted) { | ||
319 | dprint("mods_tap: tap: cancel: add_mods\n"); | ||
320 | // ad hoc: set 0 to cancel tap | ||
321 | record->tap.count = 0; | ||
322 | register_mods(mods); | ||
323 | } else | ||
324 | #endif | ||
325 | { | ||
326 | dprint("MODS_TAP: Tap: register_code\n"); | ||
327 | register_code(action.key.code); | ||
328 | } | ||
329 | } else { | ||
330 | dprint("MODS_TAP: No tap: add_mods\n"); | ||
331 | register_mods(mods); | ||
332 | } | 329 | } |
330 | unregister_code(action.key.code); | ||
333 | } else { | 331 | } else { |
334 | if (tap_count > 0) { | 332 | dprint("MODS_TAP: No tap: add_mods\n"); |
335 | dprint("MODS_TAP: Tap: unregister_code\n"); | 333 | unregister_mods(mods); |
336 | if (action.layer_tap.code == KC_CAPS) { | ||
337 | wait_ms(TAP_HOLD_CAPS_DELAY); | ||
338 | } | ||
339 | unregister_code(action.key.code); | ||
340 | } else { | ||
341 | dprint("MODS_TAP: No tap: add_mods\n"); | ||
342 | unregister_mods(mods); | ||
343 | } | ||
344 | } | 334 | } |
345 | break; | 335 | } |
346 | } | 336 | break; |
347 | } | 337 | } |
348 | break; | 338 | } break; |
349 | #endif | 339 | #endif |
350 | #ifdef EXTRAKEY_ENABLE | 340 | #ifdef EXTRAKEY_ENABLE |
351 | /* other HID usage */ | 341 | /* other HID usage */ |
@@ -374,13 +364,13 @@ void process_action(keyrecord_t *record, action_t action) | |||
374 | if (event.pressed) { | 364 | if (event.pressed) { |
375 | switch (action.key.code) { | 365 | switch (action.key.code) { |
376 | case KC_MS_BTN1: | 366 | case KC_MS_BTN1: |
377 | tp_buttons |= (1<<0); | 367 | tp_buttons |= (1 << 0); |
378 | break; | 368 | break; |
379 | case KC_MS_BTN2: | 369 | case KC_MS_BTN2: |
380 | tp_buttons |= (1<<1); | 370 | tp_buttons |= (1 << 1); |
381 | break; | 371 | break; |
382 | case KC_MS_BTN3: | 372 | case KC_MS_BTN3: |
383 | tp_buttons |= (1<<2); | 373 | tp_buttons |= (1 << 2); |
384 | break; | 374 | break; |
385 | default: | 375 | default: |
386 | break; | 376 | break; |
@@ -390,13 +380,13 @@ void process_action(keyrecord_t *record, action_t action) | |||
390 | } else { | 380 | } else { |
391 | switch (action.key.code) { | 381 | switch (action.key.code) { |
392 | case KC_MS_BTN1: | 382 | case KC_MS_BTN1: |
393 | tp_buttons &= ~(1<<0); | 383 | tp_buttons &= ~(1 << 0); |
394 | break; | 384 | break; |
395 | case KC_MS_BTN2: | 385 | case KC_MS_BTN2: |
396 | tp_buttons &= ~(1<<1); | 386 | tp_buttons &= ~(1 << 1); |
397 | break; | 387 | break; |
398 | case KC_MS_BTN3: | 388 | case KC_MS_BTN3: |
399 | tp_buttons &= ~(1<<2); | 389 | tp_buttons &= ~(1 << 2); |
400 | break; | 390 | break; |
401 | default: | 391 | default: |
402 | break; | 392 | break; |
@@ -411,28 +401,43 @@ void process_action(keyrecord_t *record, action_t action) | |||
411 | if (action.layer_bitop.on == 0) { | 401 | if (action.layer_bitop.on == 0) { |
412 | /* Default Layer Bitwise Operation */ | 402 | /* Default Layer Bitwise Operation */ |
413 | if (!event.pressed) { | 403 | if (!event.pressed) { |
414 | uint8_t shift = action.layer_bitop.part*4; | 404 | uint8_t shift = action.layer_bitop.part * 4; |
415 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift; | 405 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift; |
416 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0; | 406 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0; |
417 | switch (action.layer_bitop.op) { | 407 | switch (action.layer_bitop.op) { |
418 | case OP_BIT_AND: default_layer_and(bits | mask); break; | 408 | case OP_BIT_AND: |
419 | case OP_BIT_OR: default_layer_or(bits | mask); break; | 409 | default_layer_and(bits | mask); |
420 | case OP_BIT_XOR: default_layer_xor(bits | mask); break; | 410 | break; |
421 | case OP_BIT_SET: default_layer_set(bits | mask); break; | 411 | case OP_BIT_OR: |
412 | default_layer_or(bits | mask); | ||
413 | break; | ||
414 | case OP_BIT_XOR: | ||
415 | default_layer_xor(bits | mask); | ||
416 | break; | ||
417 | case OP_BIT_SET: | ||
418 | default_layer_set(bits | mask); | ||
419 | break; | ||
422 | } | 420 | } |
423 | } | 421 | } |
424 | } else { | 422 | } else { |
425 | /* Layer Bitwise Operation */ | 423 | /* Layer Bitwise Operation */ |
426 | if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : | 424 | if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : (action.layer_bitop.on & ON_RELEASE)) { |
427 | (action.layer_bitop.on & ON_RELEASE)) { | 425 | uint8_t shift = action.layer_bitop.part * 4; |
428 | uint8_t shift = action.layer_bitop.part*4; | 426 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift; |
429 | layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift; | 427 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0; |
430 | layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0; | ||
431 | switch (action.layer_bitop.op) { | 428 | switch (action.layer_bitop.op) { |
432 | case OP_BIT_AND: layer_and(bits | mask); break; | 429 | case OP_BIT_AND: |
433 | case OP_BIT_OR: layer_or(bits | mask); break; | 430 | layer_and(bits | mask); |
434 | case OP_BIT_XOR: layer_xor(bits | mask); break; | 431 | break; |
435 | case OP_BIT_SET: layer_state_set(bits | mask); break; | 432 | case OP_BIT_OR: |
433 | layer_or(bits | mask); | ||
434 | break; | ||
435 | case OP_BIT_XOR: | ||
436 | layer_xor(bits | mask); | ||
437 | break; | ||
438 | case OP_BIT_SET: | ||
439 | layer_state_set(bits | mask); | ||
440 | break; | ||
436 | } | 441 | } |
437 | } | 442 | } |
438 | } | 443 | } |
@@ -446,7 +451,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
446 | layer_off(action.layer_mods.layer); | 451 | layer_off(action.layer_mods.layer); |
447 | } | 452 | } |
448 | break; | 453 | break; |
449 | #ifndef NO_ACTION_TAPPING | 454 | # ifndef NO_ACTION_TAPPING |
450 | case ACT_LAYER_TAP: | 455 | case ACT_LAYER_TAP: |
451 | case ACT_LAYER_TAP_EXT: | 456 | case ACT_LAYER_TAP_EXT: |
452 | switch (action.layer_tap.code) { | 457 | switch (action.layer_tap.code) { |
@@ -463,21 +468,18 @@ void process_action(keyrecord_t *record, action_t action) | |||
463 | } | 468 | } |
464 | break; | 469 | break; |
465 | case OP_ON_OFF: | 470 | case OP_ON_OFF: |
466 | event.pressed ? layer_on(action.layer_tap.val) : | 471 | event.pressed ? layer_on(action.layer_tap.val) : layer_off(action.layer_tap.val); |
467 | layer_off(action.layer_tap.val); | ||
468 | break; | 472 | break; |
469 | case OP_OFF_ON: | 473 | case OP_OFF_ON: |
470 | event.pressed ? layer_off(action.layer_tap.val) : | 474 | event.pressed ? layer_off(action.layer_tap.val) : layer_on(action.layer_tap.val); |
471 | layer_on(action.layer_tap.val); | ||
472 | break; | 475 | break; |
473 | case OP_SET_CLEAR: | 476 | case OP_SET_CLEAR: |
474 | event.pressed ? layer_move(action.layer_tap.val) : | 477 | event.pressed ? layer_move(action.layer_tap.val) : layer_clear(); |
475 | layer_clear(); | ||
476 | break; | 478 | break; |
477 | #ifndef NO_ACTION_ONESHOT | 479 | # ifndef NO_ACTION_ONESHOT |
478 | case OP_ONESHOT: | 480 | case OP_ONESHOT: |
479 | // Oneshot modifier | 481 | // Oneshot modifier |
480 | #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 | 482 | # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 |
481 | do_release_oneshot = false; | 483 | do_release_oneshot = false; |
482 | if (event.pressed) { | 484 | if (event.pressed) { |
483 | del_mods(get_oneshot_locked_mods()); | 485 | del_mods(get_oneshot_locked_mods()); |
@@ -499,7 +501,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
499 | clear_oneshot_layer_state(ONESHOT_PRESSED); | 501 | clear_oneshot_layer_state(ONESHOT_PRESSED); |
500 | } | 502 | } |
501 | } | 503 | } |
502 | #else | 504 | # else |
503 | if (event.pressed) { | 505 | if (event.pressed) { |
504 | layer_on(action.layer_tap.val); | 506 | layer_on(action.layer_tap.val); |
505 | set_oneshot_layer(action.layer_tap.val, ONESHOT_START); | 507 | set_oneshot_layer(action.layer_tap.val, ONESHOT_START); |
@@ -509,9 +511,9 @@ void process_action(keyrecord_t *record, action_t action) | |||
509 | clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); | 511 | clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); |
510 | } | 512 | } |
511 | } | 513 | } |
512 | #endif | 514 | # endif |
513 | break; | 515 | break; |
514 | #endif | 516 | # endif |
515 | default: | 517 | default: |
516 | /* tap key */ | 518 | /* tap key */ |
517 | if (event.pressed) { | 519 | if (event.pressed) { |
@@ -529,7 +531,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
529 | wait_ms(TAP_HOLD_CAPS_DELAY); | 531 | wait_ms(TAP_HOLD_CAPS_DELAY); |
530 | } else { | 532 | } else { |
531 | wait_ms(TAP_CODE_DELAY); | 533 | wait_ms(TAP_CODE_DELAY); |
532 | } | 534 | } |
533 | unregister_code(action.layer_tap.code); | 535 | unregister_code(action.layer_tap.code); |
534 | } else { | 536 | } else { |
535 | dprint("KEYMAP_TAP_KEY: No tap: Off on release\n"); | 537 | dprint("KEYMAP_TAP_KEY: No tap: Off on release\n"); |
@@ -539,9 +541,9 @@ void process_action(keyrecord_t *record, action_t action) | |||
539 | break; | 541 | break; |
540 | } | 542 | } |
541 | break; | 543 | break; |
542 | #endif | 544 | # endif |
543 | #endif | 545 | #endif |
544 | /* Extentions */ | 546 | /* Extentions */ |
545 | #ifndef NO_ACTION_MACRO | 547 | #ifndef NO_ACTION_MACRO |
546 | case ACT_MACRO: | 548 | case ACT_MACRO: |
547 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); | 549 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); |
@@ -599,7 +601,7 @@ void process_action(keyrecord_t *record, action_t action) | |||
599 | swap_hands = false; | 601 | swap_hands = false; |
600 | } | 602 | } |
601 | break; | 603 | break; |
602 | #ifndef NO_ACTION_TAPPING | 604 | # ifndef NO_ACTION_TAPPING |
603 | case OP_SH_TAP_TOGGLE: | 605 | case OP_SH_TAP_TOGGLE: |
604 | /* tap toggle */ | 606 | /* tap toggle */ |
605 | 607 | ||
@@ -619,23 +621,23 @@ void process_action(keyrecord_t *record, action_t action) | |||
619 | /* tap key */ | 621 | /* tap key */ |
620 | if (tap_count > 0) { | 622 | if (tap_count > 0) { |
621 | if (swap_held) { | 623 | if (swap_held) { |
622 | swap_hands = !swap_hands; // undo hold set up in _tap_hint | 624 | swap_hands = !swap_hands; // undo hold set up in _tap_hint |
623 | swap_held = false; | 625 | swap_held = false; |
624 | } | 626 | } |
625 | if (event.pressed) { | 627 | if (event.pressed) { |
626 | register_code(action.swap.code); | 628 | register_code(action.swap.code); |
627 | } else { | 629 | } else { |
628 | wait_ms(TAP_CODE_DELAY); | 630 | wait_ms(TAP_CODE_DELAY); |
629 | unregister_code(action.swap.code); | 631 | unregister_code(action.swap.code); |
630 | *record = (keyrecord_t){}; // hack: reset tap mode | 632 | *record = (keyrecord_t){}; // hack: reset tap mode |
631 | } | 633 | } |
632 | } else { | 634 | } else { |
633 | if (swap_held && !event.pressed) { | 635 | if (swap_held && !event.pressed) { |
634 | swap_hands = !swap_hands; // undo hold set up in _tap_hint | 636 | swap_hands = !swap_hands; // undo hold set up in _tap_hint |
635 | swap_held = false; | 637 | swap_held = false; |
636 | } | 638 | } |
637 | } | 639 | } |
638 | #endif | 640 | # endif |
639 | } | 641 | } |
640 | #endif | 642 | #endif |
641 | #ifndef NO_ACTION_FUNCTION | 643 | #ifndef NO_ACTION_FUNCTION |
@@ -652,10 +654,10 @@ void process_action(keyrecord_t *record, action_t action) | |||
652 | switch (action.kind.id) { | 654 | switch (action.kind.id) { |
653 | case ACT_LAYER: | 655 | case ACT_LAYER: |
654 | case ACT_LAYER_MODS: | 656 | case ACT_LAYER_MODS: |
655 | #ifndef NO_ACTION_TAPPING | 657 | # ifndef NO_ACTION_TAPPING |
656 | case ACT_LAYER_TAP: | 658 | case ACT_LAYER_TAP: |
657 | case ACT_LAYER_TAP_EXT: | 659 | case ACT_LAYER_TAP_EXT: |
658 | #endif | 660 | # endif |
659 | led_set(host_keyboard_leds()); | 661 | led_set(host_keyboard_leds()); |
660 | break; | 662 | break; |
661 | default: | 663 | default: |
@@ -664,35 +666,34 @@ void process_action(keyrecord_t *record, action_t action) | |||
664 | #endif | 666 | #endif |
665 | 667 | ||
666 | #ifndef NO_ACTION_TAPPING | 668 | #ifndef NO_ACTION_TAPPING |
667 | #ifdef RETRO_TAPPING | 669 | # ifdef RETRO_TAPPING |
668 | if (!is_tap_action(action)) { | 670 | if (!is_tap_action(action)) { |
669 | retro_tapping_counter = 0; | ||
670 | } else { | ||
671 | if (event.pressed) { | ||
672 | if (tap_count > 0) { | ||
673 | retro_tapping_counter = 0; | ||
674 | } else { | ||
675 | |||
676 | } | ||
677 | } else { | ||
678 | if (tap_count > 0) { | ||
679 | retro_tapping_counter = 0; | 671 | retro_tapping_counter = 0; |
680 | } else { | 672 | } else { |
681 | if (retro_tapping_counter == 2) { | 673 | if (event.pressed) { |
682 | tap_code(action.layer_tap.code); | 674 | if (tap_count > 0) { |
675 | retro_tapping_counter = 0; | ||
676 | } else { | ||
677 | } | ||
678 | } else { | ||
679 | if (tap_count > 0) { | ||
680 | retro_tapping_counter = 0; | ||
681 | } else { | ||
682 | if (retro_tapping_counter == 2) { | ||
683 | tap_code(action.layer_tap.code); | ||
684 | } | ||
685 | retro_tapping_counter = 0; | ||
686 | } | ||
683 | } | 687 | } |
684 | retro_tapping_counter = 0; | ||
685 | } | ||
686 | } | 688 | } |
687 | } | 689 | # endif |
688 | #endif | ||
689 | #endif | 690 | #endif |
690 | 691 | ||
691 | #ifndef NO_ACTION_ONESHOT | 692 | #ifndef NO_ACTION_ONESHOT |
692 | /* Because we switch layers after a oneshot event, we need to release the | 693 | /* Because we switch layers after a oneshot event, we need to release the |
693 | * key before we leave the layer or no key up event will be generated. | 694 | * key before we leave the layer or no key up event will be generated. |
694 | */ | 695 | */ |
695 | if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) { | 696 | if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED)) { |
696 | record->event.pressed = false; | 697 | record->event.pressed = false; |
697 | layer_on(get_oneshot_layer()); | 698 | layer_on(get_oneshot_layer()); |
698 | process_record(record); | 699 | process_record(record); |
@@ -701,25 +702,20 @@ void process_action(keyrecord_t *record, action_t action) | |||
701 | #endif | 702 | #endif |
702 | } | 703 | } |
703 | 704 | ||
704 | |||
705 | |||
706 | |||
707 | /** \brief Utilities for actions. (FIXME: Needs better description) | 705 | /** \brief Utilities for actions. (FIXME: Needs better description) |
708 | * | 706 | * |
709 | * FIXME: Needs documentation. | 707 | * FIXME: Needs documentation. |
710 | */ | 708 | */ |
711 | void register_code(uint8_t code) | 709 | void register_code(uint8_t code) { |
712 | { | ||
713 | if (code == KC_NO) { | 710 | if (code == KC_NO) { |
714 | return; | 711 | return; |
715 | } | 712 | } |
716 | |||
717 | #ifdef LOCKING_SUPPORT_ENABLE | 713 | #ifdef LOCKING_SUPPORT_ENABLE |
718 | else if (KC_LOCKING_CAPS == code) { | 714 | else if (KC_LOCKING_CAPS == code) { |
719 | #ifdef LOCKING_RESYNC_ENABLE | 715 | # ifdef LOCKING_RESYNC_ENABLE |
720 | // Resync: ignore if caps lock already is on | 716 | // Resync: ignore if caps lock already is on |
721 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; | 717 | if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return; |
722 | #endif | 718 | # endif |
723 | add_key(KC_CAPSLOCK); | 719 | add_key(KC_CAPSLOCK); |
724 | send_keyboard_report(); | 720 | send_keyboard_report(); |
725 | wait_ms(100); | 721 | wait_ms(100); |
@@ -728,9 +724,9 @@ void register_code(uint8_t code) | |||
728 | } | 724 | } |
729 | 725 | ||
730 | else if (KC_LOCKING_NUM == code) { | 726 | else if (KC_LOCKING_NUM == code) { |
731 | #ifdef LOCKING_RESYNC_ENABLE | 727 | # ifdef LOCKING_RESYNC_ENABLE |
732 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; | 728 | if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return; |
733 | #endif | 729 | # endif |
734 | add_key(KC_NUMLOCK); | 730 | add_key(KC_NUMLOCK); |
735 | send_keyboard_report(); | 731 | send_keyboard_report(); |
736 | wait_ms(100); | 732 | wait_ms(100); |
@@ -739,9 +735,9 @@ void register_code(uint8_t code) | |||
739 | } | 735 | } |
740 | 736 | ||
741 | else if (KC_LOCKING_SCROLL == code) { | 737 | else if (KC_LOCKING_SCROLL == code) { |
742 | #ifdef LOCKING_RESYNC_ENABLE | 738 | # ifdef LOCKING_RESYNC_ENABLE |
743 | if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return; | 739 | if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return; |
744 | #endif | 740 | # endif |
745 | add_key(KC_SCROLLLOCK); | 741 | add_key(KC_SCROLLLOCK); |
746 | send_keyboard_report(); | 742 | send_keyboard_report(); |
747 | wait_ms(100); | 743 | wait_ms(100); |
@@ -750,9 +746,10 @@ void register_code(uint8_t code) | |||
750 | } | 746 | } |
751 | #endif | 747 | #endif |
752 | 748 | ||
753 | else if IS_KEY(code) { | 749 | else if |
754 | // TODO: should push command_proc out of this block? | 750 | IS_KEY(code) { |
755 | if (command_proc(code)) return; | 751 | // TODO: should push command_proc out of this block? |
752 | if (command_proc(code)) return; | ||
756 | 753 | ||
757 | #ifndef NO_ACTION_ONESHOT | 754 | #ifndef NO_ACTION_ONESHOT |
758 | /* TODO: remove | 755 | /* TODO: remove |
@@ -769,46 +766,44 @@ void register_code(uint8_t code) | |||
769 | } else | 766 | } else |
770 | */ | 767 | */ |
771 | #endif | 768 | #endif |
772 | { | 769 | { |
773 | add_key(code); | 770 | add_key(code); |
771 | send_keyboard_report(); | ||
772 | } | ||
773 | } | ||
774 | else if | ||
775 | IS_MOD(code) { | ||
776 | add_mods(MOD_BIT(code)); | ||
774 | send_keyboard_report(); | 777 | send_keyboard_report(); |
775 | } | 778 | } |
776 | } | 779 | else if |
777 | else if IS_MOD(code) { | 780 | IS_SYSTEM(code) { host_system_send(KEYCODE2SYSTEM(code)); } |
778 | add_mods(MOD_BIT(code)); | 781 | else if |
779 | send_keyboard_report(); | 782 | IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); } |
780 | } | ||
781 | else if IS_SYSTEM(code) { | ||
782 | host_system_send(KEYCODE2SYSTEM(code)); | ||
783 | } | ||
784 | else if IS_CONSUMER(code) { | ||
785 | host_consumer_send(KEYCODE2CONSUMER(code)); | ||
786 | } | ||
787 | 783 | ||
788 | #ifdef MOUSEKEY_ENABLE | 784 | #ifdef MOUSEKEY_ENABLE |
789 | else if IS_MOUSEKEY(code) { | 785 | else if |
790 | mousekey_on(code); | 786 | IS_MOUSEKEY(code) { |
791 | mousekey_send(); | 787 | mousekey_on(code); |
792 | } | 788 | mousekey_send(); |
793 | #endif | 789 | } |
790 | #endif | ||
794 | } | 791 | } |
795 | 792 | ||
796 | /** \brief Utilities for actions. (FIXME: Needs better description) | 793 | /** \brief Utilities for actions. (FIXME: Needs better description) |
797 | * | 794 | * |
798 | * FIXME: Needs documentation. | 795 | * FIXME: Needs documentation. |
799 | */ | 796 | */ |
800 | void unregister_code(uint8_t code) | 797 | void unregister_code(uint8_t code) { |
801 | { | ||
802 | if (code == KC_NO) { | 798 | if (code == KC_NO) { |
803 | return; | 799 | return; |
804 | } | 800 | } |
805 | |||
806 | #ifdef LOCKING_SUPPORT_ENABLE | 801 | #ifdef LOCKING_SUPPORT_ENABLE |
807 | else if (KC_LOCKING_CAPS == code) { | 802 | else if (KC_LOCKING_CAPS == code) { |
808 | #ifdef LOCKING_RESYNC_ENABLE | 803 | # ifdef LOCKING_RESYNC_ENABLE |
809 | // Resync: ignore if caps lock already is off | 804 | // Resync: ignore if caps lock already is off |
810 | if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; | 805 | if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return; |
811 | #endif | 806 | # endif |
812 | add_key(KC_CAPSLOCK); | 807 | add_key(KC_CAPSLOCK); |
813 | send_keyboard_report(); | 808 | send_keyboard_report(); |
814 | del_key(KC_CAPSLOCK); | 809 | del_key(KC_CAPSLOCK); |
@@ -816,9 +811,9 @@ void unregister_code(uint8_t code) | |||
816 | } | 811 | } |
817 | 812 | ||
818 | else if (KC_LOCKING_NUM == code) { | 813 | else if (KC_LOCKING_NUM == code) { |
819 | #ifdef LOCKING_RESYNC_ENABLE | 814 | # ifdef LOCKING_RESYNC_ENABLE |
820 | if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; | 815 | if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return; |
821 | #endif | 816 | # endif |
822 | add_key(KC_NUMLOCK); | 817 | add_key(KC_NUMLOCK); |
823 | send_keyboard_report(); | 818 | send_keyboard_report(); |
824 | del_key(KC_NUMLOCK); | 819 | del_key(KC_NUMLOCK); |
@@ -826,9 +821,9 @@ void unregister_code(uint8_t code) | |||
826 | } | 821 | } |
827 | 822 | ||
828 | else if (KC_LOCKING_SCROLL == code) { | 823 | else if (KC_LOCKING_SCROLL == code) { |
829 | #ifdef LOCKING_RESYNC_ENABLE | 824 | # ifdef LOCKING_RESYNC_ENABLE |
830 | if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return; | 825 | if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return; |
831 | #endif | 826 | # endif |
832 | add_key(KC_SCROLLLOCK); | 827 | add_key(KC_SCROLLLOCK); |
833 | send_keyboard_report(); | 828 | send_keyboard_report(); |
834 | del_key(KC_SCROLLLOCK); | 829 | del_key(KC_SCROLLLOCK); |
@@ -836,26 +831,27 @@ void unregister_code(uint8_t code) | |||
836 | } | 831 | } |
837 | #endif | 832 | #endif |
838 | 833 | ||
839 | else if IS_KEY(code) { | 834 | else if |
840 | del_key(code); | 835 | IS_KEY(code) { |
841 | send_keyboard_report(); | 836 | del_key(code); |
842 | } | 837 | send_keyboard_report(); |
843 | else if IS_MOD(code) { | 838 | } |
844 | del_mods(MOD_BIT(code)); | 839 | else if |
845 | send_keyboard_report(); | 840 | IS_MOD(code) { |
846 | } | 841 | del_mods(MOD_BIT(code)); |
847 | else if IS_SYSTEM(code) { | 842 | send_keyboard_report(); |
848 | host_system_send(0); | 843 | } |
849 | } | 844 | else if |
850 | else if IS_CONSUMER(code) { | 845 | IS_SYSTEM(code) { host_system_send(0); } |
851 | host_consumer_send(0); | 846 | else if |
852 | } | 847 | IS_CONSUMER(code) { host_consumer_send(0); } |
853 | #ifdef MOUSEKEY_ENABLE | 848 | #ifdef MOUSEKEY_ENABLE |
854 | else if IS_MOUSEKEY(code) { | 849 | else if |
855 | mousekey_off(code); | 850 | IS_MOUSEKEY(code) { |
856 | mousekey_send(); | 851 | mousekey_off(code); |
857 | } | 852 | mousekey_send(); |
858 | #endif | 853 | } |
854 | #endif | ||
859 | } | 855 | } |
860 | 856 | ||
861 | /** \brief Utilities for actions. (FIXME: Needs better description) | 857 | /** \brief Utilities for actions. (FIXME: Needs better description) |
@@ -863,21 +859,20 @@ void unregister_code(uint8_t code) | |||
863 | * FIXME: Needs documentation. | 859 | * FIXME: Needs documentation. |
864 | */ | 860 | */ |
865 | void tap_code(uint8_t code) { | 861 | void tap_code(uint8_t code) { |
866 | register_code(code); | 862 | register_code(code); |
867 | if (code == KC_CAPS) { | 863 | if (code == KC_CAPS) { |
868 | wait_ms(TAP_HOLD_CAPS_DELAY); | 864 | wait_ms(TAP_HOLD_CAPS_DELAY); |
869 | } else { | 865 | } else { |
870 | wait_ms(TAP_CODE_DELAY); | 866 | wait_ms(TAP_CODE_DELAY); |
871 | } | 867 | } |
872 | unregister_code(code); | 868 | unregister_code(code); |
873 | } | 869 | } |
874 | 870 | ||
875 | /** \brief Utilities for actions. (FIXME: Needs better description) | 871 | /** \brief Utilities for actions. (FIXME: Needs better description) |
876 | * | 872 | * |
877 | * FIXME: Needs documentation. | 873 | * FIXME: Needs documentation. |
878 | */ | 874 | */ |
879 | void register_mods(uint8_t mods) | 875 | void register_mods(uint8_t mods) { |
880 | { | ||
881 | if (mods) { | 876 | if (mods) { |
882 | add_mods(mods); | 877 | add_mods(mods); |
883 | send_keyboard_report(); | 878 | send_keyboard_report(); |
@@ -888,8 +883,7 @@ void register_mods(uint8_t mods) | |||
888 | * | 883 | * |
889 | * FIXME: Needs documentation. | 884 | * FIXME: Needs documentation. |
890 | */ | 885 | */ |
891 | void unregister_mods(uint8_t mods) | 886 | void unregister_mods(uint8_t mods) { |
892 | { | ||
893 | if (mods) { | 887 | if (mods) { |
894 | del_mods(mods); | 888 | del_mods(mods); |
895 | send_keyboard_report(); | 889 | send_keyboard_report(); |
@@ -900,8 +894,7 @@ void unregister_mods(uint8_t mods) | |||
900 | * | 894 | * |
901 | * FIXME: Needs documentation. | 895 | * FIXME: Needs documentation. |
902 | */ | 896 | */ |
903 | void clear_keyboard(void) | 897 | void clear_keyboard(void) { |
904 | { | ||
905 | clear_mods(); | 898 | clear_mods(); |
906 | clear_keyboard_but_mods(); | 899 | clear_keyboard_but_mods(); |
907 | } | 900 | } |
@@ -910,8 +903,7 @@ void clear_keyboard(void) | |||
910 | * | 903 | * |
911 | * FIXME: Needs documentation. | 904 | * FIXME: Needs documentation. |
912 | */ | 905 | */ |
913 | void clear_keyboard_but_mods(void) | 906 | void clear_keyboard_but_mods(void) { |
914 | { | ||
915 | clear_keys(); | 907 | clear_keys(); |
916 | clear_keyboard_but_mods_and_keys(); | 908 | clear_keyboard_but_mods_and_keys(); |
917 | } | 909 | } |
@@ -920,8 +912,7 @@ void clear_keyboard_but_mods(void) | |||
920 | * | 912 | * |
921 | * FIXME: Needs documentation. | 913 | * FIXME: Needs documentation. |
922 | */ | 914 | */ |
923 | void clear_keyboard_but_mods_and_keys() | 915 | void clear_keyboard_but_mods_and_keys() { |
924 | { | ||
925 | clear_weak_mods(); | 916 | clear_weak_mods(); |
926 | clear_macro_mods(); | 917 | clear_macro_mods(); |
927 | send_keyboard_report(); | 918 | send_keyboard_report(); |
@@ -939,8 +930,7 @@ void clear_keyboard_but_mods_and_keys() | |||
939 | * | 930 | * |
940 | * FIXME: Needs documentation. | 931 | * FIXME: Needs documentation. |
941 | */ | 932 | */ |
942 | bool is_tap_key(keypos_t key) | 933 | bool is_tap_key(keypos_t key) { |
943 | { | ||
944 | action_t action = layer_switch_get_action(key); | 934 | action_t action = layer_switch_get_action(key); |
945 | return is_tap_action(action); | 935 | return is_tap_action(action); |
946 | } | 936 | } |
@@ -949,8 +939,7 @@ bool is_tap_key(keypos_t key) | |||
949 | * | 939 | * |
950 | * FIXME: Needs documentation. | 940 | * FIXME: Needs documentation. |
951 | */ | 941 | */ |
952 | bool is_tap_action(action_t action) | 942 | bool is_tap_action(action_t action) { |
953 | { | ||
954 | switch (action.kind.id) { | 943 | switch (action.kind.id) { |
955 | case ACT_LMODS_TAP: | 944 | case ACT_LMODS_TAP: |
956 | case ACT_RMODS_TAP: | 945 | case ACT_RMODS_TAP: |
@@ -972,28 +961,25 @@ bool is_tap_action(action_t action) | |||
972 | return false; | 961 | return false; |
973 | case ACT_MACRO: | 962 | case ACT_MACRO: |
974 | case ACT_FUNCTION: | 963 | case ACT_FUNCTION: |
975 | if (action.func.opt & FUNC_TAP) { return true; } | 964 | if (action.func.opt & FUNC_TAP) { |
965 | return true; | ||
966 | } | ||
976 | return false; | 967 | return false; |
977 | } | 968 | } |
978 | return false; | 969 | return false; |
979 | } | 970 | } |
980 | 971 | ||
981 | |||
982 | /** \brief Debug print (FIXME: Needs better description) | 972 | /** \brief Debug print (FIXME: Needs better description) |
983 | * | 973 | * |
984 | * FIXME: Needs documentation. | 974 | * FIXME: Needs documentation. |
985 | */ | 975 | */ |
986 | void debug_event(keyevent_t event) | 976 | void debug_event(keyevent_t event) { dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); } |
987 | { | ||
988 | dprintf("%04X%c(%u)", (event.key.row<<8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); | ||
989 | } | ||
990 | 977 | ||
991 | /** \brief Debug print (FIXME: Needs better description) | 978 | /** \brief Debug print (FIXME: Needs better description) |
992 | * | 979 | * |
993 | * FIXME: Needs documentation. | 980 | * FIXME: Needs documentation. |
994 | */ | 981 | */ |
995 | void debug_record(keyrecord_t record) | 982 | void debug_record(keyrecord_t record) { |
996 | { | ||
997 | debug_event(record.event); | 983 | debug_event(record.event); |
998 | #ifndef NO_ACTION_TAPPING | 984 | #ifndef NO_ACTION_TAPPING |
999 | dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' ')); | 985 | dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' ')); |
@@ -1004,24 +990,53 @@ void debug_record(keyrecord_t record) | |||
1004 | * | 990 | * |
1005 | * FIXME: Needs documentation. | 991 | * FIXME: Needs documentation. |
1006 | */ | 992 | */ |
1007 | void debug_action(action_t action) | 993 | void debug_action(action_t action) { |
1008 | { | ||
1009 | switch (action.kind.id) { | 994 | switch (action.kind.id) { |
1010 | case ACT_LMODS: dprint("ACT_LMODS"); break; | 995 | case ACT_LMODS: |
1011 | case ACT_RMODS: dprint("ACT_RMODS"); break; | 996 | dprint("ACT_LMODS"); |
1012 | case ACT_LMODS_TAP: dprint("ACT_LMODS_TAP"); break; | 997 | break; |
1013 | case ACT_RMODS_TAP: dprint("ACT_RMODS_TAP"); break; | 998 | case ACT_RMODS: |
1014 | case ACT_USAGE: dprint("ACT_USAGE"); break; | 999 | dprint("ACT_RMODS"); |
1015 | case ACT_MOUSEKEY: dprint("ACT_MOUSEKEY"); break; | 1000 | break; |
1016 | case ACT_LAYER: dprint("ACT_LAYER"); break; | 1001 | case ACT_LMODS_TAP: |
1017 | case ACT_LAYER_MODS: dprint("ACT_LAYER_MODS"); break; | 1002 | dprint("ACT_LMODS_TAP"); |
1018 | case ACT_LAYER_TAP: dprint("ACT_LAYER_TAP"); break; | 1003 | break; |
1019 | case ACT_LAYER_TAP_EXT: dprint("ACT_LAYER_TAP_EXT"); break; | 1004 | case ACT_RMODS_TAP: |
1020 | case ACT_MACRO: dprint("ACT_MACRO"); break; | 1005 | dprint("ACT_RMODS_TAP"); |
1021 | case ACT_COMMAND: dprint("ACT_COMMAND"); break; | 1006 | break; |
1022 | case ACT_FUNCTION: dprint("ACT_FUNCTION"); break; | 1007 | case ACT_USAGE: |
1023 | case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break; | 1008 | dprint("ACT_USAGE"); |
1024 | default: dprint("UNKNOWN"); break; | 1009 | break; |
1010 | case ACT_MOUSEKEY: | ||
1011 | dprint("ACT_MOUSEKEY"); | ||
1012 | break; | ||
1013 | case ACT_LAYER: | ||
1014 | dprint("ACT_LAYER"); | ||
1015 | break; | ||
1016 | case ACT_LAYER_MODS: | ||
1017 | dprint("ACT_LAYER_MODS"); | ||
1018 | break; | ||
1019 | case ACT_LAYER_TAP: | ||
1020 | dprint("ACT_LAYER_TAP"); | ||
1021 | break; | ||
1022 | case ACT_LAYER_TAP_EXT: | ||
1023 | dprint("ACT_LAYER_TAP_EXT"); | ||
1024 | break; | ||
1025 | case ACT_MACRO: | ||
1026 | dprint("ACT_MACRO"); | ||
1027 | break; | ||
1028 | case ACT_COMMAND: | ||
1029 | dprint("ACT_COMMAND"); | ||
1030 | break; | ||
1031 | case ACT_FUNCTION: | ||
1032 | dprint("ACT_FUNCTION"); | ||
1033 | break; | ||
1034 | case ACT_SWAP_HANDS: | ||
1035 | dprint("ACT_SWAP_HANDS"); | ||
1036 | break; | ||
1037 | default: | ||
1038 | dprint("UNKNOWN"); | ||
1039 | break; | ||
1025 | } | 1040 | } |
1026 | dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff); | 1041 | dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff); |
1027 | } | 1042 | } |