home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

keymap.c (16734B)


      1 /* vdemeester personal ergodox layout  */
      2 #include QMK_KEYBOARD_H
      3 #include "led.h"
      4 #include "action_layer.h"
      5 #include "action_util.h"
      6 #include "eeconfig.h"
      7 #include "keymap_bepo.h"
      8 
      9 /* Layers */
     10 enum {
     11   BASE = 0,
     12   NMDIA,
     13   FNLR,
     14   GAME,
     15 };
     16 
     17 /* Macros */
     18 enum {
     19   MDBL0 = 0,
     20 
     21   MFNLR,
     22 
     23   // Cut/Copy/Paste
     24   MCUT,
     25   MCOPY,
     26   MPSTE
     27 };
     28 
     29 /* Fn keys */
     30 enum {
     31   F_BSE = 0,
     32   F_NMEDIA,
     33   F_SFT,
     34   F_ALT,
     35   F_CTRL,
     36   F_GAME
     37 };
     38 
     39 /* States & timers */
     40 uint16_t kf_timers[12];
     41 
     42 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     43   /* Basic layer
     44    *
     45    * ,--------------------------------------------------.            ,---------------------------------------------------.
     46    * |   `    | 1/F1 | 2/F2 | 3/F3 | 4/F4  | 5/F5 | F11/Ins  |       | F12/%| 6/F6 | 7/F7 | 8/F8 | 9/F9 | 0/F10 |    -   |
     47    * |--------+------+------+------+-------+-------------|           |------+------+------+------+------+-------+--------|
     48    * | Tab    |   Q  |   W  |   E  |   R   |   T  |Backsp|           |Backsp|   Y  |   U  |   I  |   O  |   P   |    =   |
     49    * |--------+------+------+------+-------+------|ace   |           |ace   |------+------+------+------+-------+--------|
     50    * |   Fn   |   A  |   S  |   D  |   F   |   G  |------|           |------|   H  |   J  |   K  |   L  |   ;   | '/Shift|
     51    * |--------+------+------+------+-------+------|Enter |           |Enter |------+------+------+------+-------+--------|
     52    * | LShift |   Z  |   X  |   C  |   V   |   B  |      |           |      |   N  |   M  |   ,  |   .  |   /   | \/Shift|
     53    * `--------+------+------+------+-------+-------------'           `-------------+------+------+------+-------+--------'
     54    *   | MUTE |  V+  |  V-  | LGui | A/ESC |                                       | RAlt | MENU |  L3  |       |        |
     55    *   `-----------------------------------'                                       `-------------------------------------'
     56    *                                       ,--------------.       ,-------------.
     57    *                                       |  Del  | PgUp |       | PgUp |  Del |
     58    *                                ,------+-------+------|       |------+------+------.
     59    *                                |      |       | PgDn |       | PgDn |      |      |
     60    *                                |Space | LShft |------|       |------|RShift|Enter |
     61    *                                |      |       | Ctl  |       |  Ctl |      |      |
     62    *                                `---------------------'       `--------------------'
     63    */
     64   // If it accepts an argument (i.e, is a function), it doesn't need KC_.
     65   // Otherwise, it needs KC_*
     66   [BASE] = LAYOUT_ergodox(  // layer 0 : default
     67                   // left hand
     68 		  KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_INSERT,
     69                   KC_TAB,       KC_Q,      KC_W,      KC_E,           KC_R,     KC_T,   KC_BSPC,
     70                   F(F_NMEDIA),     KC_A,      KC_S,      KC_D,           KC_F,     KC_G,
     71                   SFT_T(KC_BSLASH),      KC_Z,      KC_X,      KC_C,           KC_V,     KC_B,    KC_ENT,
     72                   KC_MUTE,  KC_VOLU,    KC_VOLD,  KC_LGUI,  ALT_T(KC_ESC),
     73 
     74                   KC_DELT,  KC_PGUP,
     75                   KC_PGDN,
     76                   KC_SPC,    KC_LSHIFT,  KC_LCTL,
     77 
     78                   // right hand
     79 		  KC_EQUAL, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,
     80                   KC_BSPC,     KC_Y,   KC_U,    KC_I,    KC_O,    KC_P,     KC_LBRACKET,
     81                   KC_H,   KC_J,    KC_K,    KC_L,    KC_SCLN,  SFT_T(KC_QUOT),
     82                   KC_ENT,      KC_N,   KC_M,    KC_COMM, KC_DOT,  KC_SLSH,  KC_RBRACKET,
     83                   KC_RALT, KC_APP, F(F_GAME), KC_UNDEFINED,   KC_UNDEFINED,
     84 
     85                   KC_PGUP, KC_DELT,
     86                   KC_PGDN,
     87                   KC_RCTL, F(F_SFT),  KC_ENT
     88                     ),
     89   /* Navigation and media layer
     90    *
     91    * ,--------------------------------------------------.           ,--------------------------------------------------.
     92    * |        |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |           |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |        |
     93    * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
     94    * |        |      |      | MsUp |      | WHUP | Vol+ |           | Lclk |      | Home |  Up  | End  |      |        |
     95    * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
     96    * |        |      | MsLe | MsDo | MsRi | WHD  |------|           |------|      | Left | Down | Right|      |        |
     97    * |--------+------+------+------+------+------| Vol- |           | Rclk |------+------+------+------+------+--------|
     98    * |        |      |      |      |      |      |      |           |      |      |      |      |      |      |        |
     99    * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
    100    *   |      |      |      |      |      |                                       |      |      |      |      |      |
    101    *   `----------------------------------'                                       `----------------------------------'
    102    *                                        ,-------------.       ,-------------.
    103    *                                        | Mute |      |       |      | Caps |
    104    *                                 ,------|------|------|       |------+------+------.
    105    *                                 |      |      |      |       |      |      |      |
    106    *                                 | Prev | Next |------|       |------| LEAD | Play |
    107    *                                 |      |      |      |       |      |      |      |
    108    *                                 `--------------------'       `--------------------'
    109    */
    110   // SYMBOLS
    111   [NMDIA] = LAYOUT_ergodox(
    112                    // left hand
    113                    KC_UNDEFINED,  KC_F1,         KC_F2,         KC_F3,         KC_F4,         KC_F5,         KC_F6,
    114                    KC_UNDEFINED,  KC_UNDEFINED,  KC_UNDEFINED,  KC_MS_U,       KC_UNDEFINED,  KC_WH_U,  KC_VOLU,
    115                    KC_TRNS,       KC_UNDEFINED,  KC_MS_L,       KC_MS_D,       KC_MS_R,       KC_WH_D,
    116                    KC_UNDEFINED,  KC_UNDEFINED,  KC_UNDEFINED,  KC_UNDEFINED,  KC_UNDEFINED,  KC_UNDEFINED,  KC_VOLD,
    117                    KC_TRNS,       KC_TRNS,       KC_UNDEFINED,  KC_TRNS,       KC_TRNS,
    118                    KC_MUTE,  KC_LEAD,
    119                    KC_TRNS,
    120                    KC_MPRV,  KC_MNXT,  KC_TRNS,
    121                    // right hand
    122                    KC_F7,        KC_F8,          KC_F9,          KC_F10,          KC_F11,          KC_F12,       KC_UNDEFINED,
    123                    KC_BTN1, KC_UNDEFINED,   KC_HOME,        KC_UP,           KC_END,          KC_PGUP, KC_UNDEFINED,
    124                    KC_UNDEFINED,   KC_LEFT,        KC_DOWN,         KC_RIGHT,        KC_PGDN, KC_UNDEFINED,
    125                    KC_BTN2, KC_UNDEFINED,   RGB_TOG,   RGB_MOD,    RGB_HUI,    RGB_HUD, KC_UNDEFINED,
    126                    RGB_SAI,   RGB_SAD,   RGB_SAD,    RGB_VAI,    RGB_VAD,
    127                    KC_TRNS, KC_CAPS,
    128                    KC_TRNS,
    129                    KC_TRNS, KC_TRNS,   KC_MPLY
    130                    ),
    131   /* fn layer
    132    *
    133    * ,--------------------------------------------------.           ,--------------------------------------------------.
    134    * |        |      |      |      |      |      |Insert|           |Insert|Eject |Power |Sleep | Wake |PrtScr|ScrollLk|
    135    * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
    136    * |        |      |      |      |      |      |VolUp |           |      |      |      | MsUp |      | PgUp | Pause  |
    137    * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
    138    * |        |      |      | Calc | Mail |Browsr|------|           |------|      |MsLeft|MsDown|MsRght| PgDn |        |
    139    * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
    140    * |        |      | cut  | copy |paste | Mute |VolDn |           |      |      |      |      |      |      |        |
    141    * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
    142    *   |      |      |      |      |      |                                       | Lclk | Mclk | Rclk |      |      |
    143    *   `----------------------------------'                                       `----------------------------------'
    144    *                                        ,-------------.       ,-------------.
    145    *                                        |      |      |       |      |      |
    146    *                                 ,------|------|------|       |------+------+------.
    147    *                                 |      |      |      |       | Next |      |      |
    148    *                                 | Mute |      |------|       |------|      |      |
    149    *                                 |      |      |      |       | Prev |      |      |
    150    *                                 `--------------------'       `--------------------'
    151    */
    152   // MEDIA AND MOUSE
    153   [FNLR] = LAYOUT_ergodox(
    154                   KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,      KC_TRNS, KC_INS,
    155                   KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,      KC_TRNS, KC_VOLU,
    156                   KC_TRNS, KC_TRNS, KC_TRNS,      KC_CALC,     KC_MAIL,      KC_WHOM,
    157                   KC_TRNS, KC_TRNS, M(MCUT),      M(MCOPY),    M(MPSTE),     KC_MUTE, KC_VOLD,
    158                   KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
    159 
    160                   KC_TRNS, KC_TRNS,
    161                   KC_TRNS,
    162                   KC_MUTE, KC_TRNS, KC_TRNS,
    163                   // right hand
    164                   KC_INS,   KC_EJCT, KC_PWR,  KC_SLEP, KC_WAKE, KC_PSCR, KC_SLCK,
    165                   KC_TRNS,  KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_PAUS,
    166                   KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, KC_TRNS,
    167                   KC_TRNS,  KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
    168                   KC_BTN1, KC_BTN2, KC_BTN3, KC_TRNS, KC_TRNS,
    169 
    170                   KC_TRNS, KC_TRNS,
    171                   KC_BTN4,
    172                   KC_BTN5, KC_MPRV, KC_MNXT
    173                   ),
    174 
    175   /* Keymap 3: Gaming
    176    *
    177    * ,--------------------------------------------------.           ,--------------------------------------------------.
    178    * |   #    |   "  |   «  |   »  |   (  |   )  | INS  |           |      |      |      |      |      |      |        |
    179    * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
    180    * |  TAB   |   1  |  2   | UP   |  3   |  4   |Back  |           |      |      |      |      |      |      |        |
    181    * |--------+------+------+------+------+------|Space |           |      |------+------+------+------+------+--------|
    182    * |   A    |   5  | LEFT | DOWN | RIGHT|  6   |------|           |------|      |      |      |      |      |        |
    183    * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
    184    * |   B    |   7  |  8   |   9  |  0   |  C   |Enter |           |      |      |      |      |      |      |        |
    185    * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
    186    *   | MUTE |  V+  |  V-  | GUI  | LAlt |                                       |      |  L0  |      |      |      |
    187    *   `----------------------------------'                                       `----------------------------------'
    188    *                                        ,-------------.       ,-------------.
    189    *                                        | DEL  | GUI  |       |      |      |
    190    *                                 ,------|------|------|       |------+------+------.
    191    *                                 |      |      | LAlt |       |      |      |      |
    192    *                                 | Space|LShift|------|       |------|      |      |
    193    *                                 |      |      |ctr/Es|       |      |      |      |
    194    *                                 `--------------------'       `--------------------'
    195    */
    196   [GAME] = LAYOUT_ergodox(
    197                   // left hand
    198                   BP_DOLLAR,    BP_DOUBLE_QUOTE,     BP_LEFT_GUILLEMET,   BP_RIGHT_GUILLEMET,   BP_LEFT_PAREN,    BP_RIGHT_PAREN,   KC_INSERT,
    199                   KC_TAB,       KC_KP_1,             KC_KP_2,             KC_UP,                KC_KP_3,          KC_KP_4,          KC_BSPC,
    200                   BP_A,         KC_KP_5,             KC_LEFT,             KC_DOWN,              KC_RIGHT,         KC_KP_6,
    201                   BP_B,         KC_KP_7,             KC_KP_8,             KC_KP_9,              KC_KP_0,          BP_C,             KC_ENT,
    202                   KC_MUTE,      KC_VOLU,             KC_VOLD,             KC_LGUI,              ALT_T(KC_ESC),
    203                   KC_DELETE,        KC_RGUI,
    204                   KC_LALT,
    205                   KC_SPC,           KC_LSHIFT,        KC_LCTL,
    206                   // right hand
    207                   KC_UNDEFINED, KC_UNDEFINED,        KC_UNDEFINED,        KC_UNDEFINED,         KC_UNDEFINED,     KC_UNDEFINED,     KC_UNDEFINED,
    208                   KC_UNDEFINED, KC_UNDEFINED,        KC_UNDEFINED,        KC_UNDEFINED,         KC_UNDEFINED,     KC_UNDEFINED,     KC_UNDEFINED,
    209                   KC_UNDEFINED,        KC_UNDEFINED,        KC_UNDEFINED,         KC_UNDEFINED,     KC_UNDEFINED,     KC_UNDEFINED,
    210                   KC_UNDEFINED, KC_UNDEFINED,        KC_UNDEFINED,        KC_UNDEFINED,         KC_UNDEFINED,     KC_UNDEFINED,     KC_UNDEFINED,
    211                   KC_UNDEFINED,        KC_UNDEFINED,              KC_TRNS,     KC_UNDEFINED,     KC_UNDEFINED,
    212                   KC_UNDEFINED, KC_UNDEFINED,
    213                   KC_UNDEFINED,
    214                   KC_UNDEFINED, KC_UNDEFINED,        KC_UNDEFINED
    215                   ),
    216 };
    217 
    218 const uint16_t PROGMEM fn_actions[] = {
    219   [F_BSE]    = ACTION_LAYER_CLEAR(ON_PRESS),
    220   [F_NMEDIA] = ACTION_LAYER_TAP_TOGGLE(NMDIA),
    221   [F_GAME]   = ACTION_LAYER_TAP_TOGGLE(GAME),
    222   [F_SFT]    = ACTION_MODS_ONESHOT (MOD_LSFT),
    223   [F_ALT]    = ACTION_MODS_ONESHOT (MOD_LALT),
    224   [F_CTRL]   = ACTION_MODS_ONESHOT (MOD_LCTL)
    225 };
    226 
    227 LEADER_EXTERNS();
    228 
    229 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
    230 {
    231   // MACRODOWN only works in this function
    232   switch(id) {
    233   case MDBL0:
    234     if (record->event.pressed) {
    235       return MACRO( I(25), T(P0), T(P0), END );
    236     }
    237     break;
    238   case MFNLR:
    239     // Activate 2 layers at once
    240     // layer_state ^= (1 << NUMR) | (1 << FNLR);
    241     layer_state ^= (1 << FNLR);
    242     break;
    243   case MCUT:
    244     if (record->event.pressed) {
    245       return MACRO(D(LSFT), T(DELT), U(LSFT), END);
    246     }
    247     break;
    248   case MCOPY:
    249     if (record->event.pressed) {
    250       return MACRO(D(LCTL), T(INS), U(LCTL), END);
    251     }
    252     break;
    253   case MPSTE:
    254     if (record->event.pressed) {
    255       return MACRO(D(LSFT), T(INS), U(LSFT), END);
    256     }
    257     break;
    258   }
    259   return MACRO_NONE;
    260 };
    261 
    262 // Runs just one time when the keyboard initializes.
    263 void matrix_init_user(void) {
    264 
    265 };
    266 
    267 void tap (uint16_t codes[]) {
    268   for (int i = 0; codes[i] != 0; i++) {
    269     register_code (codes[i]);
    270     unregister_code (codes[i]);
    271     wait_ms (50);
    272   }
    273 }
    274 
    275 void do_unicode (void) {
    276   register_code (KC_RCTL);
    277   register_code (KC_RSFT);
    278   register_code (KC_U);
    279   unregister_code (KC_U);
    280   unregister_code (KC_RSFT);
    281   unregister_code (KC_RCTL);
    282   wait_ms (100);
    283 }
    284 
    285 // Runs constantly in the background, in a loop.
    286 void matrix_scan_user(void) {
    287 
    288   uint8_t layer = biton32(layer_state);
    289 
    290   ergodox_board_led_on();
    291   ergodox_right_led_1_off();
    292   ergodox_right_led_2_off();
    293   ergodox_right_led_3_off();
    294 
    295   ergodox_right_led_1_set (LED_BRIGHTNESS_LO);
    296   ergodox_right_led_2_set (LED_BRIGHTNESS_LO);
    297   ergodox_right_led_3_set (LED_BRIGHTNESS_LO);
    298 
    299   // led 3: caps lock
    300   if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
    301     ergodox_right_led_1_on();
    302   }
    303   switch (layer) {
    304   case NMDIA:
    305     ergodox_right_led_2_on();
    306     break;
    307   case GAME:
    308     ergodox_right_led_3_on();
    309     break;
    310     //case NUMR:
    311     //ergodox_right_led_3_on();
    312     //break;
    313   default:
    314     // none
    315     break;
    316   }
    317 
    318 
    319   LEADER_DICTIONARY() {
    320     leading = false;
    321     leader_end ();
    322 
    323     SEQ_ONE_KEY (KC_U) {
    324       do_unicode();
    325     }
    326 
    327     SEQ_ONE_KEY (BP_Y) {
    328       uint16_t codes[] = {BP_O, BP_SLSH, 0};
    329       tap (codes);
    330     }
    331 
    332   }
    333   /* // led 1: numeric layer */
    334   /* if (layer_state & (1 << NUMR)) { */
    335   /*     ergodox_right_led_2_on(); */
    336   /* } */
    337   /* // led 2: FNLR */
    338   /* if (default_layer_state == 1 << FNLR) { */
    339   /*     ergodox_right_led_1_on(); */
    340   /* } */
    341 
    342 };