/*
Copyright 2019 @foostan
Copyright 2020 Drashna Jaelre <@drashna>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include QMK_KEYBOARD_H
#include
// Layer names {{{
#define _QWERTY 0
#define _GAMING 1
#define _LOWER 2
#define _UPPER 3
#define _UTIL 4
#define _MOUSE 5
#define _TERRA_A 6
#define _TERRA_B 7
// }}}
// inkch's self defined keycodes. {{{
enum metatap {
MT_LGUI = SAFE_RANGE,
MT_RGUI,
MT_LCTL,
};
#define C_Z LCTL(KC_Z)
#define CS_Z LCTL(S(KC_Z))
#define C_X LCTL(KC_X)
#define C_C LCTL(KC_C)
#define C_V LCTL(KC_V)
#define C_RIGHT LCTL(KC_RIGHT)
#define C_LEFT LCTL(KC_LEFT)
#define C_BSPC LCTL(KC_BSPC)
#define C_DEL LCTL(KC_DEL)
#define C_ENT LCTL(KC_ENT)
#define A_GRV LALT(KC_GRV)
#define A_ENT LALT(KC_ENT)
#define MO_LOWR MO(_LOWER)
#define MO_UPPR MO(_UPPER)
#define MO_UTIL MO(_UTIL)
#define MO_MOUS MO(_MOUSE)
#define DF_QWRT DF(_QWERTY)
#define DF_GAME DF(_GAMING)
#define DF_TRRA DF(_TERRA_A)
#define MO_TRRB MO(_TERRA_B)
#define OS_LCTL OSM(MOD_LCTL)
#define OS_LALT OSM(MOD_LALT)
#define OS_LGUI OSM(MOD_LGUI)
#define OS_LSFT OSM(MOD_LSFT)
#define OS_HYPR OSM(MOD_HYPR)
#define OSL_UTL OSL(_UTIL)
// }}}
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QWERTY] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,-----------------------------------------------------.
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_ESC,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
KC_LALT, MT_LGUI, MO_LOWR, MO_UPPR, MT_LCTL, KC_RALT
//`--------------------------' `--------------------------'
),
[_GAMING] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,-----------------------------------------------------.
KC_Y, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, DF_QWRT,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_H, KC_A, KC_S, KC_D, KC_F, KC_G, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, MO_UTIL,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_N, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_LALT,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
KC_ESC, KC_O, KC_SPC, KC_F16, KC_F17, KC_F18
//`--------------------------' `--------------------------'
),
[_TERRA_A] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,-----------------------------------------------------.
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, DF_QWRT,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, MO_UTIL,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_LALT,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
KC_LALT, MO_TRRB, KC_SPC, KC_F16, KC_F17, KC_F18
//`--------------------------' `--------------------------'
),
[_TERRA_B] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,-----------------------------------------------------.
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, DF_QWRT,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_1, KC_2, KC_3, KC_4, KC_5, KC_F6, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, MO_UTIL,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_6, KC_7, KC_8, KC_9, KC_0, KC_F7, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_LALT,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
_______, XXXXXXX, _______, KC_F16, KC_F17, KC_F18
//`--------------------------' `--------------------------'
),
[_LOWER] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,-----------------------------------------------------.
_______, KC_ESC, KC_TAB, KC_END, XXXXXXX, XXXXXXX, C_LEFT, KC_PGDN, KC_PGUP, C_RIGHT, KC_PSCR, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, KC_HOME, OS_LSFT, KC_DEL, OS_LGUI, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, KC_COLN, KC_DQUO,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, OS_HYPR, C_X, OS_LCTL, OS_LALT, XXXXXXX, A_ENT, C_ENT, KC_LT, KC_GT, KC_QUES, _______,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______
//`--------------------------' `--------------------------'
),
[_UPPER] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,-----------------------------------------------------.
_______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_LPRN, KC_RPRN, KC_ASTR, KC_TILD,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_PIPE, KC_GRV,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, KC_6, KC_7, KC_8, KC_9, KC_0, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_BSLS, _______,
//|--------+--------+--------+--------+--------+--------+---------| |-------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______
//`---------------------------' `-------------------------'
),
[_UTIL] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,--------------------------------------------+--------.
_______, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, DF_TRRA, DF_GAME,
//|--------+--------+--------+--------+--------+--------| |--------+----------+------+--------+--------+--------|
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, A_GRV,
//|--------+--------+--------+--------+--------+--------| |--------+----------+------+--------+--------+--------|
_______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F21, KC_F22, KC_F23, KC_F24, XXXXXXX, KC_LALT,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______
//`--------------------------' `--------------------------'
),
[_MOUSE] = LAYOUT_split_3x6_3(
//,-----------------------------------------------------. ,--------------------------------------------+--------.
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, XXXXXXX, XXXXXXX,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_LCTL, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MS_L, KC_MS_D, KC_MS_U, KC_MS_R, XXXXXXX, XXXXXXX,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BTN4, KC_BTN5, XXXXXXX, XXXXXXX, XXXXXXX,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, KC_BTN1, KC_BTN2, KC_BTN3
//`--------------------------' `--------------------------'
)
};
bool is_tapped(uint16_t pressed_time, uint16_t released_time) {
return TIMER_DIFF_16(released_time, pressed_time) < TAPPING_TERM;
}
#define METATAP_MAX_NUM 2
struct Metatap_State {
uint16_t meta;
bool pressed;
bool registered;
uint16_t pressed_time;
uint16_t tapcode[METATAP_MAX_NUM]; // Keycodes array sent when tapped
};
struct Metatap_State mt_lgui = {KC_LGUI, false, false, 0, {KC_LEFT_CTRL, KC_F13}};
struct Metatap_State mt_lctl = {KC_LCTL, false, false, 0, {KC_LEFT_SHIFT, KC_F13}};
bool is_metatap_code(uint16_t keycode) {
return MT_LGUI <= keycode && keycode <= MT_LCTL;
}
void handle_metatap(uint16_t keycode, keyrecord_t *record) {
if (!is_metatap_code(keycode)) return;
struct Metatap_State *mt;
if (keycode == MT_LGUI) mt = &mt_lgui;
if (keycode == MT_LCTL) mt = &mt_lctl;
if (record->event.pressed) {
mt->pressed = true;
mt->pressed_time = record->event.time;
} else {
if (mt->registered) {
unregister_code(mt->meta);
mt->registered = false;
} else if (mt->pressed && is_tapped(mt->pressed_time, record->event.time)) {
caps_word_off();
for (int i=0; itapcode[i]) break;
register_code(mt->tapcode[i]);
}
for (int i=METATAP_MAX_NUM-1;i>=0;i--) {
if (!mt->tapcode[i]) break;
unregister_code(mt->tapcode[i]);
}
}
mt->pressed = false;
}
}
void register_meta_if_needed(void) {
if (mt_lgui.pressed && !mt_lgui.registered) {
register_code(mt_lgui.meta);
mt_lgui.registered = true;
}
if (mt_lctl.pressed && !mt_lctl.registered) {
register_code(mt_lctl.meta);
mt_lctl.registered = true;
}
}
struct Layer_Solo_State {
int layer;
bool solo;
uint16_t pressed_time;
uint16_t tapcode; // Keycode sent when tapped
};
struct Layer_Solo_State lower = {_LOWER, false, 0, KC_SPC};
struct Layer_Solo_State upper = {_UPPER, false, 0, KC_ENT};
void handle_lu(uint16_t keycode, keyrecord_t *record) {
struct Layer_Solo_State *state;
if (keycode == MO(_LOWER)) state = &lower;
if (keycode == MO(_UPPER)) state = &upper;
if (record->event.pressed) {
state->solo = true;
layer_on(state->layer);
update_tri_layer(_LOWER, _UPPER, _UTIL);
state->pressed_time = record->event.time;
} else {
layer_off(state->layer);
update_tri_layer(_LOWER, _UPPER, _UTIL);
if (state->solo && is_tapped(state->pressed_time, record->event.time)) {
caps_word_off();
register_meta_if_needed();
register_code(state->tapcode);
unregister_code(state->tapcode);
}
state->solo = false;
}
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case MT_LGUI:
case MT_RGUI:
case MT_LCTL:
handle_metatap(keycode, record);
return false;
case MO(_LOWER):
case MO(_UPPER):
handle_lu(keycode, record);
return false;
default:
if (record->event.pressed) {
lower.solo = false;
upper.solo = false;
register_meta_if_needed();
}
}
return true;
}
/*
* Color Palette (HSV)
*
* Purple 217, 255, 255
* Green 44, 255, 255
* Orange 16, 255, 255
*
*/
// Callback for layer functions, for users.
layer_state_t layer_state_set_user(layer_state_t state) {
switch (get_highest_layer(state|default_layer_state)) {
case _TERRA_A:
case _TERRA_B:
rgblight_sethsv_noeeprom(129, 255, 255);
combo_disable();
break;
case _GAMING:
rgblight_sethsv_noeeprom(0, 255, 255);
combo_disable();
break;
case _UPPER:
rgblight_sethsv_noeeprom(16, 255, 255);
break;
case _LOWER:
rgblight_sethsv_noeeprom(44, 255, 255);
break;
case _UTIL:
rgblight_sethsv_noeeprom(217, 255, 255);
break;
case _MOUSE:
rgblight_sethsv_noeeprom(160, 255, 255);
break;
default:
rgblight_sethsv_noeeprom(30, 255, 255);
combo_enable();
break;
}
return state;
}
// Callback for default layer functions, for users. Called on keyboard initialization.
layer_state_t default_layer_state_set_user(layer_state_t state) {
switch (default_layer_state) {
case _GAMING:
rgblight_sethsv_noeeprom(0, 255, 255);
combo_disable();
break;
default:
rgblight_sethsv_noeeprom(30, 255, 255);
combo_enable();
break;
}
return state;
}
void keyboard_post_init_user(void) {
rgblight_enable_noeeprom(); // enables Rgb, without saving settings
rgblight_sethsv_noeeprom(30, 255, 255);
}
enum combos {
SD,
DF,
FG,
QW,
WE,
XC,
CV,
JK,
KL,
UI,
IO,
LOWER_JK,
LOWER_KL,
LOWER_UI,
LOWER_IO,
COMBO_LENGTH
};
// `COMBO_LEN` is reserved. Must be named exactry as such.
uint16_t COMBO_LEN = COMBO_LENGTH;
// Left hand
const uint16_t PROGMEM xc_combo[] = {KC_X, KC_C, COMBO_END};
const uint16_t PROGMEM cv_combo[] = {KC_C, KC_V, COMBO_END};
const uint16_t PROGMEM sd_combo[] = {KC_S, KC_D, COMBO_END};
const uint16_t PROGMEM df_combo[] = {KC_D, KC_F, COMBO_END};
const uint16_t PROGMEM fg_combo[] = {KC_F, KC_G, COMBO_END};
const uint16_t PROGMEM qw_combo[] = {KC_Q, KC_W, COMBO_END};
const uint16_t PROGMEM we_combo[] = {KC_W, KC_E, COMBO_END};
// Right hand
const uint16_t PROGMEM jk_combo[] = {KC_J, KC_K, COMBO_END};
const uint16_t PROGMEM kl_combo[] = {KC_K, KC_L, COMBO_END};
const uint16_t PROGMEM ui_combo[] = {KC_U, KC_I, COMBO_END};
const uint16_t PROGMEM io_combo[] = {KC_I, KC_O, COMBO_END};
const uint16_t PROGMEM lower_jk_combo[] = {KC_DOWN, KC_UP, COMBO_END};
const uint16_t PROGMEM lower_kl_combo[] = {KC_UP, KC_RIGHT, COMBO_END};
const uint16_t PROGMEM lower_ui_combo[] = {KC_PGDN, KC_PGUP, COMBO_END};
const uint16_t PROGMEM lower_io_combo[] = {KC_PGUP, C_RIGHT, COMBO_END};
combo_t key_combos[] = {
// Left hand
[SD] = COMBO(sd_combo, OS_LSFT),
[DF] = COMBO(df_combo, OS_LALT),
[FG] = COMBO(fg_combo, OS_LGUI),
[CV] = COMBO(cv_combo, MO(_MOUSE)),
// Right hand
[JK] = COMBO(jk_combo, KC_BSPC),
[KL] = COMBO(kl_combo, KC_ESC),
[LOWER_JK] = COMBO(lower_jk_combo, C_BSPC),
[LOWER_KL] = COMBO(lower_kl_combo, C_DEL),
[LOWER_UI] = COMBO(lower_ui_combo, A_ENT),
[LOWER_IO] = COMBO(lower_io_combo, C_ENT),
};