ucis.h (1785B)
1 // Copyright 2023 QMK 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 4 #pragma once 5 6 #include <stdbool.h> 7 #include <stdint.h> 8 9 /** 10 * \file 11 * 12 * \defgroup ucis UCIS 13 * \{ 14 */ 15 16 #ifndef UCIS_MAX_INPUT_LENGTH 17 # define UCIS_MAX_INPUT_LENGTH 32 18 #endif 19 20 #ifndef UCIS_MAX_CODE_POINTS 21 # define UCIS_MAX_CODE_POINTS 3 22 #endif 23 24 typedef struct { 25 char* mnemonic; 26 uint32_t code_points[UCIS_MAX_CODE_POINTS]; 27 } ucis_symbol_t; 28 29 // clang-format off 30 31 #define UCIS_TABLE(...) { \ 32 __VA_ARGS__, \ 33 { NULL, {} } \ 34 } 35 36 #define UCIS_SYM(name, ...) { \ 37 .mnemonic = name, \ 38 .code_points = {__VA_ARGS__} \ 39 } 40 41 // clang-format on 42 43 extern const ucis_symbol_t ucis_symbol_table[]; 44 45 /** 46 * \brief Begin the input sequence. 47 */ 48 void ucis_start(void); 49 50 /** 51 * \brief Whether UCIS is currently active. 52 * 53 * \return `true` if UCIS is active. 54 */ 55 bool ucis_active(void); 56 57 /** 58 * \brief Get the number of characters in the input sequence buffer. 59 * 60 * \return The current input sequence buffer length. 61 */ 62 uint8_t ucis_count(void); 63 64 /** 65 * \brief Add the given keycode to the input sequence buffer. 66 * 67 * \param keycode The keycode to add. Must be between `KC_A` and `KC_Z`, or `KC_1` and `KC_0`. 68 * 69 * \return `true` if the keycode was added. 70 */ 71 bool ucis_add(uint16_t keycode); 72 73 /** 74 * \brief Remove the last character from the input sequence. 75 * 76 * \return `true` if the sequence was not empty. 77 */ 78 bool ucis_remove_last(void); 79 80 /** 81 * Mark the input sequence as complete, and attempt to match. 82 */ 83 void ucis_finish(void); 84 85 /** 86 * \brief Cancel the input sequence. 87 */ 88 void ucis_cancel(void); 89 90 /** 91 * Send the code point(s) for the given UCIS index. 92 * 93 * \param index The index into the UCIS symbol table. 94 */ 95 void register_ucis(uint8_t index); 96 97 /** \} */