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