From e2117564c54044c809903627c0061b5a9d129815 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 14 Dec 2022 13:46:01 +1100 Subject: Leader: remove `qk_` prefix (#19304) --- quantum/process_keycode/process_leader.c | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'quantum/process_keycode/process_leader.c') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index b74b4927a8..80bc96e65f 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -14,18 +14,16 @@ * along with this program. If not, see . */ -#ifdef LEADER_ENABLE +#include "process_leader.h" +#include -# include "process_leader.h" -# include - -# ifndef LEADER_TIMEOUT -# define LEADER_TIMEOUT 300 -# endif +#ifndef LEADER_TIMEOUT +# define LEADER_TIMEOUT 300 +#endif -__attribute__((weak)) void leader_start(void) {} +__attribute__((weak)) void leader_start_user(void) {} -__attribute__((weak)) void leader_end(void) {} +__attribute__((weak)) void leader_end_user(void) {} // Leader key stuff bool leading = false; @@ -34,52 +32,54 @@ uint16_t leader_time = 0; uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; uint8_t leader_sequence_size = 0; -void qk_leader_start(void) { +void leader_start(void) { if (leading) { return; } - leader_start(); + leader_start_user(); leading = true; leader_time = timer_read(); leader_sequence_size = 0; memset(leader_sequence, 0, sizeof(leader_sequence)); } +void leader_end(void) { + leader_end_user(); +} + bool process_leader(uint16_t keycode, keyrecord_t *record) { // Leader key set-up if (record->event.pressed) { if (leading) { -# ifndef LEADER_NO_TIMEOUT +#ifndef LEADER_NO_TIMEOUT if (timer_elapsed(leader_time) < LEADER_TIMEOUT) -# endif // LEADER_NO_TIMEOUT +#endif // LEADER_NO_TIMEOUT { -# ifndef LEADER_KEY_STRICT_KEY_PROCESSING +#ifndef LEADER_KEY_STRICT_KEY_PROCESSING if (IS_QK_MOD_TAP(keycode)) { keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode); } else if (IS_QK_LAYER_TAP(keycode)) { keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode); } -# endif // LEADER_KEY_STRICT_KEY_PROCESSING +#endif // LEADER_KEY_STRICT_KEY_PROCESSING if (leader_sequence_size < ARRAY_SIZE(leader_sequence)) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; } else { leading = false; - leader_end(); + leader_end_user(); return true; } -# ifdef LEADER_PER_KEY_TIMING +#ifdef LEADER_PER_KEY_TIMING leader_time = timer_read(); -# endif +#endif return false; } } else { if (keycode == QK_LEADER) { - qk_leader_start(); + leader_start(); } } } return true; } - -#endif -- cgit v1.2.3 From bbf7a20b33de2d203518687cb5cd1aa85005ea27 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 13 Feb 2023 03:19:02 +1100 Subject: Refactor Leader key feature (#19632) Co-authored-by: Drashna Jaelre --- quantum/process_keycode/process_leader.c | 77 +++++++++----------------------- 1 file changed, 20 insertions(+), 57 deletions(-) (limited to 'quantum/process_keycode/process_leader.c') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index 80bc96e65f..a9823b6285 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -15,71 +15,34 @@ */ #include "process_leader.h" -#include +#include "leader.h" -#ifndef LEADER_TIMEOUT -# define LEADER_TIMEOUT 300 +bool process_leader(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + if (leader_sequence_active() && !leader_sequence_timed_out()) { +#ifndef LEADER_KEY_STRICT_KEY_PROCESSING + if (IS_QK_MOD_TAP(keycode)) { + keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode); + } else if (IS_QK_LAYER_TAP(keycode)) { + keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode); + } #endif -__attribute__((weak)) void leader_start_user(void) {} - -__attribute__((weak)) void leader_end_user(void) {} - -// Leader key stuff -bool leading = false; -uint16_t leader_time = 0; - -uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; -uint8_t leader_sequence_size = 0; - -void leader_start(void) { - if (leading) { - return; - } - leader_start_user(); - leading = true; - leader_time = timer_read(); - leader_sequence_size = 0; - memset(leader_sequence, 0, sizeof(leader_sequence)); -} + if (!leader_sequence_add(keycode)) { + leader_end(); -void leader_end(void) { - leader_end_user(); -} + return true; + } -bool process_leader(uint16_t keycode, keyrecord_t *record) { - // Leader key set-up - if (record->event.pressed) { - if (leading) { -#ifndef LEADER_NO_TIMEOUT - if (timer_elapsed(leader_time) < LEADER_TIMEOUT) -#endif // LEADER_NO_TIMEOUT - { -#ifndef LEADER_KEY_STRICT_KEY_PROCESSING - if (IS_QK_MOD_TAP(keycode)) { - keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode); - } else if (IS_QK_LAYER_TAP(keycode)) { - keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode); - } -#endif // LEADER_KEY_STRICT_KEY_PROCESSING - if (leader_sequence_size < ARRAY_SIZE(leader_sequence)) { - leader_sequence[leader_sequence_size] = keycode; - leader_sequence_size++; - } else { - leading = false; - leader_end_user(); - return true; - } #ifdef LEADER_PER_KEY_TIMING - leader_time = timer_read(); + leader_reset_timer(); #endif - return false; - } - } else { - if (keycode == QK_LEADER) { - leader_start(); - } + + return false; + } else if (keycode == QK_LEADER) { + leader_start(); } } + return true; } -- cgit v1.2.3