aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sway/handlers.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index d2d8c5a0..979eb3c8 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -55,38 +55,66 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge
55 // deny that shit 55 // deny that shit
56} 56}
57 57
58
58bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers 59bool 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 enum { QSIZE = 32 };
61 // Note: reminder to check conflicts with mod+q+a versus mod+q 62 static uint8_t head = 0;
62 63 static uint32_t array[QSIZE];
63 bool cmd_success = true; 64 bool cmd_success = true;
64 struct sway_mode *mode = config->current_mode;
65 65
66 struct sway_mode *mode = config->current_mode;
66 // Lowercase if necessary 67 // Lowercase if necessary
67 sym = tolower(sym); 68 sym = tolower(sym);
68 69
70 //Find key, if it has been pressed
71 int mid = 0;
72 while (mid < head && array[mid] != sym) {
73 ++mid;
74 }
75 if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
76 array[head++] = sym;
77 } else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
78 memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid));
79 }
80 sway_log(L_INFO,"%d", head);
81 // TODO: reminder to check conflicts with mod+q+a versus mod+q
69 int i; 82 int i;
70 for (i = 0; i < mode->bindings->length; ++i) { 83 for (i = 0; i < mode->bindings->length; ++i) {
71 struct sway_binding *binding = mode->bindings->items[i]; 84 struct sway_binding *binding = mode->bindings->items[i];
72 85
73 if ((modifiers->mods & binding->modifiers) == binding->modifiers) { 86 if ((modifiers->mods & binding->modifiers) == binding->modifiers) {
74 bool match = true; 87 bool match;
75 int j; 88 int j;
76 for (j = 0; j < binding->keys->length; ++j) { 89 for (j = 0; j < binding->keys->length; ++j) {
77 xkb_keysym_t *k = binding->keys->items[j]; 90 match = false;
78 if (sym != *k) { 91 xkb_keysym_t *key = binding->keys->items[j];
79 match = false; 92 uint8_t k;
93 for (k = 0; k < head; ++k) {
94 if (array[k] == *key) {
95 match = true;
96 break;
97 }
98 }
99 if (match == false) {
80 break; 100 break;
81 } 101 }
82 } 102 }
83 103
84 if (match) { 104 if (match) {
85 // TODO: --released 105 //Remove matched keys from array
106 int j;
107 for (j = 0; j < binding->keys->length; ++j) {
108 uint8_t k;
109 for (k = 0; k < head; ++k) {
110 memmove(array + k, array + k + 1, sizeof*array * (--head - k));
111 break;
112 }
113 }
86 if (state == WLC_KEY_STATE_PRESSED) { 114 if (state == WLC_KEY_STATE_PRESSED) {
87 cmd_success = !handle_command(config, binding->command); 115 cmd_success = !handle_command(config, binding->command);
88 } else { 116 } else if (state == WLC_KEY_STATE_RELEASED) {
89 cmd_success = true; 117 // TODO: --released
90 } 118 }
91 } 119 }
92 } 120 }