From de9cec2e4392ad9428e327f2a79724a620c7a1ef Mon Sep 17 00:00:00 2001 From: Taiyu Date: Mon, 10 Aug 2015 23:57:25 -0700 Subject: [PATCH] fixed bug --- sway/handlers.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 0ca1a5be..b5f1b69b 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -56,10 +56,11 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge // deny that shit } + bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { #define QSIZE 32 - static uint8_t head = 1; + static uint8_t head = 0; static uint32_t array[QSIZE]; struct sway_mode *mode = config->current_mode; @@ -74,11 +75,9 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers while (mid != head && array[mid] != sym) { ++mid; } - while (mid < head) { - array[mid] = array[mid+1]; - ++mid; - } - --head; + if (mid < head) { + memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid)); + } /* else { key is not found as its been removed } */ } // TODO: reminder to check conflicts with mod+q+a versus mod+q int i; @@ -104,6 +103,15 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers } if (match) { + //Remove matched keys from array + int j; + for (j = 0; j < binding->keys->length; ++j) { + uint8_t k; + for (k = 0; k < head; ++k) { + memmove(array + k, array + k + 1, sizeof*array * (--head - k)); + break; + } + } if (state == WLC_KEY_STATE_PRESSED) { handle_command(config, binding->command); } else if (state == WLC_KEY_STATE_RELEASED) {