diff options
-rw-r--r-- | sway/commands/bind.c | 21 | ||||
-rw-r--r-- | sway/input/keyboard.c | 17 |
2 files changed, 18 insertions, 20 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 99f54f46..ef9a4b7a 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -16,15 +16,14 @@ | |||
16 | int binding_order = 0; | 16 | int binding_order = 0; |
17 | 17 | ||
18 | void free_sway_binding(struct sway_binding *binding) { | 18 | void free_sway_binding(struct sway_binding *binding) { |
19 | if (binding->keys) { | 19 | if (!binding) { |
20 | for (int i = 0; i < binding->keys->length; i++) { | 20 | return; |
21 | free(binding->keys->items[i]); | ||
22 | } | ||
23 | list_free(binding->keys); | ||
24 | } | 21 | } |
25 | if (binding->command) { | 22 | |
26 | free(binding->command); | 23 | if (binding->keys) { |
24 | free_flat_list(binding->keys); | ||
27 | } | 25 | } |
26 | free(binding->command); | ||
28 | free(binding); | 27 | free(binding); |
29 | } | 28 | } |
30 | 29 | ||
@@ -72,7 +71,7 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
72 | return error; | 71 | return error; |
73 | } | 72 | } |
74 | 73 | ||
75 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | 74 | struct sway_binding *binding = calloc(1, sizeof(struct sway_binding)); |
76 | if (!binding) { | 75 | if (!binding) { |
77 | return cmd_results_new(CMD_FAILURE, "bindsym", | 76 | return cmd_results_new(CMD_FAILURE, "bindsym", |
78 | "Unable to allocate binding"); | 77 | "Unable to allocate binding"); |
@@ -122,7 +121,7 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
122 | free_flat_list(split); | 121 | free_flat_list(split); |
123 | return ret; | 122 | return ret; |
124 | } | 123 | } |
125 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); | 124 | xkb_keysym_t *key = calloc(1, sizeof(xkb_keysym_t)); |
126 | if (!key) { | 125 | if (!key) { |
127 | free_sway_binding(binding); | 126 | free_sway_binding(binding); |
128 | free_flat_list(split); | 127 | free_flat_list(split); |
@@ -165,7 +164,7 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { | |||
165 | return error; | 164 | return error; |
166 | } | 165 | } |
167 | 166 | ||
168 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | 167 | struct sway_binding *binding = calloc(1, sizeof(struct sway_binding)); |
169 | if (!binding) { | 168 | if (!binding) { |
170 | return cmd_results_new(CMD_FAILURE, "bindsym", | 169 | return cmd_results_new(CMD_FAILURE, "bindsym", |
171 | "Unable to allocate binding"); | 170 | "Unable to allocate binding"); |
@@ -209,7 +208,7 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { | |||
209 | list_free(split); | 208 | list_free(split); |
210 | return error; | 209 | return error; |
211 | } | 210 | } |
212 | xkb_keycode_t *key = malloc(sizeof(xkb_keycode_t)); | 211 | xkb_keycode_t *key = calloc(1, sizeof(xkb_keycode_t)); |
213 | *key = keycode - 8; | 212 | *key = keycode - 8; |
214 | list_add(binding->keys, key); | 213 | list_add(binding->keys, key); |
215 | } | 214 | } |
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 6272dcce..3090d32f 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -67,9 +67,7 @@ static bool keyboard_execute_bindsym(struct sway_keyboard *keyboard, | |||
67 | list_t *keysym_bindings = config->current_mode->keysym_bindings; | 67 | list_t *keysym_bindings = config->current_mode->keysym_bindings; |
68 | for (int i = 0; i < keysym_bindings->length; ++i) { | 68 | for (int i = 0; i < keysym_bindings->length; ++i) { |
69 | struct sway_binding *binding = keysym_bindings->items[i]; | 69 | struct sway_binding *binding = keysym_bindings->items[i]; |
70 | sway_log(L_DEBUG, "@@ checking binding: %s", binding->command); | ||
71 | if (modifiers ^ binding->modifiers || n != binding->keys->length) { | 70 | if (modifiers ^ binding->modifiers || n != binding->keys->length) { |
72 | sway_log(L_DEBUG, "@@ modifiers or key num dont match"); | ||
73 | continue; | 71 | continue; |
74 | } | 72 | } |
75 | 73 | ||
@@ -85,7 +83,8 @@ static bool keyboard_execute_bindsym(struct sway_keyboard *keyboard, | |||
85 | } | 83 | } |
86 | 84 | ||
87 | if (match) { | 85 | if (match) { |
88 | sway_log(L_DEBUG, "running command for binding: %s", binding->command); | 86 | sway_log(L_DEBUG, "running command for binding: %s", |
87 | binding->command); | ||
89 | struct cmd_results *results = handle_command(binding->command); | 88 | struct cmd_results *results = handle_command(binding->command); |
90 | if (results->status != CMD_SUCCESS) { | 89 | if (results->status != CMD_SUCCESS) { |
91 | sway_log(L_DEBUG, "could not run command for binding: %s", | 90 | sway_log(L_DEBUG, "could not run command for binding: %s", |
@@ -291,7 +290,6 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
291 | 290 | ||
292 | // handle keycodes | 291 | // handle keycodes |
293 | handled = keyboard_execute_bindcode(keyboard); | 292 | handled = keyboard_execute_bindcode(keyboard); |
294 | sway_log(L_DEBUG, "@@ handled by bindcode? %d", handled); | ||
295 | 293 | ||
296 | // handle translated keysyms | 294 | // handle translated keysyms |
297 | const xkb_keysym_t *translated_keysyms; | 295 | const xkb_keysym_t *translated_keysyms; |
@@ -299,8 +297,8 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
299 | size_t translated_keysyms_len = | 297 | size_t translated_keysyms_len = |
300 | keyboard_keysyms_translated(keyboard, keycode, &translated_keysyms, | 298 | keyboard_keysyms_translated(keyboard, keycode, &translated_keysyms, |
301 | &translated_modifiers); | 299 | &translated_modifiers); |
302 | pressed_keysyms_update(keyboard->pressed_keysyms_translated, translated_keysyms, | 300 | pressed_keysyms_update(keyboard->pressed_keysyms_translated, |
303 | translated_keysyms_len, event->state); | 301 | translated_keysyms, translated_keysyms_len, event->state); |
304 | if (event->state == WLR_KEY_PRESSED && !handled) { | 302 | if (event->state == WLR_KEY_PRESSED && !handled) { |
305 | handled = keyboard_execute_bindsym(keyboard, | 303 | handled = keyboard_execute_bindsym(keyboard, |
306 | keyboard->pressed_keysyms_translated, translated_modifiers, | 304 | keyboard->pressed_keysyms_translated, translated_modifiers, |
@@ -310,9 +308,10 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
310 | // Handle raw keysyms | 308 | // Handle raw keysyms |
311 | const xkb_keysym_t *raw_keysyms; | 309 | const xkb_keysym_t *raw_keysyms; |
312 | uint32_t raw_modifiers; | 310 | uint32_t raw_modifiers; |
313 | size_t raw_keysyms_len = keyboard_keysyms_raw(keyboard, keycode, &raw_keysyms, &raw_modifiers); | 311 | size_t raw_keysyms_len = |
314 | pressed_keysyms_update(keyboard->pressed_keysyms_raw, raw_keysyms, raw_keysyms_len, | 312 | keyboard_keysyms_raw(keyboard, keycode, &raw_keysyms, &raw_modifiers); |
315 | event->state); | 313 | pressed_keysyms_update(keyboard->pressed_keysyms_raw, raw_keysyms, |
314 | raw_keysyms_len, event->state); | ||
316 | if (event->state == WLR_KEY_PRESSED && !handled) { | 315 | if (event->state == WLR_KEY_PRESSED && !handled) { |
317 | handled = keyboard_execute_bindsym(keyboard, | 316 | handled = keyboard_execute_bindsym(keyboard, |
318 | keyboard->pressed_keysyms_raw, raw_modifiers, | 317 | keyboard->pressed_keysyms_raw, raw_modifiers, |