Leader: remove `qk_` prefix (#19304)
parent
49b81a9c2b
commit
e2117564c5
|
@ -93,18 +93,18 @@ While, this may be fine for most, if you want to specify the whole keycode (eg,
|
|||
|
||||
## 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_user()` and `leader_end_user()`.
|
||||
|
||||
The `leader_start()` function is called when you tap the `QK_LEAD` key, and the `leader_end()` function is called when either the leader sequence is completed, or the leader timeout is hit.
|
||||
The `leader_start_user()` function is called when you tap the `QK_LEAD` key, and the `leader_end_user()` function is called when either the leader sequence is completed, or the leader timeout is hit.
|
||||
|
||||
You can add these functions to your code (`keymap.c` usually) to add feedback to the Leader sequences (such as beeping or playing music).
|
||||
|
||||
```c
|
||||
void leader_start(void) {
|
||||
void leader_start_user(void) {
|
||||
// sequence started
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
// sequence ended (no success/failure detection)
|
||||
}
|
||||
```
|
||||
|
@ -139,13 +139,13 @@ void matrix_scan_user(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void leader_start(void) {
|
||||
void leader_start_user(void) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(leader_start);
|
||||
#endif
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
if (did_leader_succeed) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(leader_succeed);
|
||||
|
|
|
@ -38,7 +38,7 @@ int ctl_state = 0;
|
|||
void ctl_finished(qk_tap_dance_state_t *state, void *user_data) {
|
||||
ctl_state = cur_dance(state);
|
||||
switch (ctl_state) {
|
||||
case SINGLE_TAP: qk_leader_start(); break;
|
||||
case SINGLE_TAP: leader_start(); break;
|
||||
case SINGLE_HOLD: register_code(KC_LCTL); break;
|
||||
case DOUBLE_TAP: tap_code(KC_RCTL); break;
|
||||
case DOUBLE_HOLD: register_code(KC_RCTL); break;
|
||||
|
|
|
@ -708,11 +708,11 @@ void matrix_scan_user(void)
|
|||
}
|
||||
}
|
||||
|
||||
void leader_start(void) {
|
||||
void leader_start_user(void) {
|
||||
isLeader = true;
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
isLeader = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ void none_lead_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|||
break;
|
||||
|
||||
case DOUBLE_TAP:
|
||||
qk_leader_start();
|
||||
leader_start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ int ctl_state = 0;
|
|||
void ctl_finished(qk_tap_dance_state_t *state, void *user_data) {
|
||||
ctl_state = cur_dance(state);
|
||||
switch(ctl_state) {
|
||||
case SINGLE_TAP: qk_leader_start(); break;
|
||||
case SINGLE_TAP: leader_start(); break;
|
||||
case SINGLE_HOLD: register_code(KC_LCTL); break;
|
||||
case DOUBLE_TAP: tap_code(KC_RCTL); break;
|
||||
case DOUBLE_HOLD: register_code(KC_RCTL); break;
|
||||
|
|
|
@ -43,7 +43,7 @@ int ctl_state = 0;
|
|||
void ctl_finished(qk_tap_dance_state_t *state, void *user_data) {
|
||||
ctl_state = cur_dance(state);
|
||||
switch (ctl_state) {
|
||||
case SINGLE_TAP: qk_leader_start(); break;
|
||||
case SINGLE_TAP: leader_start(); break;
|
||||
case SINGLE_HOLD: register_code(KC_LCTL); break;
|
||||
case DOUBLE_TAP: tap_code(KC_RCTL); break;
|
||||
case DOUBLE_HOLD: register_code(KC_RCTL); break;
|
||||
|
|
|
@ -1397,13 +1397,13 @@ bool get_permissive_hold(uint16_t keycode, keyrecord_t* record) {
|
|||
* by playing sound at different stages of the leader chord
|
||||
*/
|
||||
// Called when you tap the Leader key
|
||||
void leader_start(void) {
|
||||
void leader_start_user(void) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(leader_started);
|
||||
#endif
|
||||
}
|
||||
// Called when either the leader sequence is completed, or the leader timeout is hit
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
if (did_leader_succeed) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(leader_succeed);
|
||||
|
|
|
@ -187,7 +187,7 @@ void matrix_scan_user(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
// Plays sound on if leader sequence found.
|
||||
if (leader_found) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
|
|
|
@ -469,13 +469,13 @@ void matrix_scan_user(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void leader_start(void) {
|
||||
void leader_start_user(void) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(leader_start_song);
|
||||
#endif
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
if (did_leader_succeed) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(leader_succeed_song);
|
||||
|
|
|
@ -197,7 +197,7 @@ void matrix_scan_user(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
// Plays sound on if leader sequence found.
|
||||
if (leader_found) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
|
|
|
@ -14,18 +14,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef LEADER_ENABLE
|
||||
#include "process_leader.h"
|
||||
#include <string.h>
|
||||
|
||||
# include "process_leader.h"
|
||||
# include <string.h>
|
||||
|
||||
# ifndef LEADER_TIMEOUT
|
||||
#ifndef LEADER_TIMEOUT
|
||||
# define LEADER_TIMEOUT 300
|
||||
# endif
|
||||
#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
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
|
||||
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);
|
||||
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)
|
||||
|
|
|
@ -7,9 +7,9 @@ bool onMac = true;
|
|||
LEADER_EXTERNS();
|
||||
# ifdef RGBLIGHT_ENABLE
|
||||
|
||||
void leader_start() { rgblight_setrgb_range(5, 100, 199, 10, 15); };
|
||||
void leader_start_user() { rgblight_setrgb_range(5, 100, 199, 10, 15); };
|
||||
|
||||
void leader_end() { rgblight_setrgb_range(200, 200, 255, 10, 15); };
|
||||
void leader_end_user() { rgblight_setrgb_range(200, 200, 255, 10, 15); };
|
||||
# endif
|
||||
|
||||
void matrix_scan_user(void) {
|
||||
|
|
|
@ -93,7 +93,7 @@ void matrix_scan_user(void) {
|
|||
// matrix_scan_keymap();
|
||||
}
|
||||
|
||||
void leader_start(void) {
|
||||
void leader_start_user(void) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_savebase();
|
||||
rgblight_mode_noeeprom(1);
|
||||
|
@ -101,7 +101,7 @@ void leader_start(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void leader_end(void) {
|
||||
void leader_end_user(void) {
|
||||
// pick color depending of success /fail
|
||||
// fade leader_start from 100 to 0
|
||||
// fade new color from 0 to 100 to 0
|
||||
|
|
Loading…
Reference in New Issue