diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-20 04:24:39 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-20 04:24:39 -0700 |
commit | ba6034e8c8cd2bbe15f318e511817e0904633bb3 (patch) | |
tree | 142a152770f435484e97ffa46567cb177753aec3 /sway/input_state.c | |
parent | 1d9b73ed67d9c961cf14d3d2649c84ac0ead13df (diff) |
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 @@ #include "input_state.h" -enum { KEY_STATE_MAX_LENGTH = 64 }; +#define KEY_STATE_MAX_LENGTH 64 static keycode key_state_array[KEY_STATE_MAX_LENGTH]; -static uint8_t key_state_length = 0; static uint8_t find_key(keycode key) { int i; - for (i = 0; i < key_state_length; ++i) { + for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { if (key_state_array[i] == key) { break; } @@ -20,26 +19,25 @@ static uint8_t find_key(keycode key) { } bool check_key(keycode key) { - return find_key(key) < key_state_length; + return find_key(key) < KEY_STATE_MAX_LENGTH; } void press_key(keycode key) { // Check if key exists if (!check_key(key)) { // Check that we dont exceed buffer length - if (key_state_length < KEY_STATE_MAX_LENGTH) { - key_state_array[key_state_length++] = key; + int insert = find_key(0); + if (insert < KEY_STATE_MAX_LENGTH) { + key_state_array[insert] = key; } } } void release_key(keycode key) { uint8_t index = find_key(key); - if (index < key_state_length) { + if (index < KEY_STATE_MAX_LENGTH) { //shift it over and remove key - memmove(&key_state_array[index], - &key_state_array[index + 1], - sizeof(*key_state_array) * (--key_state_length - index)); + key_state_array[index] = 0; } } |