2022-02-06 13:19:32 -08:00
|
|
|
#include "keymap.h"
|
2022-02-06 12:00:50 -08:00
|
|
|
|
2022-06-25 18:37:15 -07:00
|
|
|
|
2022-02-06 13:43:24 -08:00
|
|
|
// Define custom keys
|
|
|
|
// (Must be done BEFORE keymaps)
|
2022-02-06 12:00:50 -08:00
|
|
|
enum custom_keycodes {
|
2022-06-17 12:06:53 -07:00
|
|
|
M_SHUTDOWN = BETA_SAFE_RANGE,
|
2022-02-09 13:26:46 -08:00
|
|
|
M_RESETWM,
|
2022-02-06 12:16:11 -08:00
|
|
|
RU_LAYER,
|
2022-02-07 20:41:31 -08:00
|
|
|
EN_LAYER,
|
2022-02-09 12:07:34 -08:00
|
|
|
M_RU_CTRL,
|
2022-06-17 12:06:53 -07:00
|
|
|
M_RU_ALT
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum tap_dance_codes {
|
2022-02-06 19:47:50 -08:00
|
|
|
TD_WMLAYOUT,
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|
|
|
|
|
2022-02-06 13:43:24 -08:00
|
|
|
|
|
|
|
// Assemble key and LED maps
|
2022-02-06 19:47:30 -08:00
|
|
|
enum layer_indices {
|
2022-02-07 20:36:12 -08:00
|
|
|
LAYER_MAIN_IDX = 0,
|
|
|
|
LAYER_RUSSIAN_IDX,
|
2022-02-06 19:47:30 -08:00
|
|
|
LAYER_COLEMAK_IDX,
|
|
|
|
LAYER_NUMPAD_IDX,
|
|
|
|
LAYER_SYMBOLS_IDX,
|
|
|
|
LAYER_ARROWS_IDX,
|
|
|
|
LAYER_FKEYS_IDX,
|
|
|
|
LAYER_DESKTOP_IDX,
|
|
|
|
LAYER_KEYBOARD_IDX,
|
2022-02-07 20:36:12 -08:00
|
|
|
|
|
|
|
};
|
2022-06-15 16:29:22 -07:00
|
|
|
// Used to set system keymap
|
2022-02-09 11:14:05 -08:00
|
|
|
enum key_encodings {
|
|
|
|
LANG_NULL, // For layers that don't care about input lang
|
|
|
|
LANG_EN,
|
|
|
|
LANG_RU
|
|
|
|
};
|
2022-02-07 20:36:12 -08:00
|
|
|
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
|
2022-02-06 19:47:30 -08:00
|
|
|
};
|
2022-02-06 12:00:50 -08:00
|
|
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
2022-02-06 19:47:30 -08:00
|
|
|
[LAYER_MAIN_IDX] = LAYER_MAIN,
|
2022-02-07 20:36:12 -08:00
|
|
|
[LAYER_RUSSIAN_IDX] = LAYER_RUSSIAN,
|
2022-02-06 19:47:30 -08:00
|
|
|
[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,
|
2022-02-07 20:36:12 -08:00
|
|
|
[LAYER_KEYBOARD_IDX] = LAYER_KEYBOARD
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|
2022-02-06 13:19:32 -08:00
|
|
|
const uint8_t PROGMEM ledmap[][DRIVER_LED_TOTAL][3] = {
|
2022-02-07 20:36:12 -08:00
|
|
|
[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
|
2022-02-06 13:19:32 -08:00
|
|
|
};
|
2022-02-06 12:00:50 -08:00
|
|
|
|
2022-02-09 12:07:34 -08:00
|
|
|
int current_lang = LANG_EN;
|
2022-02-06 12:00:50 -08:00
|
|
|
|
2022-07-07 17:12:13 -07:00
|
|
|
void keyboard_post_init_user(void) {}
|
2022-02-09 12:07:34 -08:00
|
|
|
|
2022-02-06 12:00:50 -08:00
|
|
|
|
|
|
|
|
|
|
|
void set_layer_color(int layer) {
|
2022-02-06 12:16:11 -08:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rgb_matrix_indicators_user(void) {
|
2022-02-06 12:16:11 -08:00
|
|
|
if (g_suspend_state || keyboard_config.disable_layer_led) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (biton32(layer_state)) {
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_COLEMAK_IDX:
|
|
|
|
set_layer_color(LAYER_COLEMAK_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_RUSSIAN_IDX:
|
|
|
|
set_layer_color(LAYER_RUSSIAN_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_NUMPAD_IDX:
|
|
|
|
set_layer_color(LAYER_NUMPAD_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_SYMBOLS_IDX:
|
|
|
|
set_layer_color(LAYER_SYMBOLS_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_ARROWS_IDX:
|
|
|
|
set_layer_color(LAYER_ARROWS_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_FKEYS_IDX:
|
|
|
|
set_layer_color(LAYER_FKEYS_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
2022-02-07 20:36:12 -08:00
|
|
|
case LAYER_DESKTOP_IDX:
|
|
|
|
set_layer_color(LAYER_DESKTOP_LEDS_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
|
|
|
|
rgb_matrix_set_color_all(0, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
2022-02-09 12:07:34 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-06 12:16:11 -08:00
|
|
|
|
2022-02-06 12:00:50 -08:00
|
|
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
2022-02-06 12:16:11 -08:00
|
|
|
switch (keycode) {
|
2022-02-09 13:26:46 -08:00
|
|
|
case M_RESETWM:
|
2022-02-06 12:16:11 -08:00
|
|
|
if (record->event.pressed) {
|
|
|
|
SEND_STRING(SS_LCTL(SS_LGUI(SS_LSFT(SS_TAP(X_R)))));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-02-09 13:26:46 -08:00
|
|
|
case M_SHUTDOWN:
|
2022-02-06 12:16:11 -08:00
|
|
|
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) {
|
2022-02-09 12:07:34 -08:00
|
|
|
set_lang(LANG_RU);
|
2022-02-07 20:36:12 -08:00
|
|
|
layer_move(LAYER_RUSSIAN_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EN_LAYER:
|
|
|
|
if (record->event.pressed) {
|
2022-02-09 12:07:34 -08:00
|
|
|
set_lang(LANG_EN);
|
2022-02-07 20:36:12 -08:00
|
|
|
layer_move(LAYER_MAIN_IDX);
|
2022-02-06 12:16:11 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-02-09 12:07:34 -08:00
|
|
|
case M_RU_CTRL:
|
2022-02-07 20:41:31 -08:00
|
|
|
if (record->event.pressed) {
|
2022-02-09 12:07:34 -08:00
|
|
|
if (current_lang == LANG_RU) {
|
|
|
|
set_lang_long(LANG_EN, true);
|
|
|
|
layer_move(LAYER_MAIN_IDX);
|
|
|
|
current_lang = LANG_RU;
|
|
|
|
}
|
|
|
|
register_code16(KC_LCTRL);
|
2022-02-07 20:41:31 -08:00
|
|
|
} else {
|
2022-02-09 12:07:34 -08:00
|
|
|
unregister_code16(KC_LCTRL);
|
|
|
|
if (current_lang == LANG_RU) {
|
|
|
|
layer_move(LAYER_RUSSIAN_IDX);
|
|
|
|
set_lang_long(LANG_RU, true);
|
|
|
|
}
|
2022-02-07 20:41:31 -08:00
|
|
|
}
|
|
|
|
break;
|
2022-02-06 12:16:11 -08:00
|
|
|
}
|
|
|
|
return true;
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
|
2022-02-06 12:00:50 -08:00
|
|
|
uint32_t layer_state_set_user(uint32_t state) {
|
|
|
|
|
2022-02-06 12:16:11 -08:00
|
|
|
uint8_t layer = biton32(state);
|
|
|
|
|
|
|
|
ergodox_board_led_off();
|
|
|
|
ergodox_right_led_1_off();
|
|
|
|
ergodox_right_led_2_off();
|
|
|
|
ergodox_right_led_3_off();
|
2022-02-09 11:14:05 -08:00
|
|
|
|
2022-02-06 12:16:11 -08:00
|
|
|
switch (layer) {
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_MAIN_IDX:
|
|
|
|
set_lang(LANG_EN);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_RUSSIAN_IDX:
|
|
|
|
set_lang(LANG_RU);
|
2022-06-17 12:14:22 -07:00
|
|
|
ergodox_right_led_2_on();
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_COLEMAK_IDX:
|
|
|
|
set_lang(LANG_EN);
|
2022-06-17 12:14:22 -07:00
|
|
|
ergodox_right_led_2_on();
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_NUMPAD_IDX:
|
|
|
|
set_lang(LANG_EN);
|
2022-06-17 12:14:22 -07:00
|
|
|
ergodox_right_led_1_on();
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_SYMBOLS_IDX:
|
|
|
|
set_lang(LANG_EN);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_ARROWS_IDX:
|
|
|
|
set_lang(LANG_EN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_FKEYS_IDX:
|
|
|
|
set_lang(LANG_EN);
|
2022-02-06 12:16:11 -08:00
|
|
|
break;
|
|
|
|
|
2022-02-09 11:14:05 -08:00
|
|
|
case LAYER_DESKTOP_IDX:
|
|
|
|
set_lang(LANG_EN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_KEYBOARD_IDX:
|
|
|
|
set_lang(LANG_NULL);
|
2022-02-06 12:16:11 -08:00
|
|
|
ergodox_right_led_1_on();
|
|
|
|
ergodox_right_led_2_on();
|
|
|
|
ergodox_right_led_3_on();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-02-09 11:14:05 -08:00
|
|
|
|
2022-02-06 12:16:11 -08:00
|
|
|
return state;
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
qk_tap_dance_action_t tap_dance_actions[] = {
|
2022-02-06 19:47:50 -08:00
|
|
|
[TD_WMLAYOUT] = ACTION_TAP_DANCE_FN_ADVANCED(td_wmlayout_dance, td_wmlayout_finished, td_wmlayout_reset),
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|