From 737a7421fd32bfd4a451fdd4f210fd7ce7a14695 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Mon, 10 Aug 2015 23:37:25 -0700 Subject: [PATCH 1/7] added multikey handling for handle_key\(...\) --- sway/handlers.c | 51 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index d2d8c5a0..0ca1a5be 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "layout.h" #include "log.h" #include "config.h" @@ -57,41 +58,63 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge 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) { - // TODO: handle keybindings with more than 1 non-modifier key involved - // Note: reminder to check conflicts with mod+q+a versus mod+q - - bool cmd_success = true; - struct sway_mode *mode = config->current_mode; +#define QSIZE 32 + static uint8_t head = 1; + static uint32_t array[QSIZE]; + struct sway_mode *mode = config->current_mode; // Lowercase if necessary sym = tolower(sym); + //Add or remove key to array + if (state == WLC_KEY_STATE_PRESSED && head + 1 < QSIZE) { + array[head++] = sym; + } else if (state == WLC_KEY_STATE_RELEASED) { + uint8_t mid = 0; + while (mid != head && array[mid] != sym) { + ++mid; + } + while (mid < head) { + array[mid] = array[mid+1]; + ++mid; + } + --head; + } + // TODO: reminder to check conflicts with mod+q+a versus mod+q int i; for (i = 0; i < mode->bindings->length; ++i) { struct sway_binding *binding = mode->bindings->items[i]; if ((modifiers->mods & binding->modifiers) == binding->modifiers) { - bool match = true; + bool match; int j; for (j = 0; j < binding->keys->length; ++j) { - xkb_keysym_t *k = binding->keys->items[j]; - if (sym != *k) { - match = false; + match = false; + xkb_keysym_t *key = binding->keys->items[j]; + uint8_t k; + for (k = 0; k < head; ++k) { + if (array[k] == *key) { + match = true; + break; + } + } + if (match == false) { break; } } if (match) { - // TODO: --released if (state == WLC_KEY_STATE_PRESSED) { - cmd_success = !handle_command(config, binding->command); - } else { - cmd_success = true; + handle_command(config, binding->command); + } else if (state == WLC_KEY_STATE_RELEASED) { + // TODO: --released } } } } - return cmd_success; + //repeating sent input is bad + return true; +#undef Q_SIZE } bool pointer_test(swayc_t *view, void *_origin) { From de9cec2e4392ad9428e327f2a79724a620c7a1ef Mon Sep 17 00:00:00 2001 From: Taiyu Date: Mon, 10 Aug 2015 23:57:25 -0700 Subject: [PATCH 2/7] 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) { From 66799480ffabce9c824c2ec4fb75f78cc056a086 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Tue, 11 Aug 2015 00:04:40 -0700 Subject: [PATCH 3/7] removed old code --- sway/handlers.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sway/handlers.c b/sway/handlers.c index b5f1b69b..e441ac8b 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -3,7 +3,6 @@ #include #include #include -#include #include "layout.h" #include "log.h" #include "config.h" From 5534edca6e5ff7e970f626aa7e3abb4c8065e2a7 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Tue, 11 Aug 2015 00:06:43 -0700 Subject: [PATCH 4/7] removed old code --- sway/handlers.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sway/handlers.c b/sway/handlers.c index e441ac8b..8fc299f4 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -119,7 +119,6 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers } } } - //repeating sent input is bad return true; #undef Q_SIZE } From 4e33a9b23c7a342a752852460abf2c1e3875b8b4 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Tue, 11 Aug 2015 00:36:31 -0700 Subject: [PATCH 5/7] define -> enum --- sway/handlers.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 8fc299f4..65e6a7a2 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -55,17 +55,16 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge // deny that shit } +enum { QSIZE = 32 }; 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 = 0; static uint32_t array[QSIZE]; struct sway_mode *mode = config->current_mode; // Lowercase if necessary sym = tolower(sym); - //Add or remove key to array if (state == WLC_KEY_STATE_PRESSED && head + 1 < QSIZE) { array[head++] = sym; @@ -120,7 +119,6 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers } } return true; -#undef Q_SIZE } bool pointer_test(swayc_t *view, void *_origin) { From 5d5a20bf2580c33beb6abc20d2c46afc8505fb09 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Tue, 11 Aug 2015 00:38:02 -0700 Subject: [PATCH 6/7] small fix --- sway/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/handlers.c b/sway/handlers.c index 65e6a7a2..ebe3e349 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -55,10 +55,10 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge // deny that shit } -enum { QSIZE = 32 }; 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) { + enum { QSIZE = 32 }; static uint8_t head = 0; static uint32_t array[QSIZE]; From a22ba1762194e6592a4d7d5e97ba1b3cb3b1e582 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Tue, 11 Aug 2015 01:09:08 -0700 Subject: [PATCH 7/7] added command repeat on keydown --- sway/handlers.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index ebe3e349..979eb3c8 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -61,22 +61,23 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers enum { QSIZE = 32 }; static uint8_t head = 0; static uint32_t array[QSIZE]; + bool cmd_success = true; struct sway_mode *mode = config->current_mode; // Lowercase if necessary sym = tolower(sym); - //Add or remove key to array - if (state == WLC_KEY_STATE_PRESSED && head + 1 < QSIZE) { - array[head++] = sym; - } else if (state == WLC_KEY_STATE_RELEASED) { - uint8_t mid = 0; - while (mid != head && array[mid] != sym) { - ++mid; - } - if (mid < head) { - memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid)); - } /* else { key is not found as its been removed } */ + + //Find key, if it has been pressed + int mid = 0; + while (mid < head && array[mid] != sym) { + ++mid; } + if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { + array[head++] = sym; + } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { + memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid)); + } + sway_log(L_INFO,"%d", head); // TODO: reminder to check conflicts with mod+q+a versus mod+q int i; for (i = 0; i < mode->bindings->length; ++i) { @@ -111,14 +112,14 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers } } if (state == WLC_KEY_STATE_PRESSED) { - handle_command(config, binding->command); + cmd_success = !handle_command(config, binding->command); } else if (state == WLC_KEY_STATE_RELEASED) { // TODO: --released } } } } - return true; + return cmd_success; } bool pointer_test(swayc_t *view, void *_origin) {