summaryrefslogtreecommitdiff
path: root/src/keyboard.h
blob: 9bf36de1e1730bdfd8a20f0d2a3815150a507a16 (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
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

enum modifiers {
  None = 0,
  Ctrl = 1 << 0,
  Meta = 1 << 1,
  Spec = 1 << 2,
};

#define BACKSPACE Ctrl, '?'
#define DELETE Spec, '3'

#define UP Spec, 'A'
#define DOWN Spec, 'B'
#define RIGHT Spec, 'C'
#define LEFT Spec, 'D'

struct key {
  uint8_t key;
  uint8_t mod;
  uint8_t start;
  uint8_t end;
};

struct keyboard {
  uint32_t reactor_event_id;
  bool has_data;
};

struct keyboard_update {
  struct key keys[32];
  uint32_t nkeys;

  uint8_t raw[64];
  uint32_t nbytes;
};

struct reactor;

struct keyboard keyboard_create(struct reactor *reactor);

struct keyboard_update keyboard_update(struct keyboard *kbd,
                                       struct reactor *reactor);

bool key_equal_char(struct key *key, uint8_t mod, uint8_t c);
bool key_equal(struct key *key1, struct key *key2);
void key_name(struct key *key, char *buf, size_t capacity);