From 0de31e33188ae4409b35c9be9d35840a0270cd71 Mon Sep 17 00:00:00 2001 From: willbsp Date: Sun, 11 Aug 2024 10:38:11 +0100 Subject: [PATCH] Add leader_add_user callback --- docs/features/leader_key.md | 10 ++++++++++ quantum/leader.c | 5 +++++ quantum/leader.h | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/docs/features/leader_key.md b/docs/features/leader_key.md index a36e630a366..423f55b7e84 100644 --- a/docs/features/leader_key.md +++ b/docs/features/leader_key.md @@ -154,6 +154,16 @@ User callback, invoked when the leader sequence ends. --- +### `bool leader_add_user(void)` {#api-leader-add-user} + +User callback, invoked when a keycode is added to the leader sequence. + +#### Return Value {#api-leader-sequence-add-return} + +`true` to finish the key sequence, `false` to continue. + +--- + ### `void leader_start(void)` {#api-leader-start} Begin the leader sequence, resetting the buffer and timer. diff --git a/quantum/leader.c b/quantum/leader.c index 272609ad0cf..2f24ebfe805 100644 --- a/quantum/leader.c +++ b/quantum/leader.c @@ -21,6 +21,8 @@ __attribute__((weak)) void leader_start_user(void) {} __attribute__((weak)) void leader_end_user(void) {} +__attribute__((weak)) bool leader_add_user(void) { return false; } + void leader_start(void) { if (leading) { return; @@ -61,6 +63,9 @@ bool leader_sequence_add(uint16_t keycode) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; + if (leader_add_user()) { + leader_end(); + } return true; } diff --git a/quantum/leader.h b/quantum/leader.h index 3177fcd1962..c54364030fe 100644 --- a/quantum/leader.h +++ b/quantum/leader.h @@ -21,6 +21,13 @@ void leader_start_user(void); */ void leader_end_user(void); +/** + * \brief User callback, invoked when a keycode is added to the leader sequence. + * + * \return `true` to finish the key sequence, `false` to continue. + */ +bool leader_add_user(void); + /** * Begin the leader sequence, resetting the buffer and timer. */