summaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-12-20 16:54:06 -0800
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2018-12-20 16:54:06 -0800
commitafd5cda4a0d832bacfff319177fe93968f686a11 (patch)
tree114dd8500a6bcc1878894329aa0ce0edb2b56289 /quantum/process_keycode
parent30c3f3b2bd9c68ba8bba644fcfa97152a4834c03 (diff)
Fix up process_leader to be a bit more optimized (#4662)
* Fix up process_leader to be a bit more optimized * Process dual function keys better * Make leader start a callable function * Fix per key timer call location * Add escape if already leading * Return false for KC_LEAD * Add documentation
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_leader.c51
-rw-r--r--quantum/process_keycode/process_leader.h2
2 files changed, 32 insertions, 21 deletions
diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c
index b32fc1db6a..57fccdc7e7 100644
--- a/quantum/process_keycode/process_leader.c
+++ b/quantum/process_keycode/process_leader.c
@@ -35,31 +35,42 @@ 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) {
+ if (leading) { return; }
+ leader_start();
+ leading = true;
+ leader_time = timer_read();
+ leader_sequence_size = 0;
+ leader_sequence[0] = 0;
+ leader_sequence[1] = 0;
+ leader_sequence[2] = 0;
+ leader_sequence[3] = 0;
+ leader_sequence[4] = 0;
+}
+
bool process_leader(uint16_t keycode, keyrecord_t *record) {
// Leader key set-up
if (record->event.pressed) {
+ if (leading) {
+ if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
+#ifndef LEADER_KEY_STRICT_KEY_PROCESSING
+ if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
+ keycode = keycode & 0xFF;
+ }
+#endif // LEADER_KEY_STRICT_KEY_PROCESSING
+ leader_sequence[leader_sequence_size] = keycode;
+ leader_sequence_size++;
#ifdef LEADER_PER_KEY_TIMING
- leader_time = timer_read();
+ leader_time = timer_read();
#endif
- if (!leading && keycode == KC_LEAD) {
- leader_start();
- leading = true;
-#ifndef LEADER_PER_KEY_TIMING
- leader_time = timer_read();
-#endif
- leader_time = timer_read();
- leader_sequence_size = 0;
- leader_sequence[0] = 0;
- leader_sequence[1] = 0;
- leader_sequence[2] = 0;
- leader_sequence[3] = 0;
- leader_sequence[4] = 0;
- return false;
- }
- if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
- leader_sequence[leader_sequence_size] = keycode;
- leader_sequence_size++;
- return false;
+ return false;
+ }
+ } else {
+ if (keycode == KC_LEAD) {
+ qk_leader_start();
+ return false;
+ }
+ break;
}
}
return true;
diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h
index 59c3eed1be..15bccc3f67 100644
--- a/quantum/process_keycode/process_leader.h
+++ b/quantum/process_keycode/process_leader.h
@@ -24,7 +24,7 @@ bool process_leader(uint16_t keycode, keyrecord_t *record);
void leader_start(void);
void leader_end(void);
-
+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)
#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)