diff options
author | 2015-08-20 04:24:39 -0700 | |
---|---|---|
committer | 2015-08-20 04:24:39 -0700 | |
commit | ba6034e8c8cd2bbe15f318e511817e0904633bb3 (patch) | |
tree | 142a152770f435484e97ffa46567cb177753aec3 /sway/input_state.c | |
parent | remove debug message (diff) | |
download | sway-ba6034e8c8cd2bbe15f318e511817e0904633bb3.tar.gz sway-ba6034e8c8cd2bbe15f318e511817e0904633bb3.tar.zst sway-ba6034e8c8cd2bbe15f318e511817e0904633bb3.zip |
changes
Diffstat (limited to 'sway/input_state.c')
-rw-r--r-- | sway/input_state.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/sway/input_state.c b/sway/input_state.c index 0769c30f..51213b19 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -4,14 +4,13 @@ | |||
4 | 4 | ||
5 | #include "input_state.h" | 5 | #include "input_state.h" |
6 | 6 | ||
7 | enum { KEY_STATE_MAX_LENGTH = 64 }; | 7 | #define KEY_STATE_MAX_LENGTH 64 |
8 | 8 | ||
9 | static keycode key_state_array[KEY_STATE_MAX_LENGTH]; | 9 | static keycode key_state_array[KEY_STATE_MAX_LENGTH]; |
10 | static uint8_t key_state_length = 0; | ||
11 | 10 | ||
12 | static uint8_t find_key(keycode key) { | 11 | static uint8_t find_key(keycode key) { |
13 | int i; | 12 | int i; |
14 | for (i = 0; i < key_state_length; ++i) { | 13 | for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { |
15 | if (key_state_array[i] == key) { | 14 | if (key_state_array[i] == key) { |
16 | break; | 15 | break; |
17 | } | 16 | } |
@@ -20,26 +19,25 @@ static uint8_t find_key(keycode key) { | |||
20 | } | 19 | } |
21 | 20 | ||
22 | bool check_key(keycode key) { | 21 | bool check_key(keycode key) { |
23 | return find_key(key) < key_state_length; | 22 | return find_key(key) < KEY_STATE_MAX_LENGTH; |
24 | } | 23 | } |
25 | 24 | ||
26 | void press_key(keycode key) { | 25 | void press_key(keycode key) { |
27 | // Check if key exists | 26 | // Check if key exists |
28 | if (!check_key(key)) { | 27 | if (!check_key(key)) { |
29 | // Check that we dont exceed buffer length | 28 | // Check that we dont exceed buffer length |
30 | if (key_state_length < KEY_STATE_MAX_LENGTH) { | 29 | int insert = find_key(0); |
31 | key_state_array[key_state_length++] = key; | 30 | if (insert < KEY_STATE_MAX_LENGTH) { |
31 | key_state_array[insert] = key; | ||
32 | } | 32 | } |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | void release_key(keycode key) { | 36 | void release_key(keycode key) { |
37 | uint8_t index = find_key(key); | 37 | uint8_t index = find_key(key); |
38 | if (index < key_state_length) { | 38 | if (index < KEY_STATE_MAX_LENGTH) { |
39 | //shift it over and remove key | 39 | //shift it over and remove key |
40 | memmove(&key_state_array[index], | 40 | key_state_array[index] = 0; |
41 | &key_state_array[index + 1], | ||
42 | sizeof(*key_state_array) * (--key_state_length - index)); | ||
43 | } | 41 | } |
44 | } | 42 | } |
45 | 43 | ||