Skip to content

Commit

Permalink
🔨 Extract combo definitions to combos.def
Browse files Browse the repository at this point in the history
  • Loading branch information
sroccaserra committed Jan 7, 2022
1 parent 60faa87 commit 492a245
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 20 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

- <https://docs.qmk.fm/#/keycodes>
- <https://github.com/qmk/qmk_firmware/blob/master/docs/feature_combo.md>
- <https://github.com/qmk/qmk_firmware/pull/8591>
2 changes: 2 additions & 0 deletions moonlander/keymaps/sroccaserra/combos.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMB(qesc_combo, KC_ESCAPE, KC_Q, KC_W)
COMB(ment_combo, KC_ENTER, KC_M, KC_COMMA)
2 changes: 2 additions & 0 deletions moonlander/keymaps/sroccaserra/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 1 addition & 20 deletions moonlander/keymaps/sroccaserra/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;

Expand Down
77 changes: 77 additions & 0 deletions moonlander/keymaps/sroccaserra/keymap_combo.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 492a245

Please sign in to comment.