summaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2023-02-13 03:19:02 +1100
committerGitHub <noreply@github.com>2023-02-13 03:19:02 +1100
commitbbf7a20b33de2d203518687cb5cd1aa85005ea27 (patch)
treeee1a5c412a02021d085c81a26321c3424eca7022 /quantum/process_keycode
parentd10350cd2ceb2b9d80522cdec3ea908118f7fd35 (diff)
Refactor Leader key feature (#19632)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_leader.c77
-rw-r--r--quantum/process_keycode/process_leader.h24
2 files changed, 20 insertions, 81 deletions
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 <string.h>
+#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;
}
diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h
index 82b4a3ed7b..eb0f721f60 100644
--- a/quantum/process_keycode/process_leader.h
+++ b/quantum/process_keycode/process_leader.h
@@ -19,27 +19,3 @@
#include "quantum.h"
bool process_leader(uint16_t keycode, keyrecord_t *record);
-
-void leader_start_user(void);
-void leader_end_user(void);
-
-void leader_start(void);
-void leader_end(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)
-#define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0)
-#define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == 0 && leader_sequence[4] == 0)
-#define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0)
-#define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5))
-
-#define LEADER_EXTERNS() \
- extern bool leading; \
- extern uint16_t leader_time; \
- extern uint16_t leader_sequence[5]; \
- extern uint8_t leader_sequence_size
-
-#ifdef LEADER_NO_TIMEOUT
-# define LEADER_DICTIONARY() if (leading && leader_sequence_size > 0 && timer_elapsed(leader_time) > LEADER_TIMEOUT)
-#else
-# define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
-#endif