mirror of
https://github.com/swaywm/sway.git
synced 2026-03-31 07:11:24 -04:00
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.
This commit is contained in:
parent
8f5de70c93
commit
55f63935ab
5 changed files with 92 additions and 27 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue