Added layer language switching

master
Mark 2022-02-09 11:14:05 -08:00
parent 25d07525ad
commit 863b517059
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 57 additions and 18 deletions

View File

@ -36,6 +36,12 @@ enum layer_indices {
LAYER_KEYBOARD_IDX, LAYER_KEYBOARD_IDX,
}; };
// Used by 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 { enum led_indices {
// We have seperate indexes for LEDs because // We have seperate indexes for LEDs because
// some layers may not need an led map. // some layers may not need an led map.
@ -79,6 +85,7 @@ void keyboard_post_init_user(void) {
rgb_matrix_enable(); rgb_matrix_enable();
} }
int current_lang = 0;
void set_layer_color(int layer) { void set_layer_color(int layer) {
@ -148,7 +155,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case ST_MACRO_1: case ST_MACRO_1:
if (record->event.pressed) { 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)); SEND_STRING(SS_LGUI(SS_TAP(X_P)) SS_DELAY(100) SS_TAP(X_Y) SS_DELAY(100) SS_TAP(X_ENTER));
} }
break; break;
@ -206,6 +212,28 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true; return true;
} }
void set_lang(int lang) {
if (current_lang != lang) {
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;
}
}
}
uint32_t layer_state_set_user(uint32_t state) { uint32_t layer_state_set_user(uint32_t state) {
uint8_t layer = biton32(state); uint8_t layer = biton32(state);
@ -214,43 +242,54 @@ uint32_t layer_state_set_user(uint32_t state) {
ergodox_right_led_1_off(); ergodox_right_led_1_off();
ergodox_right_led_2_off(); ergodox_right_led_2_off();
ergodox_right_led_3_off(); ergodox_right_led_3_off();
switch (layer) { switch (layer) {
case 1: case LAYER_MAIN_IDX:
ergodox_right_led_1_on(); set_lang(LANG_EN);
break; break;
case 2: case LAYER_RUSSIAN_IDX:
ergodox_right_led_2_on(); set_lang(LANG_RU);
break; break;
case 3: case LAYER_COLEMAK_IDX:
ergodox_right_led_3_on(); set_lang(LANG_EN);
break; break;
case 4: case LAYER_NUMPAD_IDX:
ergodox_right_led_1_on(); set_lang(LANG_EN);
ergodox_right_led_2_on();
break; break;
case 5: case LAYER_SYMBOLS_IDX:
ergodox_right_led_1_on(); set_lang(LANG_EN);
ergodox_right_led_3_on();
break; break;
case 6: case LAYER_ARROWS_IDX:
ergodox_right_led_2_on(); set_lang(LANG_EN);
ergodox_right_led_3_on();
break; break;
case 8: case LAYER_FKEYS_IDX:
set_lang(LANG_EN);
break;
case LAYER_NAVIGATE_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_1_on();
ergodox_right_led_2_on(); ergodox_right_led_2_on();
ergodox_right_led_3_on(); ergodox_right_led_3_on();
break; break;
default: default:
break; break;
} }
return state; return state;
}; };