diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-19 20:22:15 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-19 20:22:15 -0700 |
commit | 5ff0619ca1cab044004df044c253c9170b8316c3 (patch) | |
tree | 7872a66e494acb90dd08ffc76665557b0e0ca874 /sway/input_state.c | |
parent | key_state.ch, and command conflicts resolved (diff) | |
download | sway-5ff0619ca1cab044004df044c253c9170b8316c3.tar.gz sway-5ff0619ca1cab044004df044c253c9170b8316c3.tar.zst sway-5ff0619ca1cab044004df044c253c9170b8316c3.zip |
input state, find_container_in_direction
Diffstat (limited to 'sway/input_state.c')
-rw-r--r-- | sway/input_state.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/sway/input_state.c b/sway/input_state.c new file mode 100644 index 00000000..0769c30f --- /dev/null +++ b/sway/input_state.c | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <string.h> | ||
2 | #include <stdbool.h> | ||
3 | #include <ctype.h> | ||
4 | |||
5 | #include "input_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 | int i; | ||
14 | for (i = 0; i < key_state_length; ++i) { | ||
15 | if (key_state_array[i] == key) { | ||
16 | break; | ||
17 | } | ||
18 | } | ||
19 | return i; | ||
20 | } | ||
21 | |||
22 | bool check_key(keycode key) { | ||
23 | return find_key(key) < key_state_length; | ||
24 | } | ||
25 | |||
26 | void press_key(keycode key) { | ||
27 | // Check if key exists | ||
28 | if (!check_key(key)) { | ||
29 | // Check that we dont exceed buffer length | ||
30 | if (key_state_length < KEY_STATE_MAX_LENGTH) { | ||
31 | key_state_array[key_state_length++] = key; | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
36 | void release_key(keycode key) { | ||
37 | uint8_t index = find_key(key); | ||
38 | if (index < key_state_length) { | ||
39 | //shift it over and remove key | ||
40 | memmove(&key_state_array[index], | ||
41 | &key_state_array[index + 1], | ||
42 | sizeof(*key_state_array) * (--key_state_length - index)); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0, 0}}; | ||
47 | |||
48 | static struct wlc_geometry saved_floating; | ||
49 | |||
50 | void start_floating(swayc_t *view) { | ||
51 | if (view->is_floating) { | ||
52 | saved_floating.origin.x = view->x; | ||
53 | saved_floating.origin.y = view->y; | ||
54 | saved_floating.size.w = view->width; | ||
55 | saved_floating.size.h = view->height; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | void reset_floating(swayc_t *view) { | ||
60 | if (view->is_floating) { | ||
61 | view->x = saved_floating.origin.x; | ||
62 | view->y = saved_floating.origin.y; | ||
63 | view->width = saved_floating.size.w; | ||
64 | view->height = saved_floating.size.h; | ||
65 | arrange_windows(view->parent, -1, -1); | ||
66 | } | ||
67 | pointer_state.floating = (struct pointer_floating){0,0}; | ||
68 | pointer_state.lock = (struct pointer_lock){0,0,0,0}; | ||
69 | } | ||
70 | |||