aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Spooner <[email protected]>2025-01-02 07:12:58 +0000
committerGitHub <[email protected]>2025-01-01 23:12:58 -0800
commitb603094995fad1498204cbabdb47b85e76780446 (patch)
treeb6b0c7fbf979919f84756fb3315696c42b4fb56b
parente016b9b4c5c28b4a0a7ae2fbb7cbe7e090169438 (diff)
downloadqmk_firmware-b603094995fad1498204cbabdb47b85e76780446.tar.gz
qmk_firmware-b603094995fad1498204cbabdb47b85e76780446.zip
Add leader_add_user callback (#24266)
-rw-r--r--docs/features/leader_key.md15
-rw-r--r--quantum/leader.c7
-rw-r--r--quantum/leader.h9
3 files changed, 31 insertions, 0 deletions
diff --git a/docs/features/leader_key.md b/docs/features/leader_key.md
index a36e630a36..9f9086e1ae 100644
--- a/docs/features/leader_key.md
+++ b/docs/features/leader_key.md
@@ -154,6 +154,21 @@ User callback, invoked when the leader sequence ends.
---
+### `bool leader_add_user(uint16_t keycode)` {#api-leader-add-user}
+
+User callback, invoked when a keycode is added to the leader sequence.
+
+#### 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.
+
+---
+
### `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 272609ad0c..23e5e8cd6d 100644
--- a/quantum/leader.c
+++ b/quantum/leader.c
@@ -21,6 +21,10 @@ __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;
+}
+
void leader_start(void) {
if (leading) {
return;
@@ -61,6 +65,9 @@ bool leader_sequence_add(uint16_t keycode) {
leader_sequence[leader_sequence_size] = keycode;
leader_sequence_size++;
+ if (leader_add_user(keycode)) {
+ leader_end();
+ }
return true;
}
diff --git a/quantum/leader.h b/quantum/leader.h
index 3177fcd196..fba6b287ba 100644
--- a/quantum/leader.h
+++ b/quantum/leader.h
@@ -22,6 +22,15 @@ void leader_start_user(void);
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(uint16_t keycode);
+
+/**
* Begin the leader sequence, resetting the buffer and timer.
*/
void leader_start(void);