-
Notifications
You must be signed in to change notification settings - Fork 75
Key History and Macros #1507
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
base: master
Are you sure you want to change the base?
Key History and Macros #1507
Changes from all commits
6f0bc5e
5beefea
85d2610
09ed5b7
020e556
fee2d62
f5cb996
a12f2dd
6164c3b
ccb9ea9
107d0d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -419,10 +419,21 @@ macro_result_t Macros_ExecMacro(uint8_t macroIndex) | |
| return MacroResult_JumpedForward; | ||
| } | ||
|
|
||
| uint8_t startMacro( | ||
| uint8_t index, | ||
| key_state_t *keyState, | ||
| uint16_t argumentOffset, | ||
| uint8_t keyActivationId, | ||
| uint8_t parentMacroSlot, | ||
| bool runFirstAction, | ||
| const char *inlineText, | ||
| const macro_state_t *parentMacroState | ||
| ); | ||
|
|
||
| macro_result_t Macros_CallMacro(uint8_t macroIndex) | ||
| { | ||
| uint32_t parentSlotIndex = S - MacroState; | ||
| uint8_t childSlotIndex = Macros_StartMacro(macroIndex, S->ms.currentMacroKey, 0, S->ms.keyActivationId, parentSlotIndex, true, NULL); | ||
| uint8_t childSlotIndex = startMacro(macroIndex, S->ms.currentMacroKey, 0, S->ms.keyActivationId, parentSlotIndex, true, NULL, S); | ||
|
|
||
| if (childSlotIndex != 255) { | ||
| unscheduleCurrentSlot(); | ||
|
|
@@ -436,7 +447,7 @@ macro_result_t Macros_CallMacro(uint8_t macroIndex) | |
|
|
||
| macro_result_t Macros_ForkMacro(uint8_t macroIndex) | ||
| { | ||
| Macros_StartMacro(macroIndex, S->ms.currentMacroKey, 0, S->ms.keyActivationId, 255, true, NULL); | ||
| startMacro(macroIndex, S->ms.currentMacroKey, 0, S->ms.keyActivationId, 255, true, NULL, S); | ||
| return MacroResult_Finished; | ||
| } | ||
|
|
||
|
|
@@ -446,7 +457,8 @@ uint8_t initMacro( | |
| uint16_t argumentOffset, | ||
| uint8_t keyActivationId, | ||
| uint8_t parentMacroSlot, | ||
| const char *inlineText | ||
| const char *inlineText, | ||
| const macro_state_t *parentMacroState | ||
kareltucek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| if (!macroIsValid(index) || !findFreeStateSlot() || !findFreeScopeStateSlot()) { | ||
| return 255; | ||
|
|
@@ -460,10 +472,30 @@ uint8_t initMacro( | |
| S->ms.currentMacroIndex = index; | ||
| S->ms.currentMacroKey = keyState; | ||
| S->ms.keyActivationId = keyActivationId; | ||
| S->ms.currentMacroStartTime = CurrentPostponedTime; | ||
| S->ms.currentMacroArgumentOffset = argumentOffset; | ||
| S->ms.parentMacroSlot = parentMacroSlot; | ||
| S->ms.isDoubletap = keyState != NULL && KeyHistory_WasLastDoubletap(); | ||
|
|
||
| if(parentMacroState != NULL) { | ||
| S->ms.currentMacroStartTime = parentMacroState->ms.currentMacroStartTime; | ||
| S->ms.multitapCount = parentMacroState->ms.multitapCount; | ||
| S->ms.previousKeyPressTime = parentMacroState->ms.previousKeyPressTime; | ||
| S->ms.previousKeyId = parentMacroState->ms.previousKeyId; | ||
| S->ms.secondaryRoleState = parentMacroState->ms.secondaryRoleState; | ||
| } | ||
| else { | ||
| S->ms.currentMacroStartTime = CurrentPostponedTime; | ||
| S->ms.multitapCount = 0; | ||
| S->ms.previousKeyPressTime = 0; | ||
| S->ms.previousKeyId = 255; | ||
| if (keyState != NULL) { | ||
| S->ms.multitapCount = KeyHistory_GetMultitapCount(keyState, keyActivationId); | ||
| const key_press_event_t * const prevEvt = KeyHistory_GetPreceedingPress(keyState, keyActivationId); | ||
| if (prevEvt != NULL) { | ||
| S->ms.previousKeyId = Utils_KeyStateToKeyId(prevEvt->keyState); | ||
| S->ms.previousKeyPressTime = prevEvt->timestamp; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If inline text is provided, set up the action before resetToAddressZero | ||
| if (inlineText != NULL) { | ||
|
|
@@ -488,18 +520,19 @@ uint8_t initMacro( | |
|
|
||
|
|
||
| //partentMacroSlot == 255 means no parent | ||
| uint8_t Macros_StartMacro( | ||
| uint8_t startMacro( | ||
| uint8_t index, | ||
| key_state_t *keyState, | ||
| uint16_t argumentOffset, | ||
| uint8_t keyActivationId, | ||
| uint8_t parentMacroSlot, | ||
| bool runFirstAction, | ||
| const char *inlineText | ||
| const char *inlineText, | ||
| const macro_state_t *parentMacroState | ||
| ) { | ||
| macro_state_t* oldState = S; | ||
|
|
||
| uint8_t slotIndex = initMacro(index, keyState, argumentOffset, keyActivationId, parentMacroSlot, inlineText); | ||
| uint8_t slotIndex = initMacro(index, keyState, argumentOffset, keyActivationId, parentMacroSlot, inlineText, parentMacroState); | ||
|
|
||
| if (slotIndex == 255) { | ||
| S = oldState; | ||
|
|
@@ -523,14 +556,25 @@ uint8_t Macros_StartMacro( | |
| return slotIndex; | ||
| } | ||
|
|
||
| uint8_t Macros_StartMacro( | ||
| uint8_t index, | ||
| key_state_t *keyState, | ||
| uint16_t argumentOffset, | ||
| uint8_t keyActivationId, | ||
| bool runFirstAction, | ||
| const char *inlineText | ||
| ) { | ||
| return startMacro(index, keyState, argumentOffset, keyActivationId, MacroIndex_None, runFirstAction, inlineText, NULL); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the forward declaration, these had to move here.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer forward declarations, since moving code wreaks havoc in git archeology sessions. But this is an unimportant nitpick. Feel free to leave it as is.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not be happy with having to maintain the parameter list in two places. If you are okay with that, I will put the functions back and do forward declaration.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ok with that actually 😃 |
||
| } | ||
|
|
||
| uint8_t Macros_StartInlineMacro(const char *text, key_state_t *keyState, uint8_t keyActivationId) | ||
| { | ||
| return Macros_StartMacro(MacroIndex_InlineMacro, keyState, 0, keyActivationId, 255, true, text); | ||
| return startMacro(MacroIndex_InlineMacro, keyState, 0, keyActivationId, MacroIndex_None, true, text, NULL); | ||
| } | ||
|
|
||
| void Macros_ValidateMacro(uint8_t macroIndex, uint16_t argumentOffset, uint8_t moduleId, uint8_t keyIdx, uint8_t keymapIdx, uint8_t layerIdx) { | ||
| bool wasValid = true; | ||
| uint8_t slotIndex = initMacro(macroIndex, NULL, argumentOffset, 255, 255, NULL); | ||
| uint8_t slotIndex = initMacro(macroIndex, NULL, argumentOffset, 255, MacroIndex_None, NULL, NULL); | ||
|
|
||
| if (slotIndex == 255) { | ||
| S = NULL; | ||
|
|
@@ -611,7 +655,7 @@ uint8_t Macros_QueueMacro(uint8_t index, key_state_t *keyState, uint8_t keyActiv | |
| { | ||
| macro_state_t* oldState = S; | ||
|
|
||
| uint8_t slotIndex = initMacro(index, keyState, 0, keyActivationId, 255, NULL); | ||
| uint8_t slotIndex = initMacro(index, keyState, 0, keyActivationId, MacroIndex_None, NULL, NULL); | ||
|
|
||
| if (slotIndex == 255) { | ||
| return slotIndex; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.