aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r--sway/input/keyboard.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 680d1f69..3e196ae1 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -69,8 +69,9 @@ int get_modifier_names(const char **names, uint32_t modifier_masks) {
69/** 69/**
70 * Remove all key ids associated to a keycode from the list of pressed keys 70 * Remove all key ids associated to a keycode from the list of pressed keys
71 */ 71 */
72static void state_erase_key(struct sway_shortcut_state *state, 72static bool state_erase_key(struct sway_shortcut_state *state,
73 uint32_t keycode) { 73 uint32_t keycode) {
74 bool found = false;
74 size_t j = 0; 75 size_t j = 0;
75 for (size_t i = 0; i < state->npressed; ++i) { 76 for (size_t i = 0; i < state->npressed; ++i) {
76 if (i > j) { 77 if (i > j) {
@@ -79,6 +80,8 @@ static void state_erase_key(struct sway_shortcut_state *state,
79 } 80 }
80 if (state->pressed_keycodes[i] != keycode) { 81 if (state->pressed_keycodes[i] != keycode) {
81 ++j; 82 ++j;
83 } else {
84 found = true;
82 } 85 }
83 } 86 }
84 while(state->npressed > j) { 87 while(state->npressed > j) {
@@ -87,6 +90,7 @@ static void state_erase_key(struct sway_shortcut_state *state,
87 state->pressed_keycodes[state->npressed] = 0; 90 state->pressed_keycodes[state->npressed] = 0;
88 } 91 }
89 state->current_key = 0; 92 state->current_key = 0;
93 return found;
90} 94}
91 95
92/** 96/**
@@ -117,7 +121,7 @@ static void state_add_key(struct sway_shortcut_state *state,
117/** 121/**
118 * Update the shortcut model state in response to new input 122 * Update the shortcut model state in response to new input
119 */ 123 */
120static void update_shortcut_state(struct sway_shortcut_state *state, 124static bool update_shortcut_state(struct sway_shortcut_state *state,
121 struct wlr_event_keyboard_key *event, uint32_t new_key, 125 struct wlr_event_keyboard_key *event, uint32_t new_key,
122 uint32_t raw_modifiers) { 126 uint32_t raw_modifiers) {
123 bool last_key_was_a_modifier = raw_modifiers != state->last_raw_modifiers; 127 bool last_key_was_a_modifier = raw_modifiers != state->last_raw_modifiers;
@@ -133,8 +137,10 @@ static void update_shortcut_state(struct sway_shortcut_state *state,
133 state_add_key(state, event->keycode, new_key); 137 state_add_key(state, event->keycode, new_key);
134 state->last_keycode = event->keycode; 138 state->last_keycode = event->keycode;
135 } else { 139 } else {
136 state_erase_key(state, event->keycode); 140 return state_erase_key(state, event->keycode);
137 } 141 }
142
143 return false;
138} 144}
139 145
140/** 146/**
@@ -430,9 +436,13 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
430 } 436 }
431 437
432 if (!handled || event->state == WLR_KEY_RELEASED) { 438 if (!handled || event->state == WLR_KEY_RELEASED) {
433 wlr_seat_set_keyboard(wlr_seat, wlr_device); 439 bool pressed_sent = update_shortcut_state(
434 wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec, 440 &keyboard->state_pressed_sent, event, (uint32_t)keycode, 0);
435 event->keycode, event->state); 441 if (pressed_sent || event->state == WLR_KEY_PRESSED) {
442 wlr_seat_set_keyboard(wlr_seat, wlr_device);
443 wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec,
444 event->keycode, event->state);
445 }
436 } 446 }
437 447
438 transaction_commit_dirty(); 448 transaction_commit_dirty();