#include QMK_KEYBOARD_H
enum mitosis_layers
{
_MALT,
_SHIFTED,
_FUNCTION,
_FUNCSHIFT
};
enum mitosis_keycodes
{
FNKEY = SAFE_RANGE,
SHIFT,
M_VOLU,
M_VOLD,
M_ESCM
};
#define LONGPRESS_DELAY 150
#define LAYER_TOGGLE_DELAY 300
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_MALT] = LAYOUT(
KC_Q, KC_P, KC_Y, KC_C, KC_B, KC_V, KC_M, KC_U, KC_Z, KC_L,
KC_A, KC_N, KC_I, KC_S, KC_F, KC_D, KC_T, KC_H, KC_O, KC_R,
KC_COMM, KC_DOT, KC_J, KC_G, KC_SLSH, KC_SCLN, KC_W, KC_K, KC_QUOT, KC_X,
M_VOLU, M_ESCM, KC_TAB, KC_LCTL, KC_LALT, KC_ENT, KC_DEL, KC_PGUP,
M_VOLD, KC_LGUI, KC_E, FNKEY, SHIFT, KC_SPC, KC_BSPC, KC_PGDN
),
[_SHIFTED] = LAYOUT(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______
),
[_FUNCTION] = LAYOUT(
KC_AMPR, KC_PERC, KC_UP, KC_CIRC, KC_PIPE, KC_LBRC, KC_7, KC_8, KC_9, KC_MINS,
KC_AT, KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH, KC_LPRN, KC_4, KC_5, KC_6, KC_PLUS,
KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR, KC_BSLS, KC_LCBR, KC_1, KC_2, KC_3, KC_ENT,
KC_HOME, KC_GRV, KC_PWR, _______, _______, KC_EQL, KC_TILD, KC_DOT,
KC_END, _______, _______, _______, _______, KC_0, _______, KC_PSCR
),
[_FUNCSHIFT] = LAYOUT(
_______, _______, _______, _______, _______, KC_RBRC, KC_F7, KC_F8, KC_F9, KC_F10,
_______, _______, _______, _______, _______, KC_RPRN, KC_F4, KC_F5, KC_F6, KC_F11,
_______, _______, _______, _______, _______, KC_RCBR, KC_F1, KC_F2, KC_F3, KC_F12,
_______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______
)
};
static uint16_t key_timer;
static bool singular_key = false;
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
uint8_t layer;
layer = biton32(layer_state);
switch (keycode) {
case FNKEY:
if (record->event.pressed) {
key_timer = timer_read();
singular_key = true;
layer_on(_FUNCTION);
} else {
if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
layer_off(_FUNCTION);
}
}
update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
return false;
break;
case SHIFT:
if (record->event.pressed) {
key_timer = timer_read();
singular_key = true;
layer_on(_SHIFTED);
register_code(KC_LSFT);
} else {
if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
layer_off(_SHIFTED);
unregister_code(KC_LSFT);
}
}
update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
return false;
break;
case M_VOLU:
if (record->event.pressed) {
key_timer = timer_read(); } else { if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { tap_code(KC_MPLY);
} else {
tap_code(KC_VOLU);
}
}
return false;
case M_VOLD:
if (record->event.pressed) {
key_timer = timer_read();
} else {
if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
tap_code(KC_MNXT);
} else {
tap_code(KC_VOLD);
}
}
return false;
case M_ESCM:
if (record->event.pressed) {
key_timer = timer_read();
} else {
if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
tap_code(KC_APP);
} else {
tap_code(KC_ESC);
}
}
return false;
default:
singular_key = false;
break;
}
if (layer == _FUNCSHIFT) {
if ( (keycode >= KC_F1 && keycode <= KC_F12)
|| keycode == KC_RBRC ) {
if (record->event.pressed) {
unregister_mods(MOD_LSFT);
} else {
register_mods(MOD_LSFT);
}
}
}
return true;
};
void matrix_scan_user(void) {
uint8_t layer = biton32(layer_state);
switch (layer) {
case _MALT:
set_led_off;
break;
case _FUNCTION:
set_led_blue;
break;
case _SHIFTED:
set_led_red;
break;
case _FUNCSHIFT:
set_led_green;
break;
default:
break;
}
};