From 55f63935ab9319da8e145b49edc1a7ae3e6782c6 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Thu, 7 Jan 2016 21:43:00 +0100 Subject: Implement bindsym --release This is a "simple" version of --release (same as i3) that only supports a binding that contain one normal key. e.g.: bindsym --release $mod+x exec somthing-fun I didn't bother implementing it for a combination like `$mod+x+z` since it is a bit tricky to get right and also a bit weird to actually do on a keyboard. --- sway/input_state.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'sway/input_state.c') 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 { static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; +static struct key_state last_released; + static uint32_t modifiers_state; void input_init(void) { @@ -31,6 +33,9 @@ void input_init(void) { key_state_array[i] = none; } + struct key_state none = { 0, 0, 0 }; + last_released = none; + modifiers_state = 0; } @@ -76,6 +81,12 @@ bool check_key(uint32_t key_sym, uint32_t key_code) { return find_key(key_sym, key_code, false) < KEY_STATE_MAX_LENGTH; } +bool check_released_key(uint32_t key_sym) { + return (key_sym != 0 + && (last_released.key_sym == key_sym + || last_released.alt_sym == key_sym)); +} + void press_key(uint32_t key_sym, uint32_t key_code) { if (key_code == 0) { return; @@ -94,6 +105,9 @@ void press_key(uint32_t key_sym, uint32_t key_code) { void release_key(uint32_t key_sym, uint32_t key_code) { uint8_t index = find_key(key_sym, key_code, true); if (index < KEY_STATE_MAX_LENGTH) { + last_released.key_sym = key_state_array[index].key_sym; + last_released.alt_sym = key_state_array[index].alt_sym; + last_released.key_code = key_state_array[index].key_code; struct key_state none = { 0, 0, 0 }; key_state_array[index] = none; } -- cgit v1.2.3