aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/config_options.md2
-rw-r--r--docs/feature_leader_key.md6
-rw-r--r--quantum/process_keycode/process_leader.c51
-rw-r--r--quantum/process_keycode/process_leader.h2
4 files changed, 40 insertions, 21 deletions
diff --git a/docs/config_options.md b/docs/config_options.md
index 879761a40..4bbc5debd 100644
--- a/docs/config_options.md
+++ b/docs/config_options.md
@@ -146,6 +146,8 @@ If you define these options you will enable the associated feature, which may in
146 * If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped. 146 * If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped.
147* `#define LEADER_PER_KEY_TIMING` 147* `#define LEADER_PER_KEY_TIMING`
148 * sets the timer for leader key chords to run on each key press rather than overall 148 * sets the timer for leader key chords to run on each key press rather than overall
149* `#define LEADER_KEY_STRICT_KEY_PROCESSING`
150 * Disables keycode filtering for Mod-Tap and Layer-Tap keycodes. Eg, if you enable this, you would need to specify `MT(MOD_CTL, KC_A)` if you want to use `KC_A`.
149* `#define ONESHOT_TIMEOUT 300` 151* `#define ONESHOT_TIMEOUT 300`
150 * how long before oneshot times out 152 * how long before oneshot times out
151* `#define ONESHOT_TAP_TOGGLE 2` 153* `#define ONESHOT_TAP_TOGGLE 2`
diff --git a/docs/feature_leader_key.md b/docs/feature_leader_key.md
index 168a1fc1c..82cf78901 100644
--- a/docs/feature_leader_key.md
+++ b/docs/feature_leader_key.md
@@ -72,6 +72,12 @@ SEQ_THREE_KEYS(KC_C, KC_C, KC_C) {
72} 72}
73``` 73```
74 74
75## Strict Key Processing
76
77By default, the Leader Key feature will filter the keycode out of [`Mod-Tap`](feature_advanced_keycodes.md#mod-tap) and [`Layer Tap`](feature_advanced_keycodes.md#switching-and-toggling-layers) functions when checking for the Leader sequences. That means if you're using `LT(3, KC_A)`, it will pick this up as `KC_A` for the sequence, rather than `LT(3, KC_A)`, giving a more expected behavior for newer users.
78
79While, this may be fine for most, if you want to specify the whole keycode (eg, `LT(3, KC_A)` from the example above) in the sequence, you can enable this by added `#define LEADER_KEY_STRICT_KEY_PROCESSING` to your `config.h` file. This well then disable the filtering, and you'll need to specify the whole keycode.
80
75## Customization 81## Customization
76 82
77The Leader Key feature has some additional customization to how the Leader Key feature works. It has two functions that can be called at certain parts of the process. Namely `leader_start()` and `leader_end()`. 83The Leader Key feature has some additional customization to how the Leader Key feature works. It has two functions that can be called at certain parts of the process. Namely `leader_start()` and `leader_end()`.
diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c
index b32fc1db6..57fccdc7e 100644
--- a/quantum/process_keycode/process_leader.c
+++ b/quantum/process_keycode/process_leader.c
@@ -35,31 +35,42 @@ uint16_t leader_time = 0;
35uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; 35uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
36uint8_t leader_sequence_size = 0; 36uint8_t leader_sequence_size = 0;
37 37
38void qk_leader_start(void) {
39 if (leading) { return; }
40 leader_start();
41 leading = true;
42 leader_time = timer_read();
43 leader_sequence_size = 0;
44 leader_sequence[0] = 0;
45 leader_sequence[1] = 0;
46 leader_sequence[2] = 0;
47 leader_sequence[3] = 0;
48 leader_sequence[4] = 0;
49}
50
38bool process_leader(uint16_t keycode, keyrecord_t *record) { 51bool process_leader(uint16_t keycode, keyrecord_t *record) {
39 // Leader key set-up 52 // Leader key set-up
40 if (record->event.pressed) { 53 if (record->event.pressed) {
54 if (leading) {
55 if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
56#ifndef LEADER_KEY_STRICT_KEY_PROCESSING
57 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
58 keycode = keycode & 0xFF;
59 }
60#endif // LEADER_KEY_STRICT_KEY_PROCESSING
61 leader_sequence[leader_sequence_size] = keycode;
62 leader_sequence_size++;
41#ifdef LEADER_PER_KEY_TIMING 63#ifdef LEADER_PER_KEY_TIMING
42 leader_time = timer_read(); 64 leader_time = timer_read();
43#endif 65#endif
44 if (!leading && keycode == KC_LEAD) { 66 return false;
45 leader_start(); 67 }
46 leading = true; 68 } else {
47#ifndef LEADER_PER_KEY_TIMING 69 if (keycode == KC_LEAD) {
48 leader_time = timer_read(); 70 qk_leader_start();
49#endif 71 return false;
50 leader_time = timer_read(); 72 }
51 leader_sequence_size = 0; 73 break;
52 leader_sequence[0] = 0;
53 leader_sequence[1] = 0;
54 leader_sequence[2] = 0;
55 leader_sequence[3] = 0;
56 leader_sequence[4] = 0;
57 return false;
58 }
59 if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
60 leader_sequence[leader_sequence_size] = keycode;
61 leader_sequence_size++;
62 return false;
63 } 74 }
64 } 75 }
65 return true; 76 return true;
diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h
index 59c3eed1b..15bccc3f6 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);
24 24
25void leader_start(void); 25void leader_start(void);
26void leader_end(void); 26void leader_end(void);
27 27void qk_leader_start(void);
28 28
29#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) 29#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)
30#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) 30#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)