From 0de31e33188ae4409b35c9be9d35840a0270cd71 Mon Sep 17 00:00:00 2001 From: willbsp Date: Sun, 11 Aug 2024 10:38:11 +0100 Subject: [PATCH 1/3] 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. */ From 6a54422a410cedd93535c7c059cb848c00f52c1f Mon Sep 17 00:00:00 2001 From: willbsp Date: Fri, 6 Sep 2024 12:01:09 +0100 Subject: [PATCH 2/3] Add keycode parameter to leader_add_user callback --- docs/features/leader_key.md | 9 +++++++-- quantum/leader.c | 4 ++-- quantum/leader.h | 4 +++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/features/leader_key.md b/docs/features/leader_key.md index 423f55b7e84..9f9086e1ae0 100644 --- a/docs/features/leader_key.md +++ b/docs/features/leader_key.md @@ -154,11 +154,16 @@ User callback, invoked when the leader sequence ends. --- -### `bool leader_add_user(void)` {#api-leader-add-user} +### `bool leader_add_user(uint16_t keycode)` {#api-leader-add-user} User callback, invoked when a keycode is added to the leader sequence. -#### Return Value {#api-leader-sequence-add-return} +#### Arguments {#api-leader-add-user-arguments} + + - `uint16_t keycode` + The keycode to added to the leader sequence. + +#### Return Value {#api-leader-add-user-return} `true` to finish the key sequence, `false` to continue. diff --git a/quantum/leader.c b/quantum/leader.c index 2f24ebfe805..4016c934cc0 100644 --- a/quantum/leader.c +++ b/quantum/leader.c @@ -21,7 +21,7 @@ __attribute__((weak)) void leader_start_user(void) {} __attribute__((weak)) void leader_end_user(void) {} -__attribute__((weak)) bool leader_add_user(void) { return false; } +__attribute__((weak)) bool leader_add_user(uint16_t keycode) { return false; } void leader_start(void) { if (leading) { @@ -63,7 +63,7 @@ bool leader_sequence_add(uint16_t keycode) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; - if (leader_add_user()) { + if (leader_add_user(keycode)) { leader_end(); } return true; diff --git a/quantum/leader.h b/quantum/leader.h index c54364030fe..fba6b287ba3 100644 --- a/quantum/leader.h +++ b/quantum/leader.h @@ -24,9 +24,11 @@ void leader_end_user(void); /** * \brief User callback, invoked when a keycode is added to the leader sequence. * + * \param keycode The keycode added to the leader sequence. + * * \return `true` to finish the key sequence, `false` to continue. */ -bool leader_add_user(void); +bool leader_add_user(uint16_t keycode); /** * Begin the leader sequence, resetting the buffer and timer. From 75ac180ff5461fec554e66b872fd678ef73e593f Mon Sep 17 00:00:00 2001 From: willbsp Date: Fri, 6 Sep 2024 12:04:41 +0100 Subject: [PATCH 3/3] Fix leader.c formatting --- quantum/leader.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/quantum/leader.c b/quantum/leader.c index 4016c934cc0..23e5e8cd6d3 100644 --- a/quantum/leader.c +++ b/quantum/leader.c @@ -21,7 +21,9 @@ __attribute__((weak)) void leader_start_user(void) {} __attribute__((weak)) void leader_end_user(void) {} -__attribute__((weak)) bool leader_add_user(uint16_t keycode) { return false; } +__attribute__((weak)) bool leader_add_user(uint16_t keycode) { + return false; +} void leader_start(void) { if (leading) {