diff options
| author | Drashna Jaelre <drashna@live.com> | 2024-08-17 17:35:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-18 01:35:10 +0100 |
| commit | ab4c13e835060f6fb921a7d206e28f9525d34178 (patch) | |
| tree | bd5f272dccf280f21596f43fd15c275d09d78d3c /quantum/process_keycode/process_dynamic_macro.c | |
| parent | faf51c7449880d38a006a19bf900be547177928a (diff) | |
Add dynamic macro keyboard callbacks (#24142)
Diffstat (limited to 'quantum/process_keycode/process_dynamic_macro.c')
| -rw-r--r-- | quantum/process_keycode/process_dynamic_macro.c | 52 |
1 files changed, 34 insertions, 18 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 | |||
| 74 | void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) { | 98 | void 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 | */ |
| 146 | void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) { | 170 | void 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 | */ |
| 233 | bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { | 249 | bool 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: |
