#include QMK_KEYBOARD_H
#define BASE 0
#define NUM 1
#define QWERTY 2
#define MAC 3
#define TAP_MACRO 0
enum custom_keycodes {
MC_ARROW = SAFE_RANGE,
DYNAMIC_MACRO_RANGE
};
#define ___ KC_TRANSPARENT
#define XXX KC_NO
#define SPC_RALT MT(MOD_RALT, KC_SPC)
#define MK_CUT LSFT(KC_DEL)
#define MK_COPY LCTL(KC_INS)
#define MK_PASTE LSFT(KC_INS)
#define MAC_L LGUI(LSFT(KC_UP))
#define MAC_R LGUI(LSFT(KC_DOWN))
#include "dynamic_macro.h"
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[BASE] = LAYOUT_ergodox_pretty(
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,
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,
MO(NUM), KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_MINUS,
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,
KC_AT, KC_HASH, KC_GRAVE, KC_LEFT, KC_RIGHT, KC_UP, KC_DOWN, KC_HOME, KC_END, TO(QWERTY),
ALT_T(KC_APPLICATION), ALL_T(KC_NO), KC_PGUP, KC_LGUI,
KC_BSLASH, TO(MAC),
KC_ENTER, KC_TAB, CTL_T(KC_ESCAPE), CTL_T(KC_ESCAPE), KC_BSPACE, KC_SPACE),
[NUM] = LAYOUT_ergodox_pretty(
___, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, ___, ___, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
___, KC_EXLM, KC_COMMA, KC_DOT, KC_MS_BTN1, KC_MS_BTN2, ___, ___, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12,
XXX, ___, KC_LCBR, KC_RCBR, MC_ARROW, KC_GRAVE, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_UNDS,
___, ___, KC_CIRC, KC_LBRACKET, KC_RBRACKET, KC_TILD, ___, ___, KC_0, KC_1, KC_2, KC_3, KC_KP_SLASH, KC_BSLASH,
___, ___, ___, ___, ___, ___, KC_0, KC_KP_DOT, KC_EQUAL, ___,
___, ___, KC_KP_ASTERISK, KC_KP_SLASH,
KC_LCTL, ___,
KC_KP_PLUS, KC_KP_MINUS, KC_DLR, KC_DELETE, KC_BSPACE, KC_SPACE),
[QWERTY] = LAYOUT_ergodox_pretty(
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,
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,
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),
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,
KC_GRAVE, KC_QUOTE, LALT(KC_TAB), KC_LEFT, KC_RIGHT, KC_UP, KC_DOWN, KC_LBRACKET, KC_RBRACKET, TO(BASE),
___, KC_LGUI, ___, KC_ESCAPE,
KC_HOME, KC_PGUP,
KC_ENTER, KC_TAB, KC_END, KC_PGDOWN, KC_BSPACE, KC_SPACE),
[MAC] = LAYOUT_ergodox_pretty(
___, KC_1, KC_2, KC_3, KC_4, KC_5, ___, ___, KC_6, KC_7, KC_8, KC_9, KC_0, ___,
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
___, ___, ___, MAC_L, MAC_R, ___, ___, ___, ___, ___,
___, ___, ___, ___,
___, TO(BASE),
KC_LGUI, KC_LALT, KC_LGUI, KC_LGUI, KC_LALT, KC_LGUI),
};
static bool is_macro1_recording = false;
static uint32_t current_layer_state = 0;
uint32_t layer_state_set_user(uint32_t state);
void macro_tapdance_fn(qk_tap_dance_state_t *state, void *user_data) {
uint16_t keycode;
keyrecord_t record;
dprintf("macro_tap_dance_fn %d\n", state->count);
if (is_macro1_recording) {
keycode = DYN_REC_STOP;
is_macro1_recording = false;
layer_state_set_user(current_layer_state);
} else if (state->count == 1) {
keycode = DYN_MACRO_PLAY1;
} else {
keycode = DYN_REC_START1;
is_macro1_recording = true;
layer_state_set_user(current_layer_state);
}
record.event.pressed = true;
process_record_dynamic_macro(keycode, &record);
record.event.pressed = false;
process_record_dynamic_macro(keycode, &record);
}
qk_tap_dance_action_t tap_dance_actions[] = {
[TAP_MACRO] = ACTION_TAP_DANCE_FN(macro_tapdance_fn)
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (keycode != TD(TAP_MACRO)) {
if (!process_record_dynamic_macro(keycode, record)) {
return false;
}
if(record->event.pressed) {
switch(keycode) {
case MC_ARROW:
SEND_STRING("=>");
return false;
break;
}
}
}
return true; }
void matrix_init_user(void) {
ergodox_right_led_1_off();
ergodox_right_led_2_off();
ergodox_right_led_3_off();
};
void matrix_scan_user(void) {
};
static const uint8_t max_led_value = 20;
#define LAYER_ON(layer) (current_layer_state & (1<<layer))
void led_1_on(void) {
ergodox_right_led_1_on();
ergodox_right_led_1_set(max_led_value);
}
void led_2_on(void) {
ergodox_right_led_2_on();
ergodox_right_led_2_set(max_led_value);
}
void led_3_on(void) {
ergodox_right_led_3_on();
ergodox_right_led_3_set(max_led_value);
}
void led_1_off(void) {
ergodox_right_led_1_off();
}
void led_2_off(void) {
ergodox_right_led_2_off();
}
void led_3_off(void) {
ergodox_right_led_3_off();
}
uint32_t layer_state_set_user(uint32_t state) {
current_layer_state = state;
if (is_macro1_recording) {
led_1_on();
led_2_on();
led_3_on();
return state;
}
if (LAYER_ON(NUM)) {
led_1_on();
} else {
led_1_off();
}
if (LAYER_ON(MAC)) {
led_2_on();
} else {
led_2_off();
}
if (LAYER_ON(QWERTY)) {
led_3_on();
} else {
led_3_off();
}
return state;
};