diff options
Diffstat (limited to 'sway/key_state.c')
-rw-r--r-- | sway/key_state.c | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/sway/key_state.c b/sway/key_state.c deleted file mode 100644 index 76561dbc..00000000 --- a/sway/key_state.c +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <stdbool.h> | ||
3 | #include <ctype.h> | ||
4 | |||
5 | #include "key_state.h" | ||
6 | |||
7 | enum { KEY_STATE_MAX_LENGTH = 64 }; | ||
8 | |||
9 | static keycode key_state_array[KEY_STATE_MAX_LENGTH]; | ||
10 | static uint8_t key_state_length = 0; | ||
11 | |||
12 | static uint8_t find_key(keycode key) | ||
13 | { | ||
14 | int i; | ||
15 | for (i = 0; i < key_state_length; ++i) | ||
16 | { | ||
17 | if (key_state_array[i] == key) | ||
18 | { | ||
19 | break; | ||
20 | } | ||
21 | } | ||
22 | return i; | ||
23 | } | ||
24 | |||
25 | bool check_key(keycode key) | ||
26 | { | ||
27 | return find_key(key) < key_state_length; | ||
28 | } | ||
29 | |||
30 | void press_key(keycode key) | ||
31 | { | ||
32 | // Check if key exists | ||
33 | if (!check_key(key)) | ||
34 | { | ||
35 | // Check that we dont exceed buffer length | ||
36 | if (key_state_length < KEY_STATE_MAX_LENGTH) { | ||
37 | key_state_array[key_state_length++] = key; | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | |||
42 | void release_key(keycode key) | ||
43 | { | ||
44 | uint8_t index = find_key(key); | ||
45 | if (index < key_state_length) | ||
46 | { | ||
47 | //shift it over and remove key | ||
48 | memmove(&key_state_array[index], | ||
49 | &key_state_array[index + 1], | ||
50 | sizeof(*key_state_array) * (--key_state_length - index)); | ||
51 | } | ||
52 | } | ||