unicode.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Copyright 2022
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <stdint.h>
  18. #include "quantum.h"
  19. typedef union {
  20. uint8_t raw;
  21. struct {
  22. uint8_t input_mode : 8;
  23. };
  24. } unicode_config_t;
  25. _Static_assert(sizeof(unicode_config_t) == sizeof(uint8_t), "Unicode EECONFIG out of spec.");
  26. extern unicode_config_t unicode_config;
  27. enum unicode_input_modes {
  28. UNICODE_MODE_MACOS, // macOS using Unicode Hex Input
  29. UNICODE_MODE_LINUX, // Linux using IBus
  30. UNICODE_MODE_WINDOWS, // Windows using EnableHexNumpad
  31. UNICODE_MODE_BSD, // BSD (not implemented)
  32. UNICODE_MODE_WINCOMPOSE, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
  33. UNICODE_MODE_EMACS, // Emacs is an operating system in search of a good text editor
  34. UNICODE_MODE_COUNT // Number of available input modes (always leave at the end)
  35. };
  36. void unicode_input_mode_init(void);
  37. uint8_t get_unicode_input_mode(void);
  38. void set_unicode_input_mode(uint8_t mode);
  39. void cycle_unicode_input_mode(int8_t offset);
  40. void persist_unicode_input_mode(void);
  41. void unicode_input_mode_set_user(uint8_t input_mode);
  42. void unicode_input_mode_set_kb(uint8_t input_mode);
  43. void unicode_input_start(void);
  44. void unicode_input_finish(void);
  45. void unicode_input_cancel(void);
  46. void register_hex(uint16_t hex);
  47. void register_hex32(uint32_t hex);
  48. void register_unicode(uint32_t code_point);
  49. void send_unicode_string(const char *str);
  50. // clang-format off
  51. #define UC_BSPC UC(0x0008) // (backspace)
  52. #define UC_SPC UC(0x0020) // (space)
  53. #define UC_EXLM UC(0x0021) // !
  54. #define UC_DQUT UC(0x0022) // "
  55. #define UC_HASH UC(0x0023) // #
  56. #define UC_DLR UC(0x0024) // $
  57. #define UC_PERC UC(0x0025) // %
  58. #define UC_AMPR UC(0x0026) // &
  59. #define UC_QUOT UC(0x0027) // '
  60. #define UC_LPRN UC(0x0028) // (
  61. #define UC_RPRN UC(0x0029) // )
  62. #define UC_ASTR UC(0x002A) // *
  63. #define UC_PLUS UC(0x002B) // +
  64. #define UC_COMM UC(0x002C) // ,
  65. #define UC_DASH UC(0x002D) // -
  66. #define UC_DOT UC(0x002E) // .
  67. #define UC_SLSH UC(0x002F) // /
  68. #define UC_0 UC(0x0030) // 0
  69. #define UC_1 UC(0x0031) // 1
  70. #define UC_2 UC(0x0032) // 2
  71. #define UC_3 UC(0x0033) // 3
  72. #define UC_4 UC(0x0034) // 4
  73. #define UC_5 UC(0x0035) // 5
  74. #define UC_6 UC(0x0036) // 6
  75. #define UC_7 UC(0x0037) // 7
  76. #define UC_8 UC(0x0038) // 8
  77. #define UC_9 UC(0x0039) // 9
  78. #define UC_COLN UC(0x003A) // :
  79. #define UC_SCLN UC(0x003B) // ;
  80. #define UC_LT UC(0x003C) // <
  81. #define UC_EQL UC(0x003D) // =
  82. #define UC_GT UC(0x003E) // >
  83. #define UC_QUES UC(0x003F) // ?
  84. #define UC_AT UC(0x0040) // @
  85. #define UC_A UC(0x0041) // A
  86. #define UC_B UC(0x0042) // B
  87. #define UC_C UC(0x0043) // C
  88. #define UC_D UC(0x0044) // D
  89. #define UC_E UC(0x0045) // E
  90. #define UC_F UC(0x0046) // F
  91. #define UC_G UC(0x0047) // G
  92. #define UC_H UC(0x0048) // H
  93. #define UC_I UC(0x0049) // I
  94. #define UC_J UC(0x004A) // J
  95. #define UC_K UC(0x004B) // K
  96. #define UC_L UC(0x004C) // L
  97. #define UC_M UC(0x004D) // M
  98. #define UC_N UC(0x004E) // N
  99. #define UC_O UC(0x004F) // O
  100. #define UC_P UC(0x0050) // P
  101. #define UC_Q UC(0x0051) // Q
  102. #define UC_R UC(0x0052) // R
  103. #define UC_S UC(0x0053) // S
  104. #define UC_T UC(0x0054) // T
  105. #define UC_U UC(0x0055) // U
  106. #define UC_V UC(0x0056) // V
  107. #define UC_W UC(0x0057) // W
  108. #define UC_X UC(0x0058) // X
  109. #define UC_Y UC(0x0059) // Y
  110. #define UC_Z UC(0x005A) // Z
  111. #define UC_LBRC UC(0x005B) // [
  112. #define UC_BSLS UC(0x005C) // (backslash)
  113. #define UC_RBRC UC(0x005D) // ]
  114. #define UC_CIRM UC(0x005E) // ^
  115. #define UC_UNDR UC(0x005F) // _
  116. #define UC_GRV UC(0x0060) // `
  117. #define UC_a UC(0x0061) // a
  118. #define UC_b UC(0x0062) // b
  119. #define UC_c UC(0x0063) // c
  120. #define UC_d UC(0x0064) // d
  121. #define UC_e UC(0x0065) // e
  122. #define UC_f UC(0x0066) // f
  123. #define UC_g UC(0x0067) // g
  124. #define UC_h UC(0x0068) // h
  125. #define UC_i UC(0x0069) // i
  126. #define UC_j UC(0x006A) // j
  127. #define UC_k UC(0x006B) // k
  128. #define UC_l UC(0x006C) // l
  129. #define UC_m UC(0x006D) // m
  130. #define UC_n UC(0x006E) // n
  131. #define UC_o UC(0x006F) // o
  132. #define UC_p UC(0x0070) // p
  133. #define UC_q UC(0x0071) // q
  134. #define UC_r UC(0x0072) // r
  135. #define UC_s UC(0x0073) // s
  136. #define UC_t UC(0x0074) // t
  137. #define UC_u UC(0x0075) // u
  138. #define UC_v UC(0x0076) // v
  139. #define UC_w UC(0x0077) // w
  140. #define UC_x UC(0x0078) // x
  141. #define UC_y UC(0x0079) // y
  142. #define UC_z UC(0x007A) // z
  143. #define UC_LCBR UC(0x007B) // {
  144. #define UC_PIPE UC(0x007C) // |
  145. #define UC_RCBR UC(0x007D) // }
  146. #define UC_TILD UC(0x007E) // ~
  147. #define UC_DEL UC(0x007F) // (delete)