1
0
Fork 0

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
This commit is contained in:
Drashna Jaelre 2018-12-20 16:54:06 -08:00 committed by MechMerlin
parent 30c3f3b2bd
commit afd5cda4a0
4 changed files with 40 additions and 21 deletions

View file

@ -146,6 +146,8 @@ If you define these options you will enable the associated feature, which may in
* 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. * 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.
* `#define LEADER_PER_KEY_TIMING` * `#define LEADER_PER_KEY_TIMING`
* sets the timer for leader key chords to run on each key press rather than overall * sets the timer for leader key chords to run on each key press rather than overall
* `#define LEADER_KEY_STRICT_KEY_PROCESSING`
* 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`.
* `#define ONESHOT_TIMEOUT 300` * `#define ONESHOT_TIMEOUT 300`
* how long before oneshot times out * how long before oneshot times out
* `#define ONESHOT_TAP_TOGGLE 2` * `#define ONESHOT_TAP_TOGGLE 2`

View file

@ -72,6 +72,12 @@ SEQ_THREE_KEYS(KC_C, KC_C, KC_C) {
} }
``` ```
## Strict Key Processing
By 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.
While, 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.
## Customization ## Customization
The 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()`. The 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()`.

View file

@ -35,18 +35,10 @@ uint16_t leader_time = 0;
uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
uint8_t leader_sequence_size = 0; uint8_t leader_sequence_size = 0;
bool process_leader(uint16_t keycode, keyrecord_t *record) { void qk_leader_start(void) {
// Leader key set-up if (leading) { return; }
if (record->event.pressed) {
#ifdef LEADER_PER_KEY_TIMING
leader_time = timer_read();
#endif
if (!leading && keycode == KC_LEAD) {
leader_start(); leader_start();
leading = true; leading = true;
#ifndef LEADER_PER_KEY_TIMING
leader_time = timer_read();
#endif
leader_time = timer_read(); leader_time = timer_read();
leader_sequence_size = 0; leader_sequence_size = 0;
leader_sequence[0] = 0; leader_sequence[0] = 0;
@ -54,13 +46,32 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) {
leader_sequence[2] = 0; leader_sequence[2] = 0;
leader_sequence[3] = 0; leader_sequence[3] = 0;
leader_sequence[4] = 0; leader_sequence[4] = 0;
return false;
} }
if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
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[leader_sequence_size] = keycode;
leader_sequence_size++; leader_sequence_size++;
#ifdef LEADER_PER_KEY_TIMING
leader_time = timer_read();
#endif
return false; return false;
} }
} else {
if (keycode == KC_LEAD) {
qk_leader_start();
return false;
}
break;
}
} }
return true; return true;
} }

View file

@ -24,7 +24,7 @@ bool process_leader(uint16_t keycode, keyrecord_t *record);
void leader_start(void); void leader_start(void);
void leader_end(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_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_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)