Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic macro callbacks #24142

Merged
merged 7 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add kb hooks for Dynamic Macros and use boolean functions
  • Loading branch information
drashna committed Jul 18, 2024
commit 987e2d34e86d6e2925a6869b671fca7a584406dc
47 changes: 29 additions & 18 deletions quantum/process_keycode/process_dynamic_macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,41 @@ void dynamic_macro_led_blink(void) {

/* User hooks for Dynamic Macros */

__attribute__((weak)) void dynamic_macro_record_start_user(int8_t direction) {
__attribute__((weak)) bool dynamic_macro_record_start_kb(int8_t direction) {
return dynamic_macro_record_start_user(direction);
}

__attribute__((weak)) bool dynamic_macro_record_start_user(int8_t direction) {
dynamic_macro_led_blink();
}

__attribute__((weak)) void dynamic_macro_play_user(int8_t direction) {
__attribute__((weak)) bool dynamic_macro_play_kb(int8_t direction) {
dynamic_macro_play_user(direction);
}
__attribute__((weak)) bool dynamic_macro_play_user(int8_t direction) {
dynamic_macro_led_blink();
}

__attribute__((weak)) void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) {
__attribute__((weak)) bool dynamic_macro_record_key_kb(int8_t direction, keyrecord_t *record) {
return dynamic_macro_record_key_user(direction, record);
}

__attribute__((weak)) bool dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) {
dynamic_macro_led_blink();
}

__attribute__((weak)) void dynamic_macro_record_end_user(int8_t direction) {
__attribute__((weak)) bool dynamic_macro_record_end_kb(int8_t direction) {
return dynamic_macro_record_end_user(direction);
}

__attribute__((weak)) bool dynamic_macro_record_end_user(int8_t direction) {
dynamic_macro_led_blink();
}

__attribute__((weak)) bool dynamic_macro_valid_key_kb(uint16_t keycode, keyrecord_t *record) {
return dynamic_macro_valid_key_user(keycode, record);
}

__attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
Expand All @@ -74,7 +93,7 @@ __attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrec
void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) {
dprintln("dynamic macro recording: started");

dynamic_macro_record_start_user(direction);
dynamic_macro_record_start_kb(direction);

clear_keyboard();
layer_clear();
Expand Down Expand Up @@ -108,7 +127,7 @@ void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_

layer_state_set(saved_layer_state);

dynamic_macro_play_user(direction);
dynamic_macro_play_kb(direction);
}

/**
Expand All @@ -134,7 +153,7 @@ void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_poi
**macro_pointer = *record;
*macro_pointer += direction;
}
dynamic_macro_record_key_user(direction, record);
dynamic_macro_record_key_kb(direction, record);

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));
}
Expand All @@ -144,7 +163,7 @@ void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_poi
* pointer to the end of the macro.
*/
void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) {
dynamic_macro_record_end_user(direction);
dynamic_macro_record_end_kb(direction);

/* Do not save the keys being held when stopping the recording,
* i.e. the keys used to access the layer DM_RSTP is on.
Expand Down Expand Up @@ -220,15 +239,7 @@ void dynamic_macro_stop_recording(void) {
macro_id = 0;
}

/* Handle the key events related to the dynamic macros. Should be
* called from process_record_user() like this:
*
* bool process_record_user(uint16_t keycode, keyrecord_t *record) {
* if (!process_record_dynamic_macro(keycode, record)) {
* return false;
* }
* <...THE REST OF THE FUNCTION...>
* }
/* Handle the key events related to the dynamic macros.
*/
bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
if (macro_id == 0) {
Expand Down Expand Up @@ -271,7 +282,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
return false;
#endif
default:
if (dynamic_macro_valid_key_user(keycode, record)) {
if (dynamic_macro_valid_key_kb(keycode, record)) {
/* Store the key in the macro buffer and process it normally. */
switch (macro_id) {
case 1:
Expand Down
14 changes: 10 additions & 4 deletions quantum/process_keycode/process_dynamic_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@

void dynamic_macro_led_blink(void);
bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record);
void dynamic_macro_record_start_user(int8_t direction);
void dynamic_macro_play_user(int8_t direction);
void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record);
void dynamic_macro_record_end_user(int8_t direction);
bool dynamic_macro_record_start_kb(int8_t direction);
bool dynamic_macro_record_start_user(int8_t direction);
bool dynamic_macro_play_kb(int8_t direction);
bool dynamic_macro_play_user(int8_t direction);
bool dynamic_macro_record_key_kb(int8_t direction, keyrecord_t *record);
bool dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record);
bool dynamic_macro_record_end_kb(int8_t direction);
bool dynamic_macro_record_end_user(int8_t direction);
bool dynamic_macro_valid_key_kb(uint16_t keycode, keyrecord_t *record);
bool dynamic_macro_valid_key_user(uint16_t keycode, keyrecord_t *record);
void dynamic_macro_stop_recording(void);