leader.h
2808 bytes
1// Copyright 2023 QMK
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include <stdbool.h>
5#include <stdint.h>
6
7/**
8 * \file
9 *
10 * \defgroup leader Leader Key
11 * \{
12 */
13
14/**
15 * \brief User callback, invoked when the leader sequence begins.
16 */
17void leader_start_user(void);
18
19/**
20 * \brief User callback, invoked when the leader sequence ends.
21 */
22void leader_end_user(void);
23
24/**
25 * Begin the leader sequence, resetting the buffer and timer.
26 */
27void leader_start(void);
28
29/**
30 * End the leader sequence.
31 */
32void leader_end(void);
33
34void leader_task(void);
35
36/**
37 * Whether the leader sequence is active.
38 */
39bool leader_sequence_active(void);
40
41/**
42 * Add the given keycode to the sequence buffer.
43 *
44 * If `LEADER_NO_TIMEOUT` is defined, the timer is reset if the buffer is empty.
45 *
46 * \param keycode The keycode to add.
47 *
48 * \return `true` if the keycode was added, `false` if the buffer is full.
49 */
50bool leader_sequence_add(uint16_t keycode);
51
52/**
53 * Whether the leader sequence has reached the timeout.
54 *
55 * If `LEADER_NO_TIMEOUT` is defined, the buffer must also contain at least one key.
56 */
57bool leader_sequence_timed_out(void);
58
59/**
60 * Reset the leader sequence timer.
61 */
62void leader_reset_timer(void);
63
64/**
65 * Check the sequence buffer for the given keycode.
66 *
67 * \param kc The keycode to check.
68 *
69 * \return `true` if the sequence buffer matches.
70 */
71bool leader_sequence_one_key(uint16_t kc);
72
73/**
74 * Check the sequence buffer for the given keycodes.
75 *
76 * \param kc1 The first keycode to check.
77 * \param kc2 The second keycode to check.
78 *
79 * \return `true` if the sequence buffer matches.
80 */
81bool leader_sequence_two_keys(uint16_t kc1, uint16_t kc2);
82
83/**
84 * Check the sequence buffer for the given keycodes.
85 *
86 * \param kc1 The first keycode to check.
87 * \param kc2 The second keycode to check.
88 * \param kc3 The third keycode to check.
89 *
90 * \return `true` if the sequence buffer matches.
91 */
92bool leader_sequence_three_keys(uint16_t kc1, uint16_t kc2, uint16_t kc3);
93
94/**
95 * Check the sequence buffer for the given keycodes.
96 *
97 * \param kc1 The first keycode to check.
98 * \param kc2 The second keycode to check.
99 * \param kc3 The third keycode to check.
100 * \param kc4 The fourth keycode to check.
101 *
102 * \return `true` if the sequence buffer matches.
103 */
104bool leader_sequence_four_keys(uint16_t kc1, uint16_t kc2, uint16_t kc3, uint16_t kc4);
105
106/**
107 * Check the sequence buffer for the given keycodes.
108 *
109 * \param kc1 The first keycode to check.
110 * \param kc2 The second keycode to check.
111 * \param kc3 The third keycode to check.
112 * \param kc4 The fourth keycode to check.
113 * \param kc5 The fifth keycode to check.
114 *
115 * \return `true` if the sequence buffer matches.
116 */
117bool leader_sequence_five_keys(uint16_t kc1, uint16_t kc2, uint16_t kc3, uint16_t kc4, uint16_t kc5);
118
119/** \} */