summaryrefslogtreecommitdiffstats
path: root/quantum/unicode/ucis.h
blob: 5a4fa267841cf53c992c32888a4028f7cf67b36a (plain)
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
// Copyright 2023 QMK
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <stdbool.h>
#include <stdint.h>

/**
 * \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);

/** \} */