qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap_combo.h (2422B)


      1 #pragma once
      2 
      3 // Keymap helpers
      4 // define reference layers per layer.
      5 #define REF_LAYER_FOR_LAYER(LAYER, REF_LAYER)   \
      6   case LAYER: return REF_LAYER;
      7 
      8 #define DEF_REF_LAYER(LAYER)                    \
      9   default: return LAYER;
     10 
     11 #define K_ENUM(name, key, ...) name,
     12 #define K_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
     13 #define K_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
     14 
     15 #define A_ENUM(name, string, ...) name,
     16 #define A_DATA(name, string, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
     17 #define A_COMB(name, string, ...) [name] = COMBO_ACTION(cmb_##name),
     18 #define A_ACTI(name, string, ...)               \
     19     case name:                                  \
     20         if (pressed) SEND_STRING(string);           \
     21         break;
     22 
     23 #define A_TOGG(name, layer, ...)                \
     24     case name:                                    \
     25         if (pressed) layer_invert(layer);             \
     26         break;
     27 
     28 #define BLANK(...)
     29 #undef COMBO_REF_LAYER
     30 #undef DEFAULT_REF_LAYER
     31 #define COMBO_REF_LAYER BLANK
     32 #define DEFAULT_REF_LAYER BLANK
     33 
     34 // Generate data needed for combos/actions
     35 // Create Enum
     36 #undef COMB
     37 #undef SUBS
     38 #undef TOGG
     39 #define COMB K_ENUM
     40 #define SUBS A_ENUM
     41 #define TOGG A_ENUM
     42 enum combos {
     43 #include "combos.def"
     44 };
     45 
     46 // Bake combos into mem
     47 #undef COMB
     48 #undef SUBS
     49 #undef TOGG
     50 #define COMB K_DATA
     51 #define SUBS A_DATA
     52 #define TOGG A_DATA
     53 #include "combos.def"
     54 #undef COMB
     55 #undef SUBS
     56 #undef TOGG
     57 
     58 // Fill combo array
     59 #define COMB K_COMB
     60 #define SUBS A_COMB
     61 #define TOGG A_COMB
     62 combo_t key_combos[] = {
     63 #include "combos.def"
     64 };
     65 #undef COMB
     66 #undef SUBS
     67 #undef TOGG
     68 
     69 // Fill QMK hook
     70 #define COMB BLANK
     71 #define SUBS A_ACTI
     72 #define TOGG A_TOGG
     73 void process_combo_event(uint16_t combo_index, bool pressed) {
     74     switch (combo_index) {
     75 #include "combos.def"
     76     }
     77 
     78     // Allow user overrides per keymap
     79 #if __has_include("inject.h")
     80 # include "inject.h"
     81 #endif
     82 }
     83 #undef COMB
     84 #undef SUBS
     85 #undef TOGG
     86 
     87 // Allow reference layers per layer.
     88 #define COMB BLANK
     89 #define SUBS BLANK
     90 #define TOGG BLANK
     91 
     92 #undef DEFAULT_REF_LAYER
     93 #undef COMBO_REF_LAYER
     94 #define COMBO_REF_LAYER REF_LAYER_FOR_LAYER
     95 #define DEFAULT_REF_LAYER DEF_REF_LAYER
     96 
     97 uint8_t combo_ref_from_layer(uint8_t current_layer){
     98   switch (current_layer){
     99 #include "combos.def"
    100   }
    101   return current_layer;
    102 }
    103 
    104 #undef COMB
    105 #undef SUBS
    106 #undef TOGG
    107 #undef COMBO_REF_LAYER
    108 #undef DEFAULT_REF_LAYER