diff options
author | 2015-08-10 23:37:25 -0700 | |
---|---|---|
committer | 2015-08-10 23:37:25 -0700 | |
commit | 737a7421fd32bfd4a451fdd4f210fd7ce7a14695 (patch) | |
tree | 16cfb342c643dea05082109756c33e16e807e99d | |
parent | Slightly better multihead support (diff) | |
download | sway-737a7421fd32bfd4a451fdd4f210fd7ce7a14695.tar.gz sway-737a7421fd32bfd4a451fdd4f210fd7ce7a14695.tar.zst sway-737a7421fd32bfd4a451fdd4f210fd7ce7a14695.zip |
added multikey handling for handle_key\(...\)
-rw-r--r-- | sway/handlers.c | 51 |
1 files 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 @@ | |||
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include <ctype.h> | 5 | #include <ctype.h> |
6 | #include <string.h> | ||
6 | #include "layout.h" | 7 | #include "layout.h" |
7 | #include "log.h" | 8 | #include "log.h" |
8 | #include "config.h" | 9 | #include "config.h" |
@@ -57,41 +58,63 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge | |||
57 | 58 | ||
58 | bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers | 59 | bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers |
59 | *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { | 60 | *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { |
60 | // TODO: handle keybindings with more than 1 non-modifier key involved | 61 | #define QSIZE 32 |
61 | // Note: reminder to check conflicts with mod+q+a versus mod+q | 62 | static uint8_t head = 1; |
62 | 63 | static uint32_t array[QSIZE]; | |
63 | bool cmd_success = true; | ||
64 | struct sway_mode *mode = config->current_mode; | ||
65 | 64 | ||
65 | struct sway_mode *mode = config->current_mode; | ||
66 | // Lowercase if necessary | 66 | // Lowercase if necessary |
67 | sym = tolower(sym); | 67 | sym = tolower(sym); |
68 | 68 | ||
69 | //Add or remove key to array | ||
70 | if (state == WLC_KEY_STATE_PRESSED && head + 1 < QSIZE) { | ||
71 | array[head++] = sym; | ||
72 | } else if (state == WLC_KEY_STATE_RELEASED) { | ||
73 | uint8_t mid = 0; | ||
74 | while (mid != head && array[mid] != sym) { | ||
75 | ++mid; | ||
76 | } | ||
77 | while (mid < head) { | ||
78 | array[mid] = array[mid+1]; | ||
79 | ++mid; | ||
80 | } | ||
81 | --head; | ||
82 | } | ||
83 | // TODO: reminder to check conflicts with mod+q+a versus mod+q | ||
69 | int i; | 84 | int i; |
70 | for (i = 0; i < mode->bindings->length; ++i) { | 85 | for (i = 0; i < mode->bindings->length; ++i) { |
71 | struct sway_binding *binding = mode->bindings->items[i]; | 86 | struct sway_binding *binding = mode->bindings->items[i]; |
72 | 87 | ||
73 | if ((modifiers->mods & binding->modifiers) == binding->modifiers) { | 88 | if ((modifiers->mods & binding->modifiers) == binding->modifiers) { |
74 | bool match = true; | 89 | bool match; |
75 | int j; | 90 | int j; |
76 | for (j = 0; j < binding->keys->length; ++j) { | 91 | for (j = 0; j < binding->keys->length; ++j) { |
77 | xkb_keysym_t *k = binding->keys->items[j]; | 92 | match = false; |
78 | if (sym != *k) { | 93 | xkb_keysym_t *key = binding->keys->items[j]; |
79 | match = false; | 94 | uint8_t k; |
95 | for (k = 0; k < head; ++k) { | ||
96 | if (array[k] == *key) { | ||
97 | match = true; | ||
98 | break; | ||
99 | } | ||
100 | } | ||
101 | if (match == false) { | ||
80 | break; | 102 | break; |
81 | } | 103 | } |
82 | } | 104 | } |
83 | 105 | ||
84 | if (match) { | 106 | if (match) { |
85 | // TODO: --released | ||
86 | if (state == WLC_KEY_STATE_PRESSED) { | 107 | if (state == WLC_KEY_STATE_PRESSED) { |
87 | cmd_success = !handle_command(config, binding->command); | 108 | handle_command(config, binding->command); |
88 | } else { | 109 | } else if (state == WLC_KEY_STATE_RELEASED) { |
89 | cmd_success = true; | 110 | // TODO: --released |
90 | } | 111 | } |
91 | } | 112 | } |
92 | } | 113 | } |
93 | } | 114 | } |
94 | return cmd_success; | 115 | //repeating sent input is bad |
116 | return true; | ||
117 | #undef Q_SIZE | ||
95 | } | 118 | } |
96 | 119 | ||
97 | bool pointer_test(swayc_t *view, void *_origin) { | 120 | bool pointer_test(swayc_t *view, void *_origin) { |