forked from dzhu/keytap
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkey_action.h
66 lines (53 loc) · 1.49 KB
/
key_action.h
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
#ifndef KEY_ACTION_H
#define KEY_ACTION_H
struct key_action_t;
typedef struct key_action_t key_action_t;
struct key_macro_t;
typedef struct key_macro_t key_macro_t;
struct key_macro_t{
int code;
bool press;
key_macro_t *next;
};
typedef enum {
// rollover waveform triggers the "tap" key action
DUAL_MODE_TAP_ON_ROLLOVER = 0,
// rollover waveform triggers the "hold" key action
DUAL_MODE_HOLD_ON_ROLLOVER = 1,
// only the timeout can trigger the "hold" key action
DUAL_MODE_TIMEOUT_ONLY = 2,
} dual_key_mode_t;
typedef struct {
// members must not be addtional key_dual_t's
key_action_t *tap;
key_action_t *hold;
dual_key_mode_t mode;
long hold_ms;
long double_tap_ms;
} key_dual_t;
enum key_type {
KT_NONE,
KT_SIMPLE,
KT_MACRO,
KT_DUAL,
KT_MAP,
};
union key_union {
int simple;
key_macro_t *macro;
key_dual_t dual;
key_action_t *map; // always allocated to length of 256
key_action_t *ref; // non-root keymaps with KT_NONE will have this filled
};
struct key_action_t {
enum key_type type;
union key_union key;
};
key_macro_t *key_macro_new(int code, bool press);
void key_macro_free(key_macro_t *macro);
key_macro_t *key_macro_dup(key_macro_t *macro);
void key_action_free(key_action_t *ka);
int key_action_dup(const key_action_t *in, key_action_t *out);
// helper function for dereferencing key actions from a key action map
key_action_t *key_action_get(key_action_t *ka, int i);
#endif // KEY_ACTION_H