263 lines
5.5 KiB
C
263 lines
5.5 KiB
C
#include "keymap.h"
|
|
|
|
|
|
// Define custom keys
|
|
// (Must be done BEFORE keymaps)
|
|
enum custom_keycodes {
|
|
M_SHUTDOWN = BETA_SAFE_RANGE,
|
|
M_RESETWM,
|
|
RU_LAYER,
|
|
EN_LAYER,
|
|
M_RU_CTRL,
|
|
M_RU_ALT
|
|
};
|
|
|
|
enum tap_dance_codes {
|
|
TD_WMLAYOUT,
|
|
};
|
|
|
|
|
|
// Assemble key and LED maps
|
|
enum layer_indices {
|
|
LAYER_MAIN_IDX = 0,
|
|
LAYER_RUSSIAN_IDX,
|
|
LAYER_COLEMAK_IDX,
|
|
LAYER_NUMPAD_IDX,
|
|
LAYER_SYMBOLS_IDX,
|
|
LAYER_ARROWS_IDX,
|
|
LAYER_FKEYS_IDX,
|
|
LAYER_DESKTOP_IDX,
|
|
LAYER_KEYBOARD_IDX,
|
|
|
|
};
|
|
// Used to set system keymap
|
|
enum key_encodings {
|
|
LANG_NULL, // For layers that don't care about input lang
|
|
LANG_EN,
|
|
LANG_RU
|
|
};
|
|
enum led_indices {
|
|
// We have seperate indexes for LEDs because
|
|
// some layers may not need an led map.
|
|
// This saves memory by avoiding extra empty led maps.
|
|
LAYER_COLEMAK_LEDS_IDX = 0,
|
|
LAYER_RUSSIAN_LEDS_IDX,
|
|
LAYER_NUMPAD_LEDS_IDX,
|
|
LAYER_SYMBOLS_LEDS_IDX,
|
|
LAYER_ARROWS_LEDS_IDX,
|
|
LAYER_FKEYS_LEDS_IDX,
|
|
LAYER_DESKTOP_LEDS_IDX
|
|
};
|
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|
[LAYER_MAIN_IDX] = LAYER_MAIN,
|
|
[LAYER_RUSSIAN_IDX] = LAYER_RUSSIAN,
|
|
[LAYER_COLEMAK_IDX] = LAYER_COLEMAK,
|
|
[LAYER_NUMPAD_IDX] = LAYER_NUMPAD,
|
|
[LAYER_SYMBOLS_IDX] = LAYER_SYMBOLS,
|
|
[LAYER_ARROWS_IDX] = LAYER_ARROWS,
|
|
[LAYER_FKEYS_IDX] = LAYER_FKEYS,
|
|
[LAYER_DESKTOP_IDX] = LAYER_DESKTOP,
|
|
[LAYER_KEYBOARD_IDX] = LAYER_KEYBOARD
|
|
};
|
|
const uint8_t PROGMEM ledmap[][DRIVER_LED_TOTAL][3] = {
|
|
[LAYER_COLEMAK_LEDS_IDX] = LAYER_COLEMAK_LEDS,
|
|
[LAYER_RUSSIAN_LEDS_IDX] = LAYER_RUSSIAN_LEDS,
|
|
[LAYER_NUMPAD_LEDS_IDX] = LAYER_NUMPAD_LEDS,
|
|
[LAYER_SYMBOLS_LEDS_IDX] = LAYER_SYMBOLS_LEDS,
|
|
[LAYER_ARROWS_LEDS_IDX] = LAYER_ARROWS_LEDS,
|
|
[LAYER_FKEYS_LEDS_IDX] = LAYER_FKEYS_LEDS,
|
|
[LAYER_DESKTOP_LEDS_IDX] = LAYER_DESKTOP_LEDS
|
|
};
|
|
|
|
int current_lang = LANG_EN;
|
|
|
|
void keyboard_post_init_user(void) {}
|
|
|
|
|
|
|
|
void set_layer_color(int layer) {
|
|
for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
|
|
HSV hsv = {
|
|
.h = pgm_read_byte(&ledmap[layer][i][0]),
|
|
.s = pgm_read_byte(&ledmap[layer][i][1]),
|
|
.v = pgm_read_byte(&ledmap[layer][i][2]),
|
|
};
|
|
if (!hsv.h && !hsv.s && !hsv.v) {
|
|
rgb_matrix_set_color( i, 0, 0, 0 );
|
|
} else {
|
|
RGB rgb = hsv_to_rgb( hsv );
|
|
float f = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
|
|
rgb_matrix_set_color( i, f * rgb.r, f * rgb.g, f * rgb.b );
|
|
}
|
|
}
|
|
}
|
|
|
|
void rgb_matrix_indicators_user(void) {
|
|
if (keyboard_config.disable_layer_led) {
|
|
return;
|
|
}
|
|
|
|
switch (biton32(layer_state)) {
|
|
case LAYER_COLEMAK_IDX:
|
|
set_layer_color(LAYER_COLEMAK_LEDS_IDX);
|
|
break;
|
|
case LAYER_RUSSIAN_IDX:
|
|
set_layer_color(LAYER_RUSSIAN_LEDS_IDX);
|
|
break;
|
|
case LAYER_NUMPAD_IDX:
|
|
set_layer_color(LAYER_NUMPAD_LEDS_IDX);
|
|
break;
|
|
case LAYER_SYMBOLS_IDX:
|
|
set_layer_color(LAYER_SYMBOLS_LEDS_IDX);
|
|
break;
|
|
case LAYER_ARROWS_IDX:
|
|
set_layer_color(LAYER_ARROWS_LEDS_IDX);
|
|
break;
|
|
case LAYER_FKEYS_IDX:
|
|
set_layer_color(LAYER_FKEYS_LEDS_IDX);
|
|
break;
|
|
case LAYER_DESKTOP_IDX:
|
|
set_layer_color(LAYER_DESKTOP_LEDS_IDX);
|
|
break;
|
|
default:
|
|
if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
|
|
rgb_matrix_set_color_all(0, 0, 0);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void set_lang(int lang) { set_lang_long(lang, false); }
|
|
void set_lang_long(int lang, bool force) {
|
|
if (current_lang != lang || force) {
|
|
switch (lang) {
|
|
case LANG_EN:
|
|
SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_0)))));
|
|
current_lang = lang;
|
|
break;
|
|
|
|
case LANG_RU:
|
|
SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_9)))));
|
|
current_lang = lang;
|
|
break;
|
|
|
|
case LANG_NULL:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|
switch (keycode) {
|
|
case M_RESETWM:
|
|
if (record->event.pressed) {
|
|
SEND_STRING(SS_LCTL(SS_LGUI(SS_LSFT(SS_TAP(X_R)))));
|
|
}
|
|
break;
|
|
|
|
case M_SHUTDOWN:
|
|
if (record->event.pressed) {
|
|
SEND_STRING(SS_LGUI(SS_TAP(X_P)) SS_DELAY(100) SS_TAP(X_Y) SS_DELAY(100) SS_TAP(X_ENTER));
|
|
}
|
|
break;
|
|
|
|
case RU_LAYER:
|
|
if (record->event.pressed) {
|
|
set_lang(LANG_RU);
|
|
layer_move(LAYER_RUSSIAN_IDX);
|
|
}
|
|
break;
|
|
|
|
case EN_LAYER:
|
|
if (record->event.pressed) {
|
|
set_lang(LANG_EN);
|
|
layer_move(LAYER_MAIN_IDX);
|
|
}
|
|
break;
|
|
|
|
case M_RU_CTRL:
|
|
if (record->event.pressed) {
|
|
if (current_lang == LANG_RU) {
|
|
set_lang_long(LANG_EN, true);
|
|
layer_move(LAYER_MAIN_IDX);
|
|
current_lang = LANG_RU;
|
|
}
|
|
register_code16(KC_LCTRL);
|
|
} else {
|
|
unregister_code16(KC_LCTRL);
|
|
if (current_lang == LANG_RU) {
|
|
layer_move(LAYER_RUSSIAN_IDX);
|
|
set_lang_long(LANG_RU, true);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
uint32_t layer_state_set_user(uint32_t state) {
|
|
|
|
uint8_t layer = biton32(state);
|
|
|
|
ergodox_board_led_off();
|
|
ergodox_right_led_1_off();
|
|
ergodox_right_led_2_off();
|
|
ergodox_right_led_3_off();
|
|
|
|
switch (layer) {
|
|
case LAYER_MAIN_IDX:
|
|
set_lang(LANG_EN);
|
|
break;
|
|
|
|
case LAYER_RUSSIAN_IDX:
|
|
set_lang(LANG_RU);
|
|
ergodox_right_led_2_on();
|
|
break;
|
|
|
|
case LAYER_COLEMAK_IDX:
|
|
set_lang(LANG_EN);
|
|
ergodox_right_led_2_on();
|
|
break;
|
|
|
|
case LAYER_NUMPAD_IDX:
|
|
set_lang(LANG_EN);
|
|
ergodox_right_led_1_on();
|
|
break;
|
|
|
|
case LAYER_SYMBOLS_IDX:
|
|
set_lang(LANG_EN);
|
|
break;
|
|
|
|
case LAYER_ARROWS_IDX:
|
|
set_lang(LANG_EN);
|
|
break;
|
|
|
|
case LAYER_FKEYS_IDX:
|
|
set_lang(LANG_EN);
|
|
break;
|
|
|
|
case LAYER_DESKTOP_IDX:
|
|
set_lang(LANG_EN);
|
|
break;
|
|
|
|
case LAYER_KEYBOARD_IDX:
|
|
set_lang(LANG_NULL);
|
|
ergodox_right_led_1_on();
|
|
ergodox_right_led_2_on();
|
|
ergodox_right_led_3_on();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
|
|
qk_tap_dance_action_t tap_dance_actions[] = {
|
|
[TD_WMLAYOUT] = ACTION_TAP_DANCE_FN_ADVANCED(td_wmlayout_dance, td_wmlayout_finished, td_wmlayout_reset),
|
|
};
|