diff --git a/README.md b/README.md index d85a0a4..e09b8da 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,12 @@ Initial layout version: - From the root of the `qmk_firmware` directory, `make moonlander:sroccaserra` to build the firmware. - `make moonlander:sroccaserra:flash` to flash the firmware. + +## Combos + +For firmware 20, updating `COMBO_COUNT` in config.h is still necessary. It +won't be needed anymore with firmware 21. (See PR below.) + +- +- +- diff --git a/moonlander/keymaps/sroccaserra/combos.def b/moonlander/keymaps/sroccaserra/combos.def new file mode 100644 index 0000000..43ff6f4 --- /dev/null +++ b/moonlander/keymaps/sroccaserra/combos.def @@ -0,0 +1,2 @@ +COMB(qesc_combo, KC_ESCAPE, KC_Q, KC_W) +COMB(ment_combo, KC_ENTER, KC_M, KC_COMMA) diff --git a/moonlander/keymaps/sroccaserra/config.h b/moonlander/keymaps/sroccaserra/config.h index 6f36174..e985d55 100644 --- a/moonlander/keymaps/sroccaserra/config.h +++ b/moonlander/keymaps/sroccaserra/config.h @@ -12,6 +12,8 @@ #define FIRMWARE_VERSION u8"jXKZa/mDJvX" #define RGB_MATRIX_STARTUP_SPD 60 +// Note: COMBO_COUNT will no longer be needed with firmware 21, see: +// - https://github.com/qmk/qmk_firmware/pull/8591 #define COMBO_COUNT 2 #define COMBO_TERM 40 #define COMBO_PERMISSIVE_HOLD diff --git a/moonlander/keymaps/sroccaserra/keymap.c b/moonlander/keymaps/sroccaserra/keymap.c index e54baed..d3ff4ba 100644 --- a/moonlander/keymaps/sroccaserra/keymap.c +++ b/moonlander/keymaps/sroccaserra/keymap.c @@ -30,7 +30,7 @@ enum custom_keycodes { FR_RSPC, }; - +#include "keymap_combo.h" const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT_moonlander( @@ -83,25 +83,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), }; -/// -// Start combos - -// Note: also update COMBO_COUNT in config.h -// -// - https://docs.qmk.fm/#/keycodes -// - https://github.com/qmk/qmk_firmware/blob/master/docs/feature_combo.md - -const uint16_t PROGMEM esc_combo[] = { KC_E, KC_R, COMBO_END }; -const uint16_t PROGMEM enter_combo[] = { KC_COMMA, KC_DOT, COMBO_END }; - -combo_t key_combos[COMBO_COUNT] = { - COMBO(esc_combo, KC_ESCAPE), - COMBO(enter_combo, KC_ENTER), -}; - -// End combos -/// - extern bool g_suspend_state; extern rgb_config_t rgb_matrix_config; diff --git a/moonlander/keymaps/sroccaserra/keymap_combo.h b/moonlander/keymaps/sroccaserra/keymap_combo.h new file mode 100644 index 0000000..601257d --- /dev/null +++ b/moonlander/keymaps/sroccaserra/keymap_combo.h @@ -0,0 +1,77 @@ +// Keymap helpers +// +// + +#define K_ENUM(name, key, ...) name, +#define K_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END}; +#define K_COMB(name, key, ...) [name] = COMBO(cmb_##name, key), + +#define A_ENUM(name, string, ...) name, +#define A_DATA(name, string, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END}; +#define A_COMB(name, string, ...) [name] = COMBO_ACTION(cmb_##name), +#define A_ACTI(name, string, ...) \ + case name: \ + if (pressed) SEND_STRING(string); \ + break; + +#define A_TOGG(name, layer, ...) \ + case name: \ + if (pressed) layer_invert(layer); \ + break; + +#define BLANK(...) +// Generate data needed for combos/actions +// Create Enum +#undef COMB +#undef SUBS +#undef TOGG +#define COMB K_ENUM +#define SUBS A_ENUM +#define TOGG A_ENUM +enum combos { +#include "combos.def" + COMBO_LENGTH, +}; +// Export length to combo module +uint16_t COMBO_LEN = COMBO_LENGTH; + +// Bake combos into mem +#undef COMB +#undef SUBS +#undef TOGG +#define COMB K_DATA +#define SUBS A_DATA +#define TOGG A_DATA +#include "combos.def" +#undef COMB +#undef SUBS +#undef TOGG + +// Fill combo array +#define COMB K_COMB +#define SUBS A_COMB +#define TOGG A_COMB +combo_t key_combos[] = { +#include "combos.def" +}; +#undef COMB +#undef SUBS +#undef TOGG + +// Fill QMK hook +#define COMB BLANK +#define SUBS A_ACTI +#define TOGG A_TOGG +void process_combo_event(uint16_t combo_index, bool pressed) { + switch (combo_index) { +#include "combos.def" + } + + // Allow user overrides per keymap +#if __has_include("inject.h") +# include "inject.h" +#endif +} +#undef COMB +#undef SUBS +#undef TOGG