From 70e34e491c297231a3f987fd69760d38e79dbfa4 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 27 Aug 2023 13:30:19 +1000 Subject: Unicode, Unicodemap and UCIS refactor (#21659) --- quantum/unicode/ucis.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 quantum/unicode/ucis.h (limited to 'quantum/unicode/ucis.h') diff --git a/quantum/unicode/ucis.h b/quantum/unicode/ucis.h new file mode 100644 index 0000000000..5a4fa26784 --- /dev/null +++ b/quantum/unicode/ucis.h @@ -0,0 +1,97 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +/** + * \file + * + * \defgroup ucis UCIS + * \{ + */ + +#ifndef UCIS_MAX_INPUT_LENGTH +# define UCIS_MAX_INPUT_LENGTH 32 +#endif + +#ifndef UCIS_MAX_CODE_POINTS +# define UCIS_MAX_CODE_POINTS 3 +#endif + +typedef struct { + char* mnemonic; + uint32_t code_points[UCIS_MAX_CODE_POINTS]; +} ucis_symbol_t; + +// clang-format off + +#define UCIS_TABLE(...) { \ + __VA_ARGS__, \ + { NULL, {} } \ +} + +#define UCIS_SYM(name, ...) { \ + .mnemonic = name, \ + .code_points = {__VA_ARGS__} \ +} + +// clang-format on + +extern const ucis_symbol_t ucis_symbol_table[]; + +/** + * \brief Begin the input sequence. + */ +void ucis_start(void); + +/** + * \brief Whether UCIS is currently active. + * + * \return `true` if UCIS is active. + */ +bool ucis_active(void); + +/** + * \brief Get the number of characters in the input sequence buffer. + * + * \return The current input sequence buffer length. + */ +uint8_t ucis_count(void); + +/** + * \brief Add the given keycode to the input sequence buffer. + * + * \param keycode The keycode to add. Must be between `KC_A` and `KC_Z`, or `KC_1` and `KC_0`. + * + * \return `true` if the keycode was added. + */ +bool ucis_add(uint16_t keycode); + +/** + * \brief Remove the last character from the input sequence. + * + * \return `true` if the sequence was not empty. + */ +bool ucis_remove_last(void); + +/** + * Mark the input sequence as complete, and attempt to match. + */ +void ucis_finish(void); + +/** + * \brief Cancel the input sequence. + */ +void ucis_cancel(void); + +/** + * Send the code point(s) for the given UCIS index. + * + * \param index The index into the UCIS symbol table. + */ +void register_ucis(uint8_t index); + +/** \} */ -- cgit v1.2.3