diff options
Diffstat (limited to 'sway/commands/bind.c')
-rw-r--r-- | sway/commands/bind.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 133fd089..8270b958 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
1 | #ifdef __linux__ | 2 | #ifdef __linux__ |
2 | #include <linux/input-event-codes.h> | 3 | #include <linux/input-event-codes.h> |
3 | #elif __FreeBSD__ | 4 | #elif __FreeBSD__ |
@@ -5,9 +6,11 @@ | |||
5 | #endif | 6 | #endif |
6 | #include <xkbcommon/xkbcommon.h> | 7 | #include <xkbcommon/xkbcommon.h> |
7 | #include <xkbcommon/xkbcommon-names.h> | 8 | #include <xkbcommon/xkbcommon-names.h> |
9 | #include <string.h> | ||
8 | #include <strings.h> | 10 | #include <strings.h> |
9 | #include "sway/commands.h" | 11 | #include "sway/commands.h" |
10 | #include "sway/config.h" | 12 | #include "sway/config.h" |
13 | #include "sway/ipc-server.h" | ||
11 | #include "list.h" | 14 | #include "list.h" |
12 | #include "log.h" | 15 | #include "log.h" |
13 | #include "stringop.h" | 16 | #include "stringop.h" |
@@ -27,6 +30,33 @@ void free_sway_binding(struct sway_binding *binding) { | |||
27 | free(binding); | 30 | free(binding); |
28 | } | 31 | } |
29 | 32 | ||
33 | static struct sway_binding *sway_binding_dup(struct sway_binding *sb) { | ||
34 | struct sway_binding *new_sb = calloc(1, sizeof(struct sway_binding)); | ||
35 | if (!new_sb) { | ||
36 | return NULL; | ||
37 | } | ||
38 | |||
39 | new_sb->type = sb->type; | ||
40 | new_sb->order = sb->order; | ||
41 | new_sb->flags = sb->flags; | ||
42 | new_sb->modifiers = sb->modifiers; | ||
43 | new_sb->command = strdup(sb->command); | ||
44 | |||
45 | new_sb->keys = create_list(); | ||
46 | int i; | ||
47 | for (i = 0; i < sb->keys->length; ++i) { | ||
48 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); | ||
49 | if (!key) { | ||
50 | free_sway_binding(new_sb); | ||
51 | return NULL; | ||
52 | } | ||
53 | *key = *(xkb_keysym_t *)sb->keys->items[i]; | ||
54 | list_add(new_sb->keys, key); | ||
55 | } | ||
56 | |||
57 | return new_sb; | ||
58 | } | ||
59 | |||
30 | /** | 60 | /** |
31 | * Returns true if the bindings have the same key and modifier combinations. | 61 | * Returns true if the bindings have the same key and modifier combinations. |
32 | * Note that keyboard layout is not considered, so the bindings might actually | 62 | * Note that keyboard layout is not considered, so the bindings might actually |
@@ -275,11 +305,31 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { | |||
275 | void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) { | 305 | void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) { |
276 | wlr_log(WLR_DEBUG, "running command for binding: %s", | 306 | wlr_log(WLR_DEBUG, "running command for binding: %s", |
277 | binding->command); | 307 | binding->command); |
308 | |||
309 | struct sway_binding *binding_copy = binding; | ||
310 | bool reload = false; | ||
311 | // if this is a reload command we need to make a duplicate of the | ||
312 | // binding since it will be gone after the reload has completed. | ||
313 | if (strcasecmp(binding->command, "reload") == 0) { | ||
314 | reload = true; | ||
315 | binding_copy = sway_binding_dup(binding); | ||
316 | if (!binding_copy) { | ||
317 | wlr_log(WLR_ERROR, "Failed to duplicate binding during reload"); | ||
318 | return; | ||
319 | } | ||
320 | } | ||
321 | |||
278 | config->handler_context.seat = seat; | 322 | config->handler_context.seat = seat; |
279 | struct cmd_results *results = execute_command(binding->command, NULL); | 323 | struct cmd_results *results = execute_command(binding->command, NULL); |
280 | if (results->status != CMD_SUCCESS) { | 324 | if (results->status == CMD_SUCCESS) { |
325 | ipc_event_binding(binding_copy); | ||
326 | } else { | ||
281 | wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)", | 327 | wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)", |
282 | binding->command, results->error); | 328 | binding->command, results->error); |
283 | } | 329 | } |
330 | |||
331 | if (reload) { // free the binding if we made a copy | ||
332 | free_sway_binding(binding_copy); | ||
333 | } | ||
284 | free_cmd_results(results); | 334 | free_cmd_results(results); |
285 | } | 335 | } |