Parent directory

unicode.h

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