diff options
Diffstat (limited to 'sway/input_state.c')
-rw-r--r-- | sway/input_state.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sway/input_state.c b/sway/input_state.c index 2f40b6c2..86868083 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -22,6 +22,8 @@ struct key_state { | |||
22 | 22 | ||
23 | static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; | 23 | static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; |
24 | 24 | ||
25 | static struct key_state last_released; | ||
26 | |||
25 | static uint32_t modifiers_state; | 27 | static uint32_t modifiers_state; |
26 | 28 | ||
27 | void input_init(void) { | 29 | void input_init(void) { |
@@ -31,6 +33,9 @@ void input_init(void) { | |||
31 | key_state_array[i] = none; | 33 | key_state_array[i] = none; |
32 | } | 34 | } |
33 | 35 | ||
36 | struct key_state none = { 0, 0, 0 }; | ||
37 | last_released = none; | ||
38 | |||
34 | modifiers_state = 0; | 39 | modifiers_state = 0; |
35 | } | 40 | } |
36 | 41 | ||
@@ -76,6 +81,12 @@ bool check_key(uint32_t key_sym, uint32_t key_code) { | |||
76 | return find_key(key_sym, key_code, false) < KEY_STATE_MAX_LENGTH; | 81 | return find_key(key_sym, key_code, false) < KEY_STATE_MAX_LENGTH; |
77 | } | 82 | } |
78 | 83 | ||
84 | bool check_released_key(uint32_t key_sym) { | ||
85 | return (key_sym != 0 | ||
86 | && (last_released.key_sym == key_sym | ||
87 | || last_released.alt_sym == key_sym)); | ||
88 | } | ||
89 | |||
79 | void press_key(uint32_t key_sym, uint32_t key_code) { | 90 | void press_key(uint32_t key_sym, uint32_t key_code) { |
80 | if (key_code == 0) { | 91 | if (key_code == 0) { |
81 | return; | 92 | return; |
@@ -94,6 +105,9 @@ void press_key(uint32_t key_sym, uint32_t key_code) { | |||
94 | void release_key(uint32_t key_sym, uint32_t key_code) { | 105 | void release_key(uint32_t key_sym, uint32_t key_code) { |
95 | uint8_t index = find_key(key_sym, key_code, true); | 106 | uint8_t index = find_key(key_sym, key_code, true); |
96 | if (index < KEY_STATE_MAX_LENGTH) { | 107 | if (index < KEY_STATE_MAX_LENGTH) { |
108 | last_released.key_sym = key_state_array[index].key_sym; | ||
109 | last_released.alt_sym = key_state_array[index].alt_sym; | ||
110 | last_released.key_code = key_state_array[index].key_code; | ||
97 | struct key_state none = { 0, 0, 0 }; | 111 | struct key_state none = { 0, 0, 0 }; |
98 | key_state_array[index] = none; | 112 | key_state_array[index] = none; |
99 | } | 113 | } |