Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process leader mappings on key press #7270

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions quantum/process_keycode/process_leader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions quantum/process_keycode/process_leader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down