]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/ergodox_ez/keymaps/bpruitt-goddard/keymap.c
Merge branch 'master' of github.com:qmk/qmk_firmware into hf/shinydox
[qmk_firmware.git] / keyboards / ergodox_ez / keymaps / bpruitt-goddard / keymap.c
1 // An Ergodox EZ keymap mostly following the programmer's dvorak layout.
2 // There is a standard QWERTY layer as well
3 //
4 // See the README.md file for an image of this keymap.
5
6 #include QMK_KEYBOARD_H
7
8 // The layers that we are defining for this keyboards.
9 #define BASE 0
10 #define NUM 1
11 #define QWERTY 2
12 #define MAC 3
13
14 // The Tap Dance identifiers, used in the TD keycode and tap_dance_actions array.
15 #define TAP_MACRO 0
16
17 // SAFE_RANGE must be used to tag the first element of the enum.
18 // DYNAMIC_MACRO_RANGE must always be the last element of the enum if other
19 // values are added (as its value is used to create a couple of other keycodes
20 // after it).
21 enum custom_keycodes {
22     MC_ARROW = SAFE_RANGE,
23     DYNAMIC_MACRO_RANGE
24 };
25
26 // A 'transparent' key code (that falls back to the layers below it).
27 #define ___ KC_TRANSPARENT
28
29 // A 'blocking' key code. Does nothing but prevent falling back to another layer.
30 #define XXX KC_NO
31
32 // Some combined keys (one normal keycode when tapped and one modifier or layer
33 // toggle when held).
34 #define SPC_RALT  MT(MOD_RALT, KC_SPC)  // SPACE key and right alt modifier.
35
36 // The most portable copy/paste keys (windows (mostly), linux, and some terminal emulators).
37 #define MK_CUT    LSFT(KC_DEL)  // shift + delete
38 #define MK_COPY   LCTL(KC_INS)  // ctrl + insert
39 #define MK_PASTE  LSFT(KC_INS)  // shift + insert
40 //Move mac desktop spaces
41 #define MAC_L     LGUI(LSFT(KC_UP)) // cmd + shift + up
42 #define MAC_R     LGUI(LSFT(KC_DOWN)) // cmd + shift + down
43
44 // This file must be included after DYNAMIC_MACRO_RANGE is defined...
45 #include "dynamic_macro.h"
46
47 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
48   // Layer 0: basic keys.
49   [BASE] = LAYOUT_ergodox_pretty(
50     KC_DLR,           KC_AMPR,  KC_LBRC,  KC_LCBR, KC_RCBR, KC_LPRN, KC_CIRC,           KC_F4,        KC_EQUAL,KC_ASTR, KC_BSLASH, KC_PLUS, KC_RBRACKET, KC_EXLM,
51     GUI_T(KC_BSLASH), KC_SCOLON,KC_COMMA, KC_DOT,  KC_P,    KC_Y,    KC_PERC,           KC_DELETE,    KC_F,    KC_G,    KC_C,      KC_R,    KC_L,        KC_SLASH,
52     MO(NUM),          KC_A,     KC_O,     KC_E,    KC_U,    KC_I,                                     KC_D,    KC_H,    KC_T,      KC_N,    KC_S,        KC_MINUS,
53     KC_LSPO,          KC_QUOTE, KC_Q,     KC_J,    KC_K,    KC_X,    KC_LALT,           TD(TAP_MACRO),KC_B,    KC_M,    KC_W,      KC_V,    KC_Z,        KC_RSPC,
54     KC_AT,            KC_HASH,  KC_GRAVE, KC_LEFT, KC_RIGHT,                                                   KC_UP,   KC_DOWN,   KC_HOME, KC_END,      TO(QWERTY),
55                                          ALT_T(KC_APPLICATION), ALL_T(KC_NO),           KC_PGUP, KC_LGUI,
56                                                                    KC_BSLASH,           TO(MAC),
57                                           KC_ENTER, KC_TAB, CTL_T(KC_ESCAPE),           CTL_T(KC_ESCAPE), KC_BSPACE,  KC_SPACE),
58
59   // Layer 1: function and numpad keys.
60   [NUM] = LAYOUT_ergodox_pretty(
61     ___,  KC_F1,   KC_F2,    KC_F3,       KC_F4,       KC_F5,      ___,         ___, KC_F6,   KC_F7,  KC_F8,  KC_F9,      KC_F10,       KC_F11,
62     ___,  KC_EXLM, KC_COMMA, KC_DOT,      KC_MS_BTN1,  KC_MS_BTN2, ___,         ___, KC_UP,   KC_7,   KC_8,   KC_9,       KC_ASTR,      KC_F12,
63     XXX,  ___,     KC_LCBR,  KC_RCBR,     MC_ARROW,    KC_GRAVE,                     KC_DOWN, KC_4,   KC_5,   KC_6,       KC_PLUS,      KC_UNDS,
64     ___,  ___,     KC_CIRC,  KC_LBRACKET, KC_RBRACKET, KC_TILD,    ___,         ___, KC_0,    KC_1,   KC_2,   KC_3,       KC_KP_SLASH,  KC_BSLASH,
65     ___,  ___,     ___,      ___,         ___,                                                ___,    KC_0,   KC_KP_DOT,  KC_EQUAL,     ___,
66                                                            ___,    ___,         KC_KP_ASTERISK, KC_KP_SLASH,
67                                                                KC_LCTL,         ___,
68                                       KC_KP_PLUS,  KC_KP_MINUS, KC_DLR,         KC_DELETE, KC_BSPACE,  KC_SPACE),
69
70   // Layer 2: QWERTY control.
71   [QWERTY] = LAYOUT_ergodox_pretty(
72     /* left hand */
73     KC_EQUAL,   KC_1,     KC_2,         KC_3,     KC_4,     KC_5,    KC_LEFT,           KC_RIGHT,     KC_6,   KC_7,   KC_8,     KC_9,         KC_0,         KC_MINUS,
74     KC_DELETE,  KC_Q,     KC_W,         KC_E,     KC_R,     KC_T,    KC_Y,              TO(BASE),     KC_Y,   KC_U,   KC_I,     KC_O,         KC_P,         KC_BSLASH,
75     MO(NUM),    KC_A,     KC_S,         KC_D,     KC_F,     KC_G,                                     KC_H,   KC_J,   KC_K,     KC_L,         KC_SCLN,      GUI_T(KC_QUOT),
76     KC_LSFT,    KC_Z,     KC_X,         KC_C,     KC_V,     KC_B, ALT_T(KC_NO),         MEH_T(KC_NO), KC_N,   KC_M,   KC_COMMA, KC_DOT,       KC_SLASH,     KC_RSPC,
77     KC_GRAVE,   KC_QUOTE, LALT(KC_TAB), KC_LEFT,  KC_RIGHT,                                                   KC_UP,  KC_DOWN,  KC_LBRACKET,  KC_RBRACKET,  TO(BASE),
78                                                   ___, KC_LGUI,                         ___, KC_ESCAPE,
79                                                        KC_HOME,                         KC_PGUP,
80                                       KC_ENTER, KC_TAB, KC_END,                         KC_PGDOWN, KC_BSPACE, KC_SPACE),
81
82     // Layer 3: Mac layer
83     [MAC] = LAYOUT_ergodox_pretty(
84       /* left hand */
85       ___,  KC_1, KC_2, KC_3,   KC_4,   KC_5, ___,        ___, KC_6,  KC_7, KC_8, KC_9, KC_0, ___,
86       ___,  ___,  ___,  ___,    ___,    ___,  ___,        ___, ___,   ___,  ___,  ___,  ___,  ___,
87       ___,  ___,  ___,  ___,    ___,    ___,                   ___,   ___,  ___,  ___,  ___,  ___,
88       ___,  ___,  ___,  ___,    ___,    ___,  ___,        ___, ___,   ___,  ___,  ___,  ___,  ___,
89       ___,  ___,  ___,  MAC_L,  MAC_R,                                ___,  ___,  ___,  ___,  ___,
90                                         ___,  ___,        ___, ___,
91                                               ___,        TO(BASE),
92                       KC_LGUI,  KC_LALT,  KC_LGUI,        KC_LGUI, KC_LALT, KC_LGUI),
93 };
94
95 // Whether the macro 1 is currently being recorded.
96 static bool is_macro1_recording = false;
97
98 // The current set of active layers (as a bitmask).
99 // There is a global 'layer_state' variable but it is set after the call
100 // to layer_state_set_user().
101 static uint32_t current_layer_state = 0;
102 uint32_t layer_state_set_user(uint32_t state);
103
104 // Method called at the end of the tap dance on the TAP_MACRO key. That key is
105 // used to start recording a macro (double tap or more), to stop recording (any
106 // number of tap), or to play the recorded macro (1 tap).
107 void macro_tapdance_fn(qk_tap_dance_state_t *state, void *user_data) {
108   uint16_t keycode;
109   keyrecord_t record;
110   dprintf("macro_tap_dance_fn %d\n", state->count);
111   if (is_macro1_recording) {
112     keycode = DYN_REC_STOP;
113     is_macro1_recording = false;
114     layer_state_set_user(current_layer_state);
115   } else if (state->count == 1) {
116     keycode = DYN_MACRO_PLAY1;
117   } else {
118     keycode = DYN_REC_START1;
119     is_macro1_recording = true;
120     layer_state_set_user(current_layer_state);
121   }
122
123   record.event.pressed = true;
124   process_record_dynamic_macro(keycode, &record);
125   record.event.pressed = false;
126   process_record_dynamic_macro(keycode, &record);
127 }
128
129 // The definition of the tap dance actions:
130 qk_tap_dance_action_t tap_dance_actions[] = {
131   // This Tap dance plays the macro 1 on TAP and records it on double tap.
132   [TAP_MACRO] = ACTION_TAP_DANCE_FN(macro_tapdance_fn)
133 };
134
135 // Runs for each key down or up event.
136 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
137   if (keycode != TD(TAP_MACRO)) {
138     // That key is processed by the macro_tapdance_fn. Not ignoring it here is
139     // mostly a no-op except that it is recorded in the macros (and uses space).
140     // We can't just return false when the key is a tap dance, because
141     // process_record_user, is called before the tap dance processing (and
142     // returning false would eat the tap dance).
143     if (!process_record_dynamic_macro(keycode, record)) {
144       return false;
145     }
146
147     if(record->event.pressed) {
148       switch(keycode) {
149         case MC_ARROW:
150           SEND_STRING("=>");
151           return false;
152           break;
153       }
154     }
155   }
156
157   return true; // Let QMK send the enter press/release events
158 }
159
160 // Runs just one time when the keyboard initializes.
161 void matrix_init_user(void) {
162   ergodox_right_led_1_off();
163   ergodox_right_led_2_off();
164   ergodox_right_led_3_off();
165 };
166
167 // Runs constantly in the background, in a loop.
168 void matrix_scan_user(void) {
169
170 };
171
172 // Value to use to switch LEDs on. The default value of 255 is far too bright.
173 static const uint8_t max_led_value = 20;
174
175 // Whether the given layer (one of the constant defined at the top) is active.
176 #define LAYER_ON(layer) (current_layer_state & (1<<layer))
177
178 void led_1_on(void) {
179   ergodox_right_led_1_on();
180   ergodox_right_led_1_set(max_led_value);
181 }
182
183 void led_2_on(void) {
184   ergodox_right_led_2_on();
185   ergodox_right_led_2_set(max_led_value);
186 }
187
188 void led_3_on(void) {
189   ergodox_right_led_3_on();
190   ergodox_right_led_3_set(max_led_value);
191 }
192
193 void led_1_off(void) {
194   ergodox_right_led_1_off();
195 }
196
197 void led_2_off(void) {
198   ergodox_right_led_2_off();
199 }
200
201 void led_3_off(void) {
202   ergodox_right_led_3_off();
203 }
204
205 uint32_t layer_state_set_user(uint32_t state) {
206   current_layer_state = state;
207
208   if (is_macro1_recording) {
209     led_1_on();
210     led_2_on();
211     led_3_on();
212     return state;
213   }
214
215   if (LAYER_ON(NUM)) {
216     led_1_on();
217   } else {
218     led_1_off();
219   }
220
221   if (LAYER_ON(MAC)) {
222     led_2_on();
223   } else {
224     led_2_off();
225   }
226
227   if (LAYER_ON(QWERTY)) {
228     led_3_on();
229   } else {
230     led_3_off();
231   }
232
233   return state;
234 };