diff --git a/src/Macros.cpp b/src/Macros.cpp new file mode 100644 index 00000000..2602dca4 --- /dev/null +++ b/src/Macros.cpp @@ -0,0 +1,21 @@ +#include "Macros.h" +#include "hooks.h" + +__attribute__((weak)) +void +macroAction(uint8_t macroIndex, uint8_t keyState) { +} + +static bool handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { + if (!(mappedKey.flags & (SYNTHETIC|IS_MACRO))) + return false; + + macroAction(mappedKey.rawKey, keyState); + return true; +} + +Macros_::Macros_ (void) { + event_handler_hook_add (handleMacroEvent); +} + +Macros_ Macros; diff --git a/src/Macros.h b/src/Macros.h new file mode 100644 index 00000000..12c4e352 --- /dev/null +++ b/src/Macros.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include "key_defs.h" + +#define IS_MACRO B00000001 + +#define M(n) (Key){ KEY_FLAGS|SYNTHETIC|IS_MACRO, n} +#define Key_macroKey1 M(1) +#define Key_macroKey2 M(2) +#define Key_macroKey3 M(3) +#define Key_macroKey4 M(4) +#define Key_macroKey5 M(5) +#define Key_macroKey6 M(6) +#define Key_macroKey7 M(7) +#define Key_macroKey8 M(8) +#define Key_macroKey9 M(9) +#define Key_macroKey10 M(10) + +void macroAction(uint8_t macroIndex, uint8_t keyState); + +class Macros_ { + public: + Macros_(void); +}; + +extern Macros_ Macros; diff --git a/src/key_defs.h b/src/key_defs.h index aa4e7032..fbcb1ccf 100644 --- a/src/key_defs.h +++ b/src/key_defs.h @@ -22,7 +22,6 @@ typedef union { #define SYNTHETIC B10000000 // we assert that synthetic keys can never have keys held, so we reuse the _HELD bits -#define IS_MACRO B00000001 #define IS_SYSCTL B00000010 #define IS_CONSUMER B00000100 #define IS_INTERNAL B00001000 @@ -52,18 +51,6 @@ typedef union { #define Key_NoKey (Key){ KEY_FLAGS,0 } #define Key_skip (Key){ KEY_FLAGS,0 } -#define M(n) (Key){ KEY_FLAGS|SYNTHETIC|IS_MACRO, n} -#define Key_macroKey1 M(1) -#define Key_macroKey2 M(2) -#define Key_macroKey3 M(3) -#define Key_macroKey4 M(4) -#define Key_macroKey5 M(5) -#define Key_macroKey6 M(6) -#define Key_macroKey7 M(7) -#define Key_macroKey8 M(8) -#define Key_macroKey9 M(9) -#define Key_macroKey10 M(10) - #define Key_powerDown (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_POWER_DOWN } #define Key_sleep (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_SLEEP } diff --git a/src/key_events.cpp b/src/key_events.cpp index 9795ce2a..ff071c66 100644 --- a/src/key_events.cpp +++ b/src/key_events.cpp @@ -1,16 +1,6 @@ #include "key_events.h" -__attribute__((weak)) -void -macroAction(uint8_t macroIndex, uint8_t keyState) { -} - void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) { - if (mappedKey.flags & IS_MACRO) { - macroAction(mappedKey.rawKey, keyState); - return; - } - if (!key_toggled_on(keyState)) return; diff --git a/src/key_events.h b/src/key_events.h index a8336927..ec917b48 100644 --- a/src/key_events.h +++ b/src/key_events.h @@ -8,6 +8,7 @@ #include "Storage.h" #include "keymap_metadata.h" #include "hooks.h" +#include "Macros.h" //static const Key keymaps[KEYMAPS][ROWS][COLS]; extern uint8_t primary_keymap; @@ -45,8 +46,6 @@ extern const Key keymaps[][ROWS][COLS]; */ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState); -void macroAction(uint8_t macroIndex, uint8_t keyState); - // Internal use void handle_synthetic_key_event( Key mappedKey, uint8_t keyState); void press_key(Key mappedKey);