process_unicodemap.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "process_unicodemap.h"
  2. __attribute__((weak))
  3. const uint32_t PROGMEM unicode_map[] = {
  4. };
  5. void register_hex32(uint32_t hex) {
  6. uint8_t onzerostart = 1;
  7. for(int i = 7; i >= 0; i--) {
  8. if (i <= 3) {
  9. onzerostart = 0;
  10. }
  11. uint8_t digit = ((hex >> (i*4)) & 0xF);
  12. if (digit == 0) {
  13. if (onzerostart == 0) {
  14. register_code(hex_to_keycode(digit));
  15. unregister_code(hex_to_keycode(digit));
  16. }
  17. } else {
  18. register_code(hex_to_keycode(digit));
  19. unregister_code(hex_to_keycode(digit));
  20. onzerostart = 0;
  21. }
  22. }
  23. }
  24. __attribute__((weak))
  25. void unicode_map_input_error() {}
  26. bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
  27. if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
  28. const uint32_t* map = unicode_map;
  29. uint16_t index = keycode - QK_UNICODE_MAP;
  30. uint32_t code = pgm_read_dword_far(&map[index]);
  31. if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
  32. // Convert to UTF-16 surrogate pair
  33. code -= 0x10000;
  34. uint32_t lo = code & 0x3ff;
  35. uint32_t hi = (code & 0xffc00) >> 10;
  36. unicode_input_start();
  37. register_hex32(hi + 0xd800);
  38. register_hex32(lo + 0xdc00);
  39. unicode_input_finish();
  40. } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
  41. // when character is out of range supported by the OS
  42. unicode_map_input_error();
  43. } else {
  44. unicode_input_start();
  45. register_hex32(code);
  46. unicode_input_finish();
  47. }
  48. }
  49. return true;
  50. }