diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index 58a615d85a59..6f80c1fea457 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -27,6 +27,8 @@ __attribute__((weak)) void leader_start(void) {} __attribute__((weak)) void leader_end(void) {} +__attribute__((weak)) bool leader_process_user(uint16_t *leader_sequence, bool is_timeout) { return true; } + // Leader key stuff bool leading = false; uint16_t leader_time = 0; @@ -45,6 +47,16 @@ void qk_leader_start(void) { memset(leader_sequence, 0, sizeof(leader_sequence)); } +void matrix_scan_leader(void) { +# ifdef LEADER_ON_KEY_PROCESSING + if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) { + leader_process_user(leader_sequence, true); + leading = false; + leader_end(); + } +# endif +} + bool process_leader(uint16_t keycode, keyrecord_t *record) { // Leader key set-up if (record->event.pressed) { @@ -55,9 +67,23 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) { keycode = keycode & 0xFF; } # endif // LEADER_KEY_STRICT_KEY_PROCESSING +# ifdef LEADER_ABORT + if (keycode == LEADER_ABORT) { + leading = false; + leader_end(); + return false; + } +# endif // LEADER_ABORT if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; +# ifdef LEADER_ON_KEY_PROCESSING + if (!leader_process_user(leader_sequence, false)) { + leading = false; + leader_end(); + return false; + } +# endif // LEADER_ON_KEY_PROCESSING } else { leading = false; leader_end(); diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h index e0edf57b3272..cac3bea529d2 100644 --- a/quantum/process_keycode/process_leader.h +++ b/quantum/process_keycode/process_leader.h @@ -20,9 +20,12 @@ #include "quantum.h" bool process_leader(uint16_t keycode, keyrecord_t *record); +void matrix_scan_leader(void); void leader_start(void); void leader_end(void); +bool leader_process_user(uint16_t *leader_sequence, bool is_timeout); + void qk_leader_start(void); #define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0) diff --git a/quantum/quantum.c b/quantum/quantum.c index 1f17c6ff71d4..34866967074c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -982,6 +982,10 @@ void matrix_scan_quantum() { matrix_scan_combo(); #endif +#if defined(LEADER_ENABLE) + matrix_scan_leader(); +#endif + #if defined(BACKLIGHT_ENABLE) # if defined(LED_MATRIX_ENABLE) led_matrix_task();