unicode.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "unicode_keycodes.h"
  19. /**
  20. * \file
  21. *
  22. * \defgroup unicode Unicode
  23. * \{
  24. */
  25. typedef union {
  26. uint8_t raw;
  27. struct {
  28. uint8_t input_mode : 8;
  29. };
  30. } unicode_config_t;
  31. _Static_assert(sizeof(unicode_config_t) == sizeof(uint8_t), "Unicode EECONFIG out of spec.");
  32. extern unicode_config_t unicode_config;
  33. enum unicode_input_modes {
  34. UNICODE_MODE_MACOS, // macOS using Unicode Hex Input
  35. UNICODE_MODE_LINUX, // Linux using IBus
  36. UNICODE_MODE_WINDOWS, // Windows using EnableHexNumpad
  37. UNICODE_MODE_BSD, // BSD (not implemented)
  38. UNICODE_MODE_WINCOMPOSE, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
  39. UNICODE_MODE_EMACS, // Emacs is an operating system in search of a good text editor
  40. UNICODE_MODE_COUNT // Number of available input modes (always leave at the end)
  41. };
  42. void unicode_input_mode_init(void);
  43. /**
  44. * \brief Get the current Unicode input mode.
  45. *
  46. * \return The currently active Unicode input mode.
  47. */
  48. uint8_t get_unicode_input_mode(void);
  49. /**
  50. * \brief Set the Unicode input mode.
  51. *
  52. * \param mode The input mode to set.
  53. */
  54. void set_unicode_input_mode(uint8_t mode);
  55. /**
  56. * \brief Change to the next Unicode input mode.
  57. */
  58. void unicode_input_mode_step(void);
  59. /**
  60. * \brief Change to the previous Unicode input mode.
  61. */
  62. void unicode_input_mode_step_reverse(void);
  63. /**
  64. * \brief User-level callback, invoked when the input mode is changed.
  65. *
  66. * \param input_mode The new input mode.
  67. */
  68. void unicode_input_mode_set_user(uint8_t input_mode);
  69. /**
  70. * \brief Keyboard-level callback, invoked when the input mode is changed.
  71. *
  72. * \param input_mode The new input mode.
  73. */
  74. void unicode_input_mode_set_kb(uint8_t input_mode);
  75. /**
  76. * \brief Begin the Unicode input sequence. The exact behavior depends on the currently selected input mode.
  77. */
  78. void unicode_input_start(void);
  79. /**
  80. * \brief Complete the Unicode input sequence. The exact behavior depends on the currently selected input mode.
  81. */
  82. void unicode_input_finish(void);
  83. /**
  84. * \brief Cancel the Unicode input sequence. The exact behavior depends on the currently selected input mode.
  85. */
  86. void unicode_input_cancel(void);
  87. /**
  88. * \brief Send a 16-bit hex number.
  89. *
  90. * \param hex The number to send.
  91. */
  92. void register_hex(uint16_t hex);
  93. /**
  94. * \brief Send a 32-bit hex number.
  95. *
  96. * \param hex The number to send.
  97. */
  98. void register_hex32(uint32_t hex);
  99. /**
  100. * \brief Input a single Unicode character. A surrogate pair will be sent if required by the input mode.
  101. *
  102. * \param code_point The code point of the character to send.
  103. */
  104. void register_unicode(uint32_t code_point);
  105. /**
  106. * \brief Send a string containing Unicode characters.
  107. *
  108. * \param str The string to send.
  109. */
  110. void send_unicode_string(const char *str);
  111. /** \} */