diff options
author | Drashna Jaelre <drashna@live.com> | 2019-07-16 01:37:19 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-07-16 01:37:19 -0700 |
commit | c44fc68297029da87233777aff6978d39caebbb1 (patch) | |
tree | f580b1ae96684577caa899a8180a2f9cb4a81aca /quantum | |
parent | 5fa0a274eaf6c3f2b1dbd4e6e23a4c3b884f1d44 (diff) | |
download | qmk_firmware-c44fc68297029da87233777aff6978d39caebbb1.tar.gz qmk_firmware-c44fc68297029da87233777aff6978d39caebbb1.zip |
Allow Combo feature to be enabled/disabled live (#6318)
* Add ability to enable/disable combos
* Update documentation for Combo feature
* Change keycodes for appeasement
* Simplify combo_toggle function
* Update names
* Update combo docs to use tables
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/process_keycode/process_combo.c | 43 | ||||
-rw-r--r-- | quantum/process_keycode/process_combo.h | 5 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 3 |
3 files changed, 50 insertions, 1 deletions
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2c6c9d0d5..d3c3b1673 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c | |||
@@ -28,6 +28,7 @@ static uint16_t timer = 0; | |||
28 | static uint8_t current_combo_index = 0; | 28 | static uint8_t current_combo_index = 0; |
29 | static bool drop_buffer = false; | 29 | static bool drop_buffer = false; |
30 | static bool is_active = false; | 30 | static bool is_active = false; |
31 | static bool b_combo_enable = true; // defaults to enabled | ||
31 | 32 | ||
32 | static uint8_t buffer_size = 0; | 33 | static uint8_t buffer_size = 0; |
33 | #ifdef COMBO_ALLOW_ACTION_KEYS | 34 | #ifdef COMBO_ALLOW_ACTION_KEYS |
@@ -128,6 +129,23 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
128 | drop_buffer = false; | 129 | drop_buffer = false; |
129 | bool no_combo_keys_pressed = true; | 130 | bool no_combo_keys_pressed = true; |
130 | 131 | ||
132 | if (keycode == CMB_ON && record->event.pressed) { | ||
133 | combo_enable(); | ||
134 | return true; | ||
135 | } | ||
136 | |||
137 | if (keycode == CMB_OFF && record->event.pressed) { | ||
138 | combo_disable(); | ||
139 | return true; | ||
140 | } | ||
141 | |||
142 | if (keycode == CMB_TOG && record->event.pressed) { | ||
143 | combo_toggle(); | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | if (!is_combo_enabled()) { return true; } | ||
148 | |||
131 | for (current_combo_index = 0; current_combo_index < COMBO_COUNT; | 149 | for (current_combo_index = 0; current_combo_index < COMBO_COUNT; |
132 | ++current_combo_index) { | 150 | ++current_combo_index) { |
133 | combo_t *combo = &key_combos[current_combo_index]; | 151 | combo_t *combo = &key_combos[current_combo_index]; |
@@ -166,7 +184,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { | |||
166 | } | 184 | } |
167 | 185 | ||
168 | void matrix_scan_combo(void) { | 186 | void matrix_scan_combo(void) { |
169 | if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) { | 187 | if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { |
170 | 188 | ||
171 | /* This disables the combo, meaning key events for this | 189 | /* This disables the combo, meaning key events for this |
172 | * combo will be handled by the next processors in the chain | 190 | * combo will be handled by the next processors in the chain |
@@ -175,3 +193,26 @@ void matrix_scan_combo(void) { | |||
175 | dump_key_buffer(true); | 193 | dump_key_buffer(true); |
176 | } | 194 | } |
177 | } | 195 | } |
196 | |||
197 | void combo_enable(void) { | ||
198 | b_combo_enable = true; | ||
199 | } | ||
200 | |||
201 | void combo_disable(void) { | ||
202 | b_combo_enable = is_active = false; | ||
203 | timer = 0; | ||
204 | dump_key_buffer(true); | ||
205 | |||
206 | } | ||
207 | |||
208 | void combo_toggle(void) { | ||
209 | if (b_combo_enable) { | ||
210 | combo_disable(); | ||
211 | } else { | ||
212 | combo_enable(); | ||
213 | } | ||
214 | } | ||
215 | |||
216 | bool is_combo_enabled(void) { | ||
217 | return b_combo_enable; | ||
218 | } | ||
diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index f06d2d345..aab284957 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h | |||
@@ -58,4 +58,9 @@ bool process_combo(uint16_t keycode, keyrecord_t *record); | |||
58 | void matrix_scan_combo(void); | 58 | void matrix_scan_combo(void); |
59 | void process_combo_event(uint8_t combo_index, bool pressed); | 59 | void process_combo_event(uint8_t combo_index, bool pressed); |
60 | 60 | ||
61 | void combo_enable(void); | ||
62 | void combo_disable(void); | ||
63 | void combo_toggle(void); | ||
64 | bool is_combo_enabled(void); | ||
65 | |||
61 | #endif | 66 | #endif |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 779c355ef..207e0a826 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
@@ -489,6 +489,9 @@ enum quantum_keycodes { | |||
489 | // Right control, close paren | 489 | // Right control, close paren |
490 | KC_RAPC, | 490 | KC_RAPC, |
491 | 491 | ||
492 | CMB_ON, | ||
493 | CMB_OFF, | ||
494 | CMB_TOG, | ||
492 | // always leave at the end | 495 | // always leave at the end |
493 | SAFE_RANGE | 496 | SAFE_RANGE |
494 | }; | 497 | }; |