1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* Copyright 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
#include "unicode_keycodes.h"
/**
* \file
*
* \defgroup unicode Unicode
* \{
*/
typedef union {
uint8_t raw;
struct {
uint8_t input_mode : 8;
};
} unicode_config_t;
_Static_assert(sizeof(unicode_config_t) == sizeof(uint8_t), "Unicode EECONFIG out of spec.");
extern unicode_config_t unicode_config;
enum unicode_input_modes {
UNICODE_MODE_MACOS, // macOS using Unicode Hex Input
UNICODE_MODE_LINUX, // Linux using IBus
UNICODE_MODE_WINDOWS, // Windows using EnableHexNumpad
UNICODE_MODE_BSD, // BSD (not implemented)
UNICODE_MODE_WINCOMPOSE, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
UNICODE_MODE_EMACS, // Emacs is an operating system in search of a good text editor
UNICODE_MODE_COUNT // Number of available input modes (always leave at the end)
};
void unicode_input_mode_init(void);
/**
* \brief Get the current Unicode input mode.
*
* \return The currently active Unicode input mode.
*/
uint8_t get_unicode_input_mode(void);
/**
* \brief Set the Unicode input mode.
*
* \param mode The input mode to set.
*/
void set_unicode_input_mode(uint8_t mode);
/**
* \brief Change to the next Unicode input mode.
*/
void unicode_input_mode_step(void);
/**
* \brief Change to the previous Unicode input mode.
*/
void unicode_input_mode_step_reverse(void);
/**
* \brief User-level callback, invoked when the input mode is changed.
*
* \param input_mode The new input mode.
*/
void unicode_input_mode_set_user(uint8_t input_mode);
/**
* \brief Keyboard-level callback, invoked when the input mode is changed.
*
* \param input_mode The new input mode.
*/
void unicode_input_mode_set_kb(uint8_t input_mode);
/**
* \brief Begin the Unicode input sequence. The exact behavior depends on the currently selected input mode.
*/
void unicode_input_start(void);
/**
* \brief Complete the Unicode input sequence. The exact behavior depends on the currently selected input mode.
*/
void unicode_input_finish(void);
/**
* \brief Cancel the Unicode input sequence. The exact behavior depends on the currently selected input mode.
*/
void unicode_input_cancel(void);
/**
* \brief Send a 16-bit hex number.
*
* \param hex The number to send.
*/
void register_hex(uint16_t hex);
/**
* \brief Send a 32-bit hex number.
*
* \param hex The number to send.
*/
void register_hex32(uint32_t hex);
/**
* \brief Input a single Unicode character. A surrogate pair will be sent if required by the input mode.
*
* \param code_point The code point of the character to send.
*/
void register_unicode(uint32_t code_point);
/**
* \brief Send a string containing Unicode characters.
*
* \param str The string to send.
*/
void send_unicode_string(const char *str);
/** \} */
|