From 092c0716e65b0d68bd65573a24bf6e3dffe4f896 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 19:53:16 -0400 Subject: [PATCH 1/8] feat: add dynamic_macro_stop_recording function. --- .../process_keycode/process_dynamic_macro.c | 65 ++++++++++--------- .../process_keycode/process_dynamic_macro.h | 1 + 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index bf6af566e2a8..1f713e432469 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -151,6 +151,40 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin *macro_end = macro_pointer; } +static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; + +/* Pointer to the first buffer element after the first macro. + * Initially points to the very beginning of the buffer since the + * macro is empty. */ +static keyrecord_t *macro_end = macro_buffer; + +/* The other end of the macro buffer. Serves as the beginning of + * the second macro. */ +static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; + +/* Like macro_end but for the second macro. */ +static keyrecord_t *r_macro_end = r_macro_buffer; + +/* A persistent pointer to the current macro position (iterator) + * used during the recording. */ +static keyrecord_t *macro_pointer = NULL; + +/* 0 - no macro is being recorded right now + * 1,2 - either macro 1 or 2 is being recorded */ +static uint8_t macro_id = 0; + +void dynamic_macro_stop_recording(void) { + switch (macro_id) { + case 1: + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; + case 2: + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; + } + macro_id = 0; +} + /* Handle the key events related to the dynamic macros. Should be * called from process_record_user() like this: * @@ -186,27 +220,6 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { * macros or one long macro and one short macro. Or even one empty * and one using the whole buffer. */ - static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; - - /* Pointer to the first buffer element after the first macro. - * Initially points to the very beginning of the buffer since the - * macro is empty. */ - static keyrecord_t *macro_end = macro_buffer; - - /* The other end of the macro buffer. Serves as the beginning of - * the second macro. */ - static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; - - /* Like macro_end but for the second macro. */ - static keyrecord_t *r_macro_end = r_macro_buffer; - - /* A persistent pointer to the current macro position (iterator) - * used during the recording. */ - static keyrecord_t *macro_pointer = NULL; - - /* 0 - no macro is being recorded right now - * 1,2 - either macro 1 or 2 is being recorded */ - static uint8_t macro_id = 0; if (macro_id == 0) { /* No macro recording in progress. */ @@ -238,15 +251,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release * just after the recording * starts for DM_RSTP. */ - switch (macro_id) { - case 1: - dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); - break; - case 2: - dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); - break; - } - macro_id = 0; + dynamic_macro_stop_recording(); } return false; #ifdef DYNAMIC_MACRO_NO_NESTING diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h index ab70726897cb..9841254af4f0 100644 --- a/quantum/process_keycode/process_dynamic_macro.h +++ b/quantum/process_keycode/process_dynamic_macro.h @@ -39,3 +39,4 @@ 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); +void dynamic_macro_stop_recording(void); From 7f9ac41227d99e078049ec7080dd4f0097842f47 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 20:02:24 -0400 Subject: [PATCH 2/8] doc: add a comment describing the new function. --- quantum/process_keycode/process_dynamic_macro.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index 1f713e432469..d20c7045cef0 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -173,6 +173,9 @@ static keyrecord_t *macro_pointer = NULL; * 1,2 - either macro 1 or 2 is being recorded */ static uint8_t macro_id = 0; +/** + * If a dynamic macro is currently being recorded, stop recording. + */ void dynamic_macro_stop_recording(void) { switch (macro_id) { case 1: From f846856b5a565ef18b6ddccaa671e6d853bc622c Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 20:21:51 -0400 Subject: [PATCH 3/8] style: adjust whitespace. --- quantum/process_keycode/process_dynamic_macro.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index d20c7045cef0..03a0af3d3e87 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -174,8 +174,7 @@ static keyrecord_t *macro_pointer = NULL; static uint8_t macro_id = 0; /** - * If a dynamic macro is currently being recorded, stop recording. - */ + * If a dynamic macro is currently being recorded, stop recording. */ void dynamic_macro_stop_recording(void) { switch (macro_id) { case 1: From f545ef5b5d5e2d18898cc7523c66275e90fb8bfc Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 20:29:57 -0400 Subject: [PATCH 4/8] style: adjust indentation. --- quantum/process_keycode/process_dynamic_macro.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index 03a0af3d3e87..df03c5ca48c3 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -177,12 +177,12 @@ static uint8_t macro_id = 0; * If a dynamic macro is currently being recorded, stop recording. */ void dynamic_macro_stop_recording(void) { switch (macro_id) { - case 1: - dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); - break; - case 2: - dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); - break; + case 1: + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; + case 2: + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; } macro_id = 0; } From 59fc56c021ca77a6208210b188356caf8e6c5289 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 20:31:13 -0400 Subject: [PATCH 5/8] style: adjust indentation. --- quantum/process_keycode/process_dynamic_macro.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index df03c5ca48c3..de691b6eaff2 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -178,11 +178,11 @@ static uint8_t macro_id = 0; void dynamic_macro_stop_recording(void) { switch (macro_id) { case 1: - dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); - break; + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; case 2: - dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); - break; + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; } macro_id = 0; } From 736f7d449fb97f505d674694a1f24f46144fce4f Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 20:35:57 -0400 Subject: [PATCH 6/8] style: move a comment. --- .../process_keycode/process_dynamic_macro.c | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index de691b6eaff2..0abc47c019cb 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -151,6 +151,30 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin *macro_end = macro_pointer; } +/* Both macros use the same buffer but read/write on different + * ends of it. + * + * Macro1 is written left-to-right starting from the beginning of + * the buffer. + * + * Macro2 is written right-to-left starting from the end of the + * buffer. + * + * ¯o_buffer macro_end + * v v + * +------------------------------------------------------------+ + * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| + * +------------------------------------------------------------+ + * ^ ^ + * r_macro_end r_macro_buffer + * + * During the recording when one macro encounters the end of the + * other macro, the recording is stopped. Apart from this, there + * are no arbitrary limits for the macros' length in relation to + * each other: for example one can either have two medium sized + * macros or one long macro and one short macro. Or even one empty + * and one using the whole buffer. + */ static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; /* Pointer to the first buffer element after the first macro. @@ -198,31 +222,6 @@ void dynamic_macro_stop_recording(void) { * } */ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { - /* Both macros use the same buffer but read/write on different - * ends of it. - * - * Macro1 is written left-to-right starting from the beginning of - * the buffer. - * - * Macro2 is written right-to-left starting from the end of the - * buffer. - * - * ¯o_buffer macro_end - * v v - * +------------------------------------------------------------+ - * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| - * +------------------------------------------------------------+ - * ^ ^ - * r_macro_end r_macro_buffer - * - * During the recording when one macro encounters the end of the - * other macro, the recording is stopped. Apart from this, there - * are no arbitrary limits for the macros' length in relation to - * each other: for example one can either have two medium sized - * macros or one long macro and one short macro. Or even one empty - * and one using the whole buffer. - */ - if (macro_id == 0) { /* No macro recording in progress. */ if (!record->event.pressed) { From 54fce75e01a6d38277a12dd0340405320cd2710e Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 21:58:07 -0400 Subject: [PATCH 7/8] style: see if the linter likes this formatting better. --- quantum/process_keycode/process_dynamic_macro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index 0abc47c019cb..e8df3749f6be 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -198,7 +198,8 @@ static keyrecord_t *macro_pointer = NULL; static uint8_t macro_id = 0; /** - * If a dynamic macro is currently being recorded, stop recording. */ + * If a dynamic macro is currently being recorded, stop recording. + */ void dynamic_macro_stop_recording(void) { switch (macro_id) { case 1: From 27598ea707b58d90d5d6577a577e2ccc3cc7dc9c Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Thu, 1 Jun 2023 22:03:35 -0400 Subject: [PATCH 8/8] style: see if the linter likes this formatting better. --- quantum/process_keycode/process_dynamic_macro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index e8df3749f6be..a022949d3d3a 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -198,8 +198,8 @@ static keyrecord_t *macro_pointer = NULL; static uint8_t macro_id = 0; /** - * If a dynamic macro is currently being recorded, stop recording. - */ + * If a dynamic macro is currently being recorded, stop recording. + */ void dynamic_macro_stop_recording(void) { switch (macro_id) { case 1: