diff options
| author | Nick Brassel <nick@tzarc.org> | 2023-05-15 22:27:37 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-15 22:27:37 +1000 |
| commit | 5faa23d54ca1e3ab83097f2a07922f48800616e6 (patch) | |
| tree | 6ed05e5492f3fc8dda210a75b897dd9d4ed8df38 /quantum/process_keycode | |
| parent | 433dc6068603e61d466e755aedcea0be96664f95 (diff) | |
Keymap introspection for combos. (#19670)
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_combo.c | 23 | ||||
| -rw-r--r-- | quantum/process_keycode/process_combo.h | 2 |
2 files changed, 9 insertions, 16 deletions
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2670ccabed..bbee560be9 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c | |||
| @@ -19,14 +19,7 @@ | |||
| 19 | #include "process_combo.h" | 19 | #include "process_combo.h" |
| 20 | #include "action_tapping.h" | 20 | #include "action_tapping.h" |
| 21 | #include "action.h" | 21 | #include "action.h" |
| 22 | 22 | #include "keymap_introspection.h" | |
| 23 | #ifdef COMBO_COUNT | ||
| 24 | __attribute__((weak)) combo_t key_combos[COMBO_COUNT]; | ||
| 25 | uint16_t COMBO_LEN = COMBO_COUNT; | ||
| 26 | #else | ||
| 27 | extern combo_t key_combos[]; | ||
| 28 | extern uint16_t COMBO_LEN; | ||
| 29 | #endif | ||
| 30 | 23 | ||
| 31 | __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} | 24 | __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} |
| 32 | 25 | ||
| @@ -195,8 +188,8 @@ static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) { | |||
| 195 | void clear_combos(void) { | 188 | void clear_combos(void) { |
| 196 | uint16_t index = 0; | 189 | uint16_t index = 0; |
| 197 | longest_term = 0; | 190 | longest_term = 0; |
| 198 | for (index = 0; index < COMBO_LEN; ++index) { | 191 | for (index = 0; index < combo_count(); ++index) { |
| 199 | combo_t *combo = &key_combos[index]; | 192 | combo_t *combo = combo_get(index); |
| 200 | if (!COMBO_ACTIVE(combo)) { | 193 | if (!COMBO_ACTIVE(combo)) { |
| 201 | RESET_COMBO_STATE(combo); | 194 | RESET_COMBO_STATE(combo); |
| 202 | } | 195 | } |
| @@ -287,7 +280,7 @@ void drop_combo_from_buffer(uint16_t combo_index) { | |||
| 287 | queued_combo_t *qcombo = &combo_buffer[i]; | 280 | queued_combo_t *qcombo = &combo_buffer[i]; |
| 288 | 281 | ||
| 289 | if (qcombo->combo_index == combo_index) { | 282 | if (qcombo->combo_index == combo_index) { |
| 290 | combo_t *combo = &key_combos[combo_index]; | 283 | combo_t *combo = combo_get(combo_index); |
| 291 | DISABLE_COMBO(combo); | 284 | DISABLE_COMBO(combo); |
| 292 | 285 | ||
| 293 | if (i == combo_buffer_read) { | 286 | if (i == combo_buffer_read) { |
| @@ -354,7 +347,7 @@ static inline void apply_combos(void) { | |||
| 354 | // Apply all buffered normal combos. | 347 | // Apply all buffered normal combos. |
| 355 | for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) { | 348 | for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) { |
| 356 | queued_combo_t *buffered_combo = &combo_buffer[i]; | 349 | queued_combo_t *buffered_combo = &combo_buffer[i]; |
| 357 | combo_t * combo = &key_combos[buffered_combo->combo_index]; | 350 | combo_t * combo = combo_get(buffered_combo->combo_index); |
| 358 | 351 | ||
| 359 | #ifdef COMBO_MUST_TAP_PER_COMBO | 352 | #ifdef COMBO_MUST_TAP_PER_COMBO |
| 360 | if (get_combo_must_tap(buffered_combo->combo_index, combo)) { | 353 | if (get_combo_must_tap(buffered_combo->combo_index, combo)) { |
| @@ -459,7 +452,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t * | |||
| 459 | combo_t *drop = NULL; | 452 | combo_t *drop = NULL; |
| 460 | for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) { | 453 | for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) { |
| 461 | queued_combo_t *qcombo = &combo_buffer[combo_buffer_i]; | 454 | queued_combo_t *qcombo = &combo_buffer[combo_buffer_i]; |
| 462 | combo_t * buffered_combo = &key_combos[qcombo->combo_index]; | 455 | combo_t * buffered_combo = combo_get(qcombo->combo_index); |
| 463 | 456 | ||
| 464 | if ((drop = overlaps(buffered_combo, combo))) { | 457 | if ((drop = overlaps(buffered_combo, combo))) { |
| 465 | DISABLE_COMBO(drop); | 458 | DISABLE_COMBO(drop); |
| @@ -565,8 +558,8 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
| 565 | } | 558 | } |
| 566 | #endif | 559 | #endif |
| 567 | 560 | ||
| 568 | for (uint16_t idx = 0; idx < COMBO_LEN; ++idx) { | 561 | for (uint16_t idx = 0; idx < combo_count(); ++idx) { |
| 569 | combo_t *combo = &key_combos[idx]; | 562 | combo_t *combo = combo_get(idx); |
| 570 | is_combo_key |= process_single_combo(combo, keycode, record, idx); | 563 | is_combo_key |= process_single_combo(combo, keycode, record, idx); |
| 571 | no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo)); | 564 | no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo)); |
| 572 | } | 565 | } |
diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index e430c4a5f7..bba5d5ee63 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h | |||
| @@ -37,7 +37,7 @@ | |||
| 37 | # define COMBO_BUFFER_LENGTH 4 | 37 | # define COMBO_BUFFER_LENGTH 4 |
| 38 | #endif | 38 | #endif |
| 39 | 39 | ||
| 40 | typedef struct { | 40 | typedef struct combo_t { |
| 41 | const uint16_t *keys; | 41 | const uint16_t *keys; |
| 42 | uint16_t keycode; | 42 | uint16_t keycode; |
| 43 | #ifdef EXTRA_SHORT_COMBOS | 43 | #ifdef EXTRA_SHORT_COMBOS |
