diff options
Diffstat (limited to 'main/keyboard.h')
| -rw-r--r-- | main/keyboard.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/main/keyboard.h b/main/keyboard.h new file mode 100644 index 0000000..9c4118f --- /dev/null +++ b/main/keyboard.h | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #ifndef KEYBOARD_H | ||
| 2 | #define KEYBOARD_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | |||
| 7 | #define KB_INPUT_MAX 64 | ||
| 8 | |||
| 9 | typedef enum { | ||
| 10 | KB_ALPHA_LOWER, | ||
| 11 | KB_ALPHA_UPPER, | ||
| 12 | KB_NUMSYM | ||
| 13 | } kb_layer_t; | ||
| 14 | |||
| 15 | typedef enum { | ||
| 16 | KB_ACTION_NONE = 0, | ||
| 17 | KB_ACTION_CHAR, | ||
| 18 | KB_ACTION_SHIFT, | ||
| 19 | KB_ACTION_BACKSPACE, | ||
| 20 | KB_ACTION_DONE, | ||
| 21 | KB_ACTION_LAYER, | ||
| 22 | KB_ACTION_SPACE | ||
| 23 | } kb_action_t; | ||
| 24 | |||
| 25 | typedef struct { | ||
| 26 | char input[KB_INPUT_MAX + 1]; | ||
| 27 | int cursor; | ||
| 28 | bool reveal; | ||
| 29 | kb_layer_t layer; | ||
| 30 | } kb_state_t; | ||
| 31 | |||
| 32 | typedef struct { | ||
| 33 | kb_action_t action; | ||
| 34 | char ch; | ||
| 35 | } kb_result_t; | ||
| 36 | |||
| 37 | typedef struct { | ||
| 38 | int key_w; | ||
| 39 | int key_h; | ||
| 40 | int key_gap; | ||
| 41 | int start_y; | ||
| 42 | int screen_w; | ||
| 43 | int row_count; | ||
| 44 | } kb_layout_t; | ||
| 45 | |||
| 46 | void kb_state_init(kb_state_t *st); | ||
| 47 | void kb_set_layout(const kb_layout_t *layout); | ||
| 48 | const kb_layout_t *kb_get_layout(void); | ||
| 49 | int kb_get_row_keys(int row, kb_layer_t layer, const char **keys_out); | ||
| 50 | kb_result_t kb_hit_test(int tx, int ty, kb_layer_t layer); | ||
| 51 | void kb_apply(kb_state_t *st, kb_result_t result); | ||
| 52 | |||
| 53 | #endif | ||