mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-16 21:01:31 +00:00
Standardize the Unicode EEPROM code
This commit is contained in:
parent
cd544e10a9
commit
18fcde13ad
@ -19,42 +19,28 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
static uint8_t input_mode;
|
unicode_config_t unicode_config;
|
||||||
uint8_t mods;
|
static uint8_t saved_mods;
|
||||||
|
|
||||||
void set_unicode_input_mode(uint8_t os_target) {
|
void set_unicode_input_mode(uint8_t os_target) {
|
||||||
input_mode = os_target;
|
unicode_config.input_mode = os_target;
|
||||||
eeprom_update_byte(EECONFIG_UNICODEMODE, os_target);
|
eeprom_update_byte(EECONFIG_UNICODEMODE, os_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_unicode_input_mode(void) {
|
uint8_t get_unicode_input_mode(void) {
|
||||||
return input_mode;
|
return unicode_config.input_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unicode_input_mode_init(void) {
|
void unicode_input_mode_init(void) {
|
||||||
static bool first_flag = false;
|
unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
|
||||||
if (!first_flag) {
|
|
||||||
input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE);
|
|
||||||
first_flag = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
void unicode_input_start (void) {
|
void unicode_input_start (void) {
|
||||||
// save current mods
|
saved_mods = get_mods(); // Save current mods
|
||||||
mods = keyboard_report->mods;
|
clear_mods(); // Unregister mods to start from a clean state
|
||||||
|
|
||||||
// unregister all mods to start from clean state
|
switch(unicode_config.input_mode) {
|
||||||
if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
|
|
||||||
if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
|
|
||||||
if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
|
|
||||||
if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
|
|
||||||
if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
|
|
||||||
if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
|
|
||||||
if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
|
|
||||||
if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
|
|
||||||
|
|
||||||
switch(input_mode) {
|
|
||||||
case UC_OSX:
|
case UC_OSX:
|
||||||
register_code(KC_LALT);
|
register_code(KC_LALT);
|
||||||
break;
|
break;
|
||||||
@ -85,7 +71,7 @@ void unicode_input_start (void) {
|
|||||||
|
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
void unicode_input_finish (void) {
|
void unicode_input_finish (void) {
|
||||||
switch(input_mode) {
|
switch(unicode_config.input_mode) {
|
||||||
case UC_OSX:
|
case UC_OSX:
|
||||||
case UC_WIN:
|
case UC_WIN:
|
||||||
unregister_code(KC_LALT);
|
unregister_code(KC_LALT);
|
||||||
@ -99,15 +85,7 @@ void unicode_input_finish (void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reregister previously set mods
|
set_mods(saved_mods); // Reregister previously set mods
|
||||||
if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
|
|
||||||
if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
|
|
||||||
if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
|
|
||||||
if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
|
|
||||||
if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
|
|
||||||
if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
|
|
||||||
if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
|
|
||||||
if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
|
@ -23,8 +23,13 @@
|
|||||||
#define UNICODE_TYPE_DELAY 10
|
#define UNICODE_TYPE_DELAY 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__attribute__ ((unused))
|
typedef union {
|
||||||
static uint8_t input_mode;
|
uint32_t raw;
|
||||||
|
struct {
|
||||||
|
uint8_t input_mode :8;
|
||||||
|
};
|
||||||
|
} unicode_config_t;
|
||||||
|
|
||||||
|
|
||||||
void set_unicode_input_mode(uint8_t os_target);
|
void set_unicode_input_mode(uint8_t os_target);
|
||||||
uint8_t get_unicode_input_mode(void);
|
uint8_t get_unicode_input_mode(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user