summaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2024-08-17 17:35:10 -0700
committerGitHub <noreply@github.com>2024-08-18 01:35:10 +0100
commitab4c13e835060f6fb921a7d206e28f9525d34178 (patch)
treebd5f272dccf280f21596f43fd15c275d09d78d3c /quantum/process_keycode
parentfaf51c7449880d38a006a19bf900be547177928a (diff)
Add dynamic macro keyboard callbacks (#24142)
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_dynamic_macro.c52
-rw-r--r--quantum/process_keycode/process_dynamic_macro.h14
2 files changed, 44 insertions, 22 deletions
diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c
index 214cd80a87..f8e8256ac8 100644
--- a/quantum/process_keycode/process_dynamic_macro.c
+++ b/quantum/process_keycode/process_dynamic_macro.c
@@ -38,20 +38,44 @@ void dynamic_macro_led_blink(void) {
38 38
39/* User hooks for Dynamic Macros */ 39/* User hooks for Dynamic Macros */
40 40
41__attribute__((weak)) void dynamic_macro_record_start_user(int8_t direction) { 41__attribute__((weak)) bool dynamic_macro_record_start_kb(int8_t direction) {
42 return dynamic_macro_record_start_user(direction);
43}
44
45__attribute__((weak)) bool dynamic_macro_record_start_user(int8_t direction) {
42 dynamic_macro_led_blink(); 46 dynamic_macro_led_blink();
47 return true;
48}
49
50__attribute__((weak)) bool dynamic_macro_play_kb(int8_t direction) {
51 return dynamic_macro_play_user(direction);
43} 52}
44 53
45__attribute__((weak)) void dynamic_macro_play_user(int8_t direction) { 54__attribute__((weak)) bool dynamic_macro_play_user(int8_t direction) {
46 dynamic_macro_led_blink(); 55 dynamic_macro_led_blink();
56 return true;
57}
58
59__attribute__((weak)) bool dynamic_macro_record_key_kb(int8_t direction, keyrecord_t *record) {
60 return dynamic_macro_record_key_user(direction, record);
47} 61}
48 62
49__attribute__((weak)) void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) { 63__attribute__((weak)) bool dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) {
50 dynamic_macro_led_blink(); 64 dynamic_macro_led_blink();
65 return true;
66}
67
68__attribute__((weak)) bool dynamic_macro_record_end_kb(int8_t direction) {
69 return dynamic_macro_record_end_user(direction);
51} 70}
52 71
53__attribute__((weak)) void dynamic_macro_record_end_user(int8_t direction) { 72__attribute__((weak)) bool dynamic_macro_record_end_user(int8_t direction) {
54 dynamic_macro_led_blink(); 73 dynamic_macro_led_blink();
74 return true;
75}
76
77__attribute__((weak)) bool dynamic_macro_valid_key_kb(uint16_t keycode, keyrecord_t *record) {
78 return dynamic_macro_valid_key_user(keycode, record);
55} 79}
56 80
57__attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrecord_t *record) { 81__attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrecord_t *record) {
@@ -74,7 +98,7 @@ __attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrec
74void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) { 98void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) {
75 dprintln("dynamic macro recording: started"); 99 dprintln("dynamic macro recording: started");
76 100
77 dynamic_macro_record_start_user(direction); 101 dynamic_macro_record_start_kb(direction);
78 102
79 clear_keyboard(); 103 clear_keyboard();
80 layer_clear(); 104 layer_clear();
@@ -108,7 +132,7 @@ void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_
108 132
109 layer_state_set(saved_layer_state); 133 layer_state_set(saved_layer_state);
110 134
111 dynamic_macro_play_user(direction); 135 dynamic_macro_play_kb(direction);
112} 136}
113 137
114/** 138/**
@@ -134,7 +158,7 @@ void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_poi
134 **macro_pointer = *record; 158 **macro_pointer = *record;
135 *macro_pointer += direction; 159 *macro_pointer += direction;
136 } 160 }
137 dynamic_macro_record_key_user(direction, record); 161 dynamic_macro_record_key_kb(direction, record);
138 162
139 dprintf("dynamic macro: slot %d length: %d/%d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer), DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end)); 163 dprintf("dynamic macro: slot %d length: %d/%d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer), DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end));
140} 164}
@@ -144,7 +168,7 @@ void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_poi
144 * pointer to the end of the macro. 168 * pointer to the end of the macro.
145 */ 169 */
146void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) { 170void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) {
147 dynamic_macro_record_end_user(direction); 171 dynamic_macro_record_end_kb(direction);
148 172
149 /* Do not save the keys being held when stopping the recording, 173 /* Do not save the keys being held when stopping the recording,
150 * i.e. the keys used to access the layer DM_RSTP is on. 174 * i.e. the keys used to access the layer DM_RSTP is on.
@@ -220,15 +244,7 @@ void dynamic_macro_stop_recording(void) {
220 macro_id = 0; 244 macro_id = 0;
221} 245}
222 246
223/* Handle the key events related to the dynamic macros. Should be 247/* Handle the key events related to the dynamic macros.
224 * called from process_record_user() like this:
225 *
226 * bool process_record_user(uint16_t keycode, keyrecord_t *record) {
227 * if (!process_record_dynamic_macro(keycode, record)) {
228 * return false;
229 * }
230 * <...THE REST OF THE FUNCTION...>
231 * }
232 */ 248 */
233bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { 249bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
234 if (macro_id == 0) { 250 if (macro_id == 0) {
@@ -271,7 +287,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
271 return false; 287 return false;
272#endif 288#endif
273 default: 289 default:
274 if (dynamic_macro_valid_key_user(keycode, record)) { 290 if (dynamic_macro_valid_key_kb(keycode, record)) {
275 /* Store the key in the macro buffer and process it normally. */ 291 /* Store the key in the macro buffer and process it normally. */
276 switch (macro_id) { 292 switch (macro_id) {
277 case 1: 293 case 1:
diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h
index 2f10733cae..984fc0cd41 100644
--- a/quantum/process_keycode/process_dynamic_macro.h
+++ b/quantum/process_keycode/process_dynamic_macro.h
@@ -37,8 +37,14 @@
37 37
38void dynamic_macro_led_blink(void); 38void dynamic_macro_led_blink(void);
39bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record); 39bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record);
40void dynamic_macro_record_start_user(int8_t direction); 40bool dynamic_macro_record_start_kb(int8_t direction);
41void dynamic_macro_play_user(int8_t direction); 41bool dynamic_macro_record_start_user(int8_t direction);
42void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); 42bool dynamic_macro_play_kb(int8_t direction);
43void dynamic_macro_record_end_user(int8_t direction); 43bool dynamic_macro_play_user(int8_t direction);
44bool dynamic_macro_record_key_kb(int8_t direction, keyrecord_t *record);
45bool dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record);
46bool dynamic_macro_record_end_kb(int8_t direction);
47bool dynamic_macro_record_end_user(int8_t direction);
48bool dynamic_macro_valid_key_kb(uint16_t keycode, keyrecord_t *record);
49bool dynamic_macro_valid_key_user(uint16_t keycode, keyrecord_t *record);
44void dynamic_macro_stop_recording(void); 50void dynamic_macro_stop_recording(void);