Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
This commit is contained in:
commit
3cb1dce622
5
Makefile
5
Makefile
|
@ -198,6 +198,11 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes)
|
|||
SRC += $(QUANTUM_DIR)/audio/luts.c
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(UCIS_ENABLE)), yes)
|
||||
OPT_DEFS += -DUCIS_ENABLE
|
||||
UNICODE_ENABLE = yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(UNICODE_ENABLE)), yes)
|
||||
OPT_DEFS += -DUNICODE_ENABLE
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
|
||||
|
|
|
@ -18,9 +18,7 @@ void set_unicode_input_mode(uint8_t os_target)
|
|||
input_mode = os_target;
|
||||
}
|
||||
|
||||
bool process_unicode(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode > QK_UNICODE && record->event.pressed) {
|
||||
uint16_t unicode = keycode & 0x7FFF;
|
||||
void unicode_input_start (void) {
|
||||
switch(input_mode) {
|
||||
case UC_OSX:
|
||||
register_code(KC_LALT);
|
||||
|
@ -30,6 +28,8 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) {
|
|||
register_code(KC_LSFT);
|
||||
register_code(KC_U);
|
||||
unregister_code(KC_U);
|
||||
unregister_code(KC_LSFT);
|
||||
unregister_code(KC_LCTL);
|
||||
break;
|
||||
case UC_WIN:
|
||||
register_code(KC_LALT);
|
||||
|
@ -37,21 +37,168 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) {
|
|||
unregister_code(KC_PPLS);
|
||||
break;
|
||||
}
|
||||
for(int i = 3; i >= 0; i--) {
|
||||
uint8_t digit = ((unicode >> (i*4)) & 0xF);
|
||||
register_code(hex_to_keycode(digit));
|
||||
unregister_code(hex_to_keycode(digit));
|
||||
}
|
||||
wait_ms(UNICODE_TYPE_DELAY);
|
||||
}
|
||||
|
||||
void unicode_input_finish (void) {
|
||||
switch(input_mode) {
|
||||
case UC_OSX:
|
||||
case UC_WIN:
|
||||
unregister_code(KC_LALT);
|
||||
break;
|
||||
case UC_LNX:
|
||||
unregister_code(KC_LCTL);
|
||||
unregister_code(KC_LSFT);
|
||||
register_code(KC_SPC);
|
||||
unregister_code(KC_SPC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void register_hex(uint16_t hex) {
|
||||
for(int i = 3; i >= 0; i--) {
|
||||
uint8_t digit = ((hex >> (i*4)) & 0xF);
|
||||
register_code(hex_to_keycode(digit));
|
||||
unregister_code(hex_to_keycode(digit));
|
||||
}
|
||||
}
|
||||
|
||||
bool process_unicode(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode > QK_UNICODE && record->event.pressed) {
|
||||
uint16_t unicode = keycode & 0x7FFF;
|
||||
unicode_input_start();
|
||||
register_hex(unicode);
|
||||
unicode_input_finish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef UCIS_ENABLE
|
||||
void qk_ucis_start(void) {
|
||||
qk_ucis_state.count = 0;
|
||||
qk_ucis_state.in_progress = true;
|
||||
|
||||
qk_ucis_start_user();
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
void qk_ucis_start_user(void) {
|
||||
unicode_input_start();
|
||||
register_hex(0x2328);
|
||||
unicode_input_finish();
|
||||
}
|
||||
|
||||
static bool is_uni_seq(char *seq) {
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; seq[i]; i++) {
|
||||
uint16_t code;
|
||||
if (('1' <= seq[i]) && (seq[i] <= '0'))
|
||||
code = seq[i] - '1' + KC_1;
|
||||
else
|
||||
code = seq[i] - 'a' + KC_A;
|
||||
|
||||
if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code)
|
||||
return false;
|
||||
}
|
||||
|
||||
return (qk_ucis_state.codes[i] == KC_ENT ||
|
||||
qk_ucis_state.codes[i] == KC_SPC);
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
void qk_ucis_symbol_fallback (void) {
|
||||
for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
|
||||
uint8_t code = qk_ucis_state.codes[i];
|
||||
register_code(code);
|
||||
unregister_code(code);
|
||||
wait_ms(UNICODE_TYPE_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void register_ucis(const char *hex) {
|
||||
for(int i = 0; hex[i]; i++) {
|
||||
uint8_t kc = 0;
|
||||
char c = hex[i];
|
||||
|
||||
switch (c) {
|
||||
case '0':
|
||||
kc = KC_0;
|
||||
break;
|
||||
case '1' ... '9':
|
||||
kc = c - '1' + KC_1;
|
||||
break;
|
||||
case 'a' ... 'f':
|
||||
kc = c - 'a' + KC_A;
|
||||
break;
|
||||
case 'A' ... 'F':
|
||||
kc = c - 'A' + KC_A;
|
||||
break;
|
||||
}
|
||||
|
||||
if (kc) {
|
||||
register_code (kc);
|
||||
unregister_code (kc);
|
||||
wait_ms (UNICODE_TYPE_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool process_ucis (uint16_t keycode, keyrecord_t *record) {
|
||||
uint8_t i;
|
||||
|
||||
if (!qk_ucis_state.in_progress)
|
||||
return true;
|
||||
|
||||
if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH &&
|
||||
!(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!record->event.pressed)
|
||||
return true;
|
||||
|
||||
qk_ucis_state.codes[qk_ucis_state.count] = keycode;
|
||||
qk_ucis_state.count++;
|
||||
|
||||
if (keycode == KC_BSPC) {
|
||||
if (qk_ucis_state.count >= 2) {
|
||||
qk_ucis_state.count -= 2;
|
||||
return true;
|
||||
} else {
|
||||
qk_ucis_state.count--;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
|
||||
bool symbol_found = false;
|
||||
|
||||
for (i = qk_ucis_state.count; i > 0; i--) {
|
||||
register_code (KC_BSPC);
|
||||
unregister_code (KC_BSPC);
|
||||
wait_ms(UNICODE_TYPE_DELAY);
|
||||
}
|
||||
|
||||
if (keycode == KC_ESC) {
|
||||
qk_ucis_state.in_progress = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
unicode_input_start();
|
||||
for (i = 0; ucis_symbol_table[i].symbol; i++) {
|
||||
if (is_uni_seq (ucis_symbol_table[i].symbol)) {
|
||||
symbol_found = true;
|
||||
register_ucis(ucis_symbol_table[i].code + 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!symbol_found) {
|
||||
qk_ucis_symbol_fallback();
|
||||
}
|
||||
unicode_input_finish();
|
||||
|
||||
qk_ucis_state.in_progress = false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,10 +8,46 @@
|
|||
#define UC_WIN 2
|
||||
#define UC_BSD 3
|
||||
|
||||
#ifndef UNICODE_TYPE_DELAY
|
||||
#define UNICODE_TYPE_DELAY 10
|
||||
#endif
|
||||
|
||||
void set_unicode_input_mode(uint8_t os_target);
|
||||
void unicode_input_start(void);
|
||||
void unicode_input_finish(void);
|
||||
void register_hex(uint16_t hex);
|
||||
|
||||
bool process_unicode(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
#ifdef UCIS_ENABLE
|
||||
#ifndef UCIS_MAX_SYMBOL_LENGTH
|
||||
#define UCIS_MAX_SYMBOL_LENGTH 32
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char *symbol;
|
||||
char *code;
|
||||
} qk_ucis_symbol_t;
|
||||
|
||||
struct {
|
||||
uint8_t count;
|
||||
uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
|
||||
bool in_progress:1;
|
||||
} qk_ucis_state;
|
||||
|
||||
#define UCIS_TABLE(...) {__VA_ARGS__, {NULL, NULL}}
|
||||
#define UCIS_SYM(name, code) {name, #code}
|
||||
|
||||
extern const qk_ucis_symbol_t ucis_symbol_table[];
|
||||
|
||||
void qk_ucis_start(void);
|
||||
void qk_ucis_start_user(void);
|
||||
void qk_ucis_symbol_fallback (void);
|
||||
void register_ucis(const char *hex);
|
||||
bool process_ucis (uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
#endif
|
||||
|
||||
#define UC_BSPC UC(0x0008)
|
||||
|
||||
#define UC_SPC UC(0x0020)
|
||||
|
|
|
@ -86,6 +86,9 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
#endif
|
||||
#ifdef UNICODE_ENABLE
|
||||
process_unicode(keycode, record) &&
|
||||
#endif
|
||||
#ifdef UCIS_ENABLE
|
||||
process_ucis(keycode, record) &&
|
||||
#endif
|
||||
true)) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue