split up unicode systems into different files
This commit is contained in:
		@@ -168,12 +168,12 @@ endif
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ifeq ($(strip $(UCIS_ENABLE)), yes)
 | 
					ifeq ($(strip $(UCIS_ENABLE)), yes)
 | 
				
			||||||
	OPT_DEFS += -DUCIS_ENABLE
 | 
						OPT_DEFS += -DUCIS_ENABLE
 | 
				
			||||||
	UNICODE_ENABLE = yes
 | 
						SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
 | 
					ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
 | 
				
			||||||
	OPT_DEFS += -DUNICODEMAP_ENABLE
 | 
						OPT_DEFS += -DUNICODEMAP_ENABLE
 | 
				
			||||||
	UNICODE_ENABLE = yes
 | 
						SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifeq ($(strip $(UNICODE_ENABLE)), yes)
 | 
					ifeq ($(strip $(UNICODE_ENABLE)), yes)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										133
									
								
								quantum/process_keycode/process_ucis.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								quantum/process_keycode/process_ucis.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,133 @@
 | 
				
			|||||||
 | 
					#include "process_ucis.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					qk_ucis_state_t qk_ucis_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										34
									
								
								quantum/process_keycode/process_ucis.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								quantum/process_keycode/process_ucis.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					#ifndef PROCESS_UCIS_H
 | 
				
			||||||
 | 
					#define PROCESS_UCIS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "quantum.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef UCIS_MAX_SYMBOL_LENGTH
 | 
				
			||||||
 | 
					#define UCIS_MAX_SYMBOL_LENGTH 32
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					  char *symbol;
 | 
				
			||||||
 | 
					  char *code;
 | 
				
			||||||
 | 
					} qk_ucis_symbol_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					  uint8_t count;
 | 
				
			||||||
 | 
					  uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
 | 
				
			||||||
 | 
					  bool in_progress:1;
 | 
				
			||||||
 | 
					} qk_ucis_state_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern qk_ucis_state_t 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
 | 
				
			||||||
@@ -4,18 +4,6 @@
 | 
				
			|||||||
static uint8_t input_mode;
 | 
					static uint8_t input_mode;
 | 
				
			||||||
uint8_t mods;
 | 
					uint8_t mods;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__attribute__((weak))
 | 
					 | 
				
			||||||
uint16_t hex_to_keycode(uint8_t hex)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  if (hex == 0x0) {
 | 
					 | 
				
			||||||
    return KC_0;
 | 
					 | 
				
			||||||
  } else if (hex < 0xA) {
 | 
					 | 
				
			||||||
    return KC_1 + (hex - 0x1);
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    return KC_A + (hex - 0xA);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void set_unicode_input_mode(uint8_t os_target)
 | 
					void set_unicode_input_mode(uint8_t os_target)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  input_mode = os_target;
 | 
					  input_mode = os_target;
 | 
				
			||||||
@@ -108,191 +96,3 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) {
 | 
				
			|||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef UNICODEMAP_ENABLE
 | 
					 | 
				
			||||||
__attribute__((weak))
 | 
					 | 
				
			||||||
const uint32_t PROGMEM unicode_map[] = {
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void register_hex32(uint32_t hex) {
 | 
					 | 
				
			||||||
  uint8_t onzerostart = 1;
 | 
					 | 
				
			||||||
  for(int i = 7; i >= 0; i--) {
 | 
					 | 
				
			||||||
    if (i <= 3) {
 | 
					 | 
				
			||||||
      onzerostart = 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    uint8_t digit = ((hex >> (i*4)) & 0xF);
 | 
					 | 
				
			||||||
    if (digit == 0) {
 | 
					 | 
				
			||||||
      if (onzerostart == 0) {
 | 
					 | 
				
			||||||
        register_code(hex_to_keycode(digit));
 | 
					 | 
				
			||||||
        unregister_code(hex_to_keycode(digit));
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      register_code(hex_to_keycode(digit));
 | 
					 | 
				
			||||||
      unregister_code(hex_to_keycode(digit));
 | 
					 | 
				
			||||||
      onzerostart = 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
__attribute__((weak))
 | 
					 | 
				
			||||||
void unicode_map_input_error() {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
 | 
					 | 
				
			||||||
  if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
 | 
					 | 
				
			||||||
    const uint32_t* map = unicode_map;
 | 
					 | 
				
			||||||
    uint16_t index = keycode - QK_UNICODE_MAP;
 | 
					 | 
				
			||||||
    uint32_t code = pgm_read_dword_far(&map[index]);
 | 
					 | 
				
			||||||
    if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
 | 
					 | 
				
			||||||
      // Convert to UTF-16 surrogate pair
 | 
					 | 
				
			||||||
      code -= 0x10000;
 | 
					 | 
				
			||||||
      uint32_t lo = code & 0x3ff;
 | 
					 | 
				
			||||||
      uint32_t hi = (code & 0xffc00) >> 10;
 | 
					 | 
				
			||||||
      unicode_input_start();
 | 
					 | 
				
			||||||
      register_hex32(hi + 0xd800);
 | 
					 | 
				
			||||||
      register_hex32(lo + 0xdc00);
 | 
					 | 
				
			||||||
      unicode_input_finish();
 | 
					 | 
				
			||||||
    } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
 | 
					 | 
				
			||||||
      // when character is out of range supported by the OS
 | 
					 | 
				
			||||||
      unicode_map_input_error();
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      unicode_input_start();
 | 
					 | 
				
			||||||
      register_hex32(code);
 | 
					 | 
				
			||||||
      unicode_input_finish();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  return true;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef UCIS_ENABLE
 | 
					 | 
				
			||||||
qk_ucis_state_t qk_ucis_state;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,42 +21,6 @@ void register_hex(uint16_t hex);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool process_unicode(uint16_t keycode, keyrecord_t *record);
 | 
					bool process_unicode(uint16_t keycode, keyrecord_t *record);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef UNICODEMAP_ENABLE
 | 
					 | 
				
			||||||
void unicode_map_input_error(void);
 | 
					 | 
				
			||||||
bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
  uint8_t count;
 | 
					 | 
				
			||||||
  uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
 | 
					 | 
				
			||||||
  bool in_progress:1;
 | 
					 | 
				
			||||||
} qk_ucis_state_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern qk_ucis_state_t 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_BSPC	UC(0x0008)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define UC_SPC	UC(0x0020)
 | 
					#define UC_SPC	UC(0x0020)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										54
									
								
								quantum/process_keycode/process_unicodemap.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								quantum/process_keycode/process_unicodemap.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
				
			|||||||
 | 
					#include "process_unicode_map.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__attribute__((weak))
 | 
				
			||||||
 | 
					const uint32_t PROGMEM unicode_map[] = {
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void register_hex32(uint32_t hex) {
 | 
				
			||||||
 | 
					  uint8_t onzerostart = 1;
 | 
				
			||||||
 | 
					  for(int i = 7; i >= 0; i--) {
 | 
				
			||||||
 | 
					    if (i <= 3) {
 | 
				
			||||||
 | 
					      onzerostart = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    uint8_t digit = ((hex >> (i*4)) & 0xF);
 | 
				
			||||||
 | 
					    if (digit == 0) {
 | 
				
			||||||
 | 
					      if (onzerostart == 0) {
 | 
				
			||||||
 | 
					        register_code(hex_to_keycode(digit));
 | 
				
			||||||
 | 
					        unregister_code(hex_to_keycode(digit));
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      register_code(hex_to_keycode(digit));
 | 
				
			||||||
 | 
					      unregister_code(hex_to_keycode(digit));
 | 
				
			||||||
 | 
					      onzerostart = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__attribute__((weak))
 | 
				
			||||||
 | 
					void unicode_map_input_error() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
 | 
				
			||||||
 | 
					  if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
 | 
				
			||||||
 | 
					    const uint32_t* map = unicode_map;
 | 
				
			||||||
 | 
					    uint16_t index = keycode - QK_UNICODE_MAP;
 | 
				
			||||||
 | 
					    uint32_t code = pgm_read_dword_far(&map[index]);
 | 
				
			||||||
 | 
					    if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
 | 
				
			||||||
 | 
					      // Convert to UTF-16 surrogate pair
 | 
				
			||||||
 | 
					      code -= 0x10000;
 | 
				
			||||||
 | 
					      uint32_t lo = code & 0x3ff;
 | 
				
			||||||
 | 
					      uint32_t hi = (code & 0xffc00) >> 10;
 | 
				
			||||||
 | 
					      unicode_input_start();
 | 
				
			||||||
 | 
					      register_hex32(hi + 0xd800);
 | 
				
			||||||
 | 
					      register_hex32(lo + 0xdc00);
 | 
				
			||||||
 | 
					      unicode_input_finish();
 | 
				
			||||||
 | 
					    } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
 | 
				
			||||||
 | 
					      // when character is out of range supported by the OS
 | 
				
			||||||
 | 
					      unicode_map_input_error();
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      unicode_input_start();
 | 
				
			||||||
 | 
					      register_hex32(code);
 | 
				
			||||||
 | 
					      unicode_input_finish();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								quantum/process_keycode/process_unicodemap.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								quantum/process_keycode/process_unicodemap.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					#ifndef PROCESS_UNICODEMAP_H
 | 
				
			||||||
 | 
					#define PROCESS_UNICODEMAP_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "quantum.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void unicode_map_input_error(void);
 | 
				
			||||||
 | 
					bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
@@ -972,6 +972,19 @@ void send_nibble(uint8_t number) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__attribute__((weak))
 | 
				
			||||||
 | 
					uint16_t hex_to_keycode(uint8_t hex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (hex == 0x0) {
 | 
				
			||||||
 | 
					    return KC_0;
 | 
				
			||||||
 | 
					  } else if (hex < 0xA) {
 | 
				
			||||||
 | 
					    return KC_1 + (hex - 0x1);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return KC_A + (hex - 0xA);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void api_send_unicode(uint32_t unicode) {
 | 
					void api_send_unicode(uint32_t unicode) {
 | 
				
			||||||
#ifdef API_ENABLE
 | 
					#ifdef API_ENABLE
 | 
				
			||||||
    uint8_t chunk[4];
 | 
					    uint8_t chunk[4];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,6 +56,14 @@ extern uint32_t default_layer_state;
 | 
				
			|||||||
	#include "process_unicode.h"
 | 
						#include "process_unicode.h"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef UCIS_ENABLE
 | 
				
			||||||
 | 
						#include "process_ucis.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef UNICODEMAP_ENABLE
 | 
				
			||||||
 | 
						#include "process_unicodemap.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "process_tap_dance.h"
 | 
					#include "process_tap_dance.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef PRINTING_ENABLE
 | 
					#ifdef PRINTING_ENABLE
 | 
				
			||||||
@@ -117,7 +125,7 @@ void send_dword(uint32_t number);
 | 
				
			|||||||
void send_word(uint16_t number);
 | 
					void send_word(uint16_t number);
 | 
				
			||||||
void send_byte(uint8_t number);
 | 
					void send_byte(uint8_t number);
 | 
				
			||||||
void send_nibble(uint8_t number);
 | 
					void send_nibble(uint8_t number);
 | 
				
			||||||
 | 
					uint16_t hex_to_keycode(uint8_t hex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void led_set_user(uint8_t usb_led);
 | 
					void led_set_user(uint8_t usb_led);
 | 
				
			||||||
void led_set_kb(uint8_t usb_led);
 | 
					void led_set_kb(uint8_t usb_led);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user