Advertisement
bennyp

Untitled

Aug 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.64 KB | None | 0 0
  1. #include "ergodox.h"
  2. #include "config.h"
  3. #include "quantum_keycodes.h"
  4. #include "action_layer.h"
  5. #include "version.h"
  6.  
  7. #define _______ KC_TRNS
  8. #define KC_ATM LGUI(LSFT(KC_P))
  9. #define KC_ATP LGUI(LCTL(KC_P))
  10.  
  11. #define BASE 0
  12. #define SYMB 3
  13. #define VIMY 2
  14. #define MOUS 1
  15.  
  16. #define VIM_QUEUE_NONE 0
  17. #define VIM_QUEUE_D 1
  18. #define VIM_QUEUE_V 2
  19.  
  20. #define PRESS(keycode) register_code16(keycode)
  21. #define RELEASE(keycode) unregister_code16(keycode)
  22.  
  23. enum custom_keycodes {
  24.   PLACEHOLDER = SAFE_RANGE, // can always be here
  25.   VIM_END,
  26.   VIM_WOR,
  27.   VIM_BAK,
  28.   VIM_YAN,
  29.   VIM_PUT,
  30.   VIM_OPN,
  31.   VIM_UDO,
  32.   VIM_DEL,
  33.   EPRM,
  34.   VRSN,
  35.   RGB_SLD,
  36. };
  37.  
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39.  
  40.   /* Keymap 0: Basic layer
  41.   *
  42.   * ,--------------------------------------------------.           ,--------------------------------------------------.
  43.   * |    `   |   1  |   2  |   3  |   4  |   5  | ⇧⌘P  |           | PROJ |   6  |   7  |   8  |   9  |   0  |   -    |
  44.   * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
  45.   * |⇥ / SYMB|   Q  |   W  |   E  |   R  |   T  |MOUSE |           | SYMB |   Y  |   U  |   I  |   O  |   P  |   \    |
  46.   * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
  47.   * | ⎋ / VIM|   A  |   S  |   D  |   F  |   G  |------|           |------|   H  |   J  |   K  |   L  |   ;  |   '    |
  48.   * |--------+------+------+------+------+------|   =  |           |   +  |------+------+------+------+------+--------|
  49.   * |   L⇧   |   Z  |   X  |   C  |   V  |   B  |      |           |      |   N  |   M  |   ,  |   .  |   /  |   R⇧   |
  50.   * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
  51.   *   |  ⌃  |   ⌥  |  (   |  [   |   {  |                                       |  }   |  ]   |   )  |   ⌥   |   ⌃  |
  52.   *   `----------------------------------'                                       `----------------------------------'
  53.   *                                        ,-------------.       ,-------------.
  54.   *                                        |   ←  |   ↓  |       |   ↑  |   →  |
  55.   *                                 ,------|------|------|       |------+------+------.
  56.   *                                 |SPACE |      | Home |       | PgUp |ENTER | BSPC |
  57.   *                                 |      | DEL  |------|       |------|      |      |
  58.   *                                 |   ⌘  |      | End  |       | PgDn |MOUSE |   ⌘  |
  59.   *                                 `--------------------'       `--------------------'
  60.   */
  61.  
  62.   [BASE] = KEYMAP(
  63.     // Base Layer Left Hand
  64.     KC_GRV,         KC_1,   KC_2,   KC_3,    KC_4,   KC_5, KC_ATM,
  65.     LT(SYMB,KC_TAB),KC_Q,   KC_W,   KC_E,    KC_R,   KC_T, TG(MOUS),
  66.     LT(VIMY,KC_ESC),KC_A,   KC_S,   KC_D,    KC_F,   KC_G,
  67.     KC_LSFT,        KC_Z,   KC_X,   KC_C,    KC_V,   KC_B, KC_EQL,
  68.     KC_LCTL,        KC_LALT,KC_LPRN,KC_LBRC, KC_LCBR,
  69.  
  70.                                                                 KC_LEFT,KC_DOWN,
  71.                                                                         KC_HOME,
  72.                                                 GUI_T(KC_SPC),  KC_DEL, KC_END,
  73.  
  74.     // Base Layer Right Hand
  75.                               KC_ATP,  KC_6, KC_7,   KC_8,    KC_9,   KC_0,   KC_MINS,
  76.                               TG(SYMB),KC_Y, KC_U,   KC_I,    KC_O,   KC_P,   KC_BSLS,
  77.                                        KC_H, KC_J,   KC_K,    KC_L,   KC_SCLN,LT(VIMY, KC_QUOT),
  78.                               KC_PLUS, KC_N, KC_M,   KC_COMM, KC_DOT, KC_SLSH,KC_RSFT,
  79.                                              KC_RCBR,KC_RBRC, KC_RPRN,KC_RALT,KC_RCTL,
  80.  
  81.     KC_UP,  KC_RGHT,
  82.     KC_PGUP,
  83.     KC_PGDN, LT(MOUS,KC_ENT), GUI_T(KC_BSPC)
  84.   ),
  85.  
  86.   /* Keymap 1: Symbol and Calc layer
  87.   *
  88.   * ,--------------------------------------------------.           ,--------------------------------------------------.
  89.   * | Version|  F1  |  F2  |  F3  |  F4  |  F5  |      |           |      |  F6  |  F7  |  F8  |  F9  |  F10 |   F11  |
  90.   * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
  91.   * |        |   !  |   @  |   {  |   }  |   |  |      |           |      |      |   7  |   8  |   9  |   -  |   F12  |
  92.   * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
  93.   * |        |   #  |   $  |   [  |   ]  |   &  |------|           |------|      |   4  |   5  |   6  |   +  |   F13  |
  94.   * |--------+------+------+------+------+------|      |           |  =   |------+------+------+------+------+--------|
  95.   * |        |   %  |   ^  |   (  |   )  |   ~  |      |           |      |      |   1  |   2  |   3  |   *  |  F14   |
  96.   * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
  97.   *   |      |      |      |      |      |                                       |      |  0   |   .  |   /  |      |
  98.   *   `----------------------------------'                                       `----------------------------------'
  99.   *                                        ,-------------.       ,-------------.
  100.   *                                        |      |      |       |      |      |
  101.   *                                 ,------|------|------|       |------+------+------.
  102.   *                                 |      |      |      |       |      |      |      |
  103.   *                                 |      |      |------|       |------|      |      |
  104.   *                                 |      |      |      |       |      |      |      |
  105.   *                                 `--------------------'       `--------------------'
  106.   */
  107.  
  108.   [SYMB] = KEYMAP(
  109.     // Layer 1 Left Hand
  110.     M(0),   KC_F1,  KC_F2,  KC_F3,  KC_F4,  KC_F5,  _______,
  111.     _______,KC_EXLM,KC_AT,  KC_LCBR,KC_RCBR,KC_PIPE,_______,
  112.     _______,KC_HASH,KC_DLR, KC_LPRN,KC_RPRN,KC_AMPR,
  113.     _______,KC_PERC,KC_CIRC,KC_LBRC,KC_RBRC,KC_TILD,_______,
  114.     _______,_______,_______,_______,_______,
  115.  
  116.                                                               _______,_______,_______,
  117.                                                               _______,_______,_______,
  118.  
  119.     // Layer 1 Right Hand
  120.                               _______,KC_F6,  KC_F7,  KC_F8,  KC_F9,KC_F10, KC_F11,
  121.                               _______,_______,KC_7,   KC_8,   KC_9,   KC_MINS,KC_F12,
  122.                                       _______,KC_4,   KC_5,   KC_6,   KC_PLUS,_______,
  123.                               KC_EQL ,_______,KC_1,   KC_2,   KC_3,   KC_ASTR,_______,
  124.                                               _______,KC_0,   KC_DOT, KC_SLSH,_______,
  125.  
  126.     _______,_______,_______,
  127.     _______,_______,_______
  128.   ),
  129.  
  130.   /* Keymap 2: Vim commands layer
  131.   *
  132.   * ,--------------------------------------------------.           ,--------------------------------------------------.
  133.   * |        |      |      |      |      |      |      |           |      |      | Prev | Play | Next |      |        |
  134.   * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
  135.   * |        |      | WORD |  END |      |      |      |           |      | YANK | UNDO |      | OPEN |  PUT |        |
  136.   * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
  137.   * |        |      |      |      |      |      |------|           |------|  ←   |  ↓   |  ↑   |  →   |      |        |
  138.   * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
  139.   * |        |      |  DEL |      |      | BACK |      |           |      |      |      |      |      |      |        |
  140.   * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
  141.   *   |      |      |      |      |      |                                       | Vol0 | Vol↓ | Vol↑ |      |      |
  142.   *   `----------------------------------'                                       `----------------------------------'
  143.   *                                        ,-------------.       ,-------------.
  144.   *                                        |      |      |       |      |      |
  145.   *                                 ,------|------|------|       |------+------+------.
  146.   *                                 |      |      |      |       |      |      |      |
  147.   *                                 |      |      |------|       |------|      |      |
  148.   *                                 |      |      |      |       |      |      |      |
  149.   *                                 `--------------------'       `--------------------'
  150.   */
  151.  
  152.   [VIMY] = KEYMAP(
  153.     // Layer 2 Left Hand
  154.     _______,_______,_______,_______,_______,_______,_______,
  155.     _______,_______,VIM_WOR,VIM_END,_______,_______,_______,
  156.     _______,_______,_______,_______,_______,_______,
  157.     _______,_______,KC_DEL ,_______,_______,VIM_BAK,_______,
  158.     _______,_______,_______,_______,_______,
  159.  
  160.                                                               _______,_______,_______,
  161.                                                               _______,_______,_______,
  162.  
  163.     // Layer 2 Right Hand
  164.                               _______,_______,_______,_______,_______,_______,_______,
  165.                               _______,VIM_YAN,VIM_UDO,_______,VIM_OPN,VIM_PUT,_______,
  166.                                       KC_LEFT,KC_DOWN,KC_UP,  KC_RGHT,_______,_______,
  167.                               _______,_______,_______,_______,_______,_______,_______,
  168.                                               _______,_______,_______,_______,_______,
  169.  
  170.     _______,_______,_______,
  171.     _______,_______,_______
  172.   ),
  173.  
  174.   /* Keymap 2: Mouse, and Media layer
  175.   *
  176.   * ,--------------------------------------------------.           ,--------------------------------------------------.
  177.   * |        | ☀️↑  | ☀️↓  |      |      |      |      |           |      |  ⏪   |  ▶️  |  ⏩   | 🔇   |  🔈   |   🔊    |
  178.   * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
  179.   * |        |      |      |      |      |      |      |           |      |      |      |  MB3 |      |      |        |
  180.   * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
  181.   * |        |      |      |      |      |      |------|           |------|      | MB1  |MOUSEU| MB2  |      |        |
  182.   * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
  183.   * |        |      |      |      |      |      |      |           |      |      |MOUSEL|MOUSED|MOUSER|      |        |
  184.   * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
  185.   *   |      |      |      |      |      |                                       |WHEELU|      |WHEELD|      |      |
  186.   *   `----------------------------------'                                       `----------------------------------'
  187.   *                                        ,-------------.       ,-------------.
  188.   *                                        |      |      |       |      |      |
  189.   *                                 ,------|------|------|       |------+------+------.
  190.   *                                 |      |      |      |       |      |      |      |
  191.   *                                 |      |      |------|       |------|      |      |
  192.   *                                 |      |      |      |       |      |      |      |
  193.   *                                 `--------------------'       `--------------------'
  194.   */
  195.  
  196.   [MOUS] = KEYMAP(
  197.     // Layer 3 Left Hand
  198.     _______,_______,_______,_______,_______,_______,_______,
  199.     _______,_______,_______,_______,_______,_______,_______,
  200.     _______,_______,_______,_______,_______,_______,
  201.     _______,_______,_______,_______,_______,_______,_______,
  202.     _______,_______,_______,_______,_______,
  203.  
  204.                                                               _______,_______,_______,
  205.                                                               _______,_______,_______,
  206.  
  207.     // Layer 2 Right Hand
  208.                               _______,KC_MRWD,KC_MPLY,KC_MFFD,KC_MUTE,KC_VOLD,KC_VOLU,
  209.                               _______,_______,_______,KC_BTN3,_______,_______,_______,
  210.                                       _______,KC_BTN1,KC_MS_U,KC_BTN2,_______,_______,
  211.                               _______,_______,KC_MS_L,KC_MS_D,KC_MS_R,KC_ACL1,_______,
  212.                                               KC_WH_U,_______,KC_WH_D,KC_ACL0,_______,
  213.  
  214.     _______,_______,_______,
  215.     _______,_______,_______
  216.   )
  217.  
  218. };
  219.  
  220. const uint16_t PROGMEM fn_actions[] = {
  221.   [1] = ACTION_LAYER_TAP_TOGGLE(1)
  222. };
  223.  
  224. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
  225.       switch(id) {
  226.         case 0:
  227.             if (record->event.pressed) {
  228.               SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
  229.             }
  230.             break;
  231.       }
  232.     return MACRO_NONE;
  233. };
  234.  
  235. void TAP(uint16_t keycode) {
  236.     PRESS(keycode);
  237.     RELEASE(keycode);
  238. }
  239.  
  240. // static const uint8_t VIM_DEL_KEYS[6] = {
  241. //   KC_D, KC_W, KC_H, KC_J, KC_K, KC_L
  242. // };
  243.  
  244. int vim_queue = 0;
  245.  
  246. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  247.   switch (vim_queue) {
  248.     case 0:
  249.       switch (keycode) {
  250.  
  251.         // dynamically generate these.
  252.         case EPRM:
  253.           if (record->event.pressed) { eeconfig_init(); }
  254.           return false;
  255.           break;
  256.         case VRSN:
  257.           if (record->event.pressed) { SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION); }
  258.           return false;
  259.           break;
  260.         case RGB_SLD:
  261.           if (record->event.pressed) { rgblight_mode(1); }
  262.           return false;
  263.           break;
  264.  
  265.         /**
  266.          * Vim-like `delete` command
  267.          * Simulates vim's `d` command.
  268.          */
  269.         case VIM_DEL:
  270.           if (record->event.pressed) { vim_queue = VIM_QUEUE_D; }
  271.           return false;
  272.           break;
  273.  
  274.         /**
  275.          * Vim-like `open` command.
  276.          * Works by moving cursor to the end of the current line,
  277.          * then opening a new line with `enter`.
  278.          */
  279.         case VIM_OPN:
  280.           if (record->event.pressed) {
  281.             TAP(KC_END);
  282.             TAP(KC_ENTER);
  283.           }
  284.           return false;
  285.           break;
  286.  
  287.         /**
  288.          * Vim-like `word` command
  289.          * Simulates vim's `w` command by moving the cursor first to the
  290.          * end of the current word, then to the end of the next word,
  291.          * then to the beginning of that word.
  292.          */
  293.         case VIM_WOR:
  294.           if (record->event.pressed) {
  295.             PRESS(KC_LALT);
  296.             TAP(KC_RIGHT);
  297.             TAP(KC_RIGHT);
  298.             TAP(KC_LEFT);
  299.             RELEASE(KC_LALT);
  300.           }
  301.           return false;
  302.           break;
  303.  
  304.         /**
  305.          * Vim-like `end` command
  306.          * Simulates vim's `e` command by sending ⌥→
  307.          */
  308.         case VIM_END:
  309.           if (record->event.pressed) {
  310.             PRESS(KC_LALT);
  311.             TAP(KC_RGHT);
  312.             RELEASE(KC_LALT);
  313.           }
  314.           return false;
  315.           break;
  316.  
  317.         /**
  318.          * Vim-like `back` command
  319.          * Simulates vim's `b` command by sending ⌥←
  320.          */
  321.         case VIM_BAK:
  322.           if (record->event.pressed) {
  323.             PRESS(KC_LALT);
  324.             TAP(KC_LEFT);
  325.             RELEASE(KC_LALT);
  326.           }
  327.           return false;
  328.           break;
  329.  
  330.         /**
  331.          * Vim-like `yank` command
  332.          * Simulates vim's `y` command by sending ⌘C
  333.          */
  334.         case VIM_YAN:
  335.           if (record->event.pressed) {
  336.             PRESS(KC_LGUI);
  337.             TAP(KC_C);
  338.             RELEASE(KC_LGUI);
  339.           }
  340.           return false;
  341.           break;
  342.  
  343.         /**
  344.          * Vim-like `put` command
  345.          * Simulates vim's `p` command by sending ⌘V
  346.          */
  347.         case VIM_PUT:
  348.           if (record->event.pressed) {
  349.             PRESS(KC_LGUI);
  350.             TAP(KC_V);
  351.             RELEASE(KC_LGUI);
  352.           }
  353.           return false;
  354.           break;
  355.  
  356.         /**
  357.          * Vim-like `undo` command
  358.          * Simulates vim's `u` command by sending ⌘Z
  359.          */
  360.         case VIM_UDO:
  361.           if (record->event.pressed) {
  362.             PRESS(KC_LGUI);
  363.             TAP(KC_Z);
  364.             RELEASE(KC_LGUI);
  365.           }
  366.           return false;
  367.           break;
  368.       }
  369.  
  370.     case VIM_QUEUE_D:
  371.       switch (keycode) {
  372.  
  373.         /**
  374.          * Vim-like `delete whole line` command
  375.          * Simulates vim's `dd` command by sending ⌃A to move to start of line,
  376.          * Then sending ⌃K to kill the line.
  377.          */
  378.         case KC_D:
  379.           PRESS(KC_LCTL);
  380.           TAP(KC_A);
  381.           RELEASE(KC_LCTL);
  382.           PRESS(KC_LCTL);
  383.           TAP(KC_K);
  384.           RELEASE(KC_LCTL);
  385.           vim_queue = 0;
  386.           return false;
  387.           break;
  388.  
  389.         /**
  390.          * Vim-like `delete word` command
  391.          * Simulates vim's `dw` command by selecting from the current
  392.          * position until the end of the word then deleting.
  393.          */
  394.         case KC_W:
  395.           PRESS(KC_LSHIFT);
  396.           PRESS(KC_LALT);
  397.           TAP(KC_RIGHT);
  398.           TAP(KC_DELETE);
  399.           RELEASE(KC_LALT);
  400.           RELEASE(KC_LSHIFT);
  401.           vim_queue = 0;
  402.           return false;
  403.           break;
  404.       }
  405.   }
  406.  
  407.   return true;
  408. };
  409.  
  410. void matrix_init_user(void) {
  411.   debug_enable = true;
  412.   debug_mouse = true;
  413. };
  414.  
  415. void matrix_scan_user(void) {
  416.     uint8_t layer = biton32(layer_state);
  417.  
  418.     ergodox_board_led_off();
  419.     ergodox_right_led_1_off();
  420.     ergodox_right_led_2_off();
  421.     ergodox_right_led_3_off();
  422.     switch (layer) {
  423.         case 1:
  424.             ergodox_right_led_1_on();
  425.             break;
  426.         case 2:
  427.             ergodox_right_led_2_on();
  428.             break;
  429.         case 3:
  430.             ergodox_right_led_3_on();
  431.             break;
  432.         case 4:
  433.             ergodox_right_led_1_on();
  434.             ergodox_right_led_2_on();
  435.             break;
  436.         case 5:
  437.             ergodox_right_led_1_on();
  438.             ergodox_right_led_3_on();
  439.             break;
  440.         case 6:
  441.             ergodox_right_led_2_on();
  442.             ergodox_right_led_3_on();
  443.             break;
  444.         case 7:
  445.             ergodox_right_led_1_on();
  446.             ergodox_right_led_2_on();
  447.             ergodox_right_led_3_on();
  448.             break;
  449.         default:
  450.             break;
  451.     }
  452.  
  453. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement