diff options
Diffstat (limited to 'sway/commands/bar/bindsym.c')
-rw-r--r-- | sway/commands/bar/bindsym.c | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/sway/commands/bar/bindsym.c b/sway/commands/bar/bindsym.c deleted file mode 100644 index e6d6220e..00000000 --- a/sway/commands/bar/bindsym.c +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "list.h" | ||
7 | #include "log.h" | ||
8 | #include "stringop.h" | ||
9 | |||
10 | struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | ||
11 | struct cmd_results *error = NULL; | ||
12 | if ((error = checkarg(argc, "bar bindsym", EXPECTED_AT_LEAST, 2))) { | ||
13 | return error; | ||
14 | } | ||
15 | if (!config->current_bar) { | ||
16 | return cmd_results_new(CMD_FAILURE, "bar bindsym", "No bar defined."); | ||
17 | } | ||
18 | |||
19 | struct bar_binding *binding = calloc(1, sizeof(struct bar_binding)); | ||
20 | if (!binding) { | ||
21 | return cmd_results_new(CMD_FAILURE, "bar bindsym", | ||
22 | "Unable to allocate bar binding"); | ||
23 | } | ||
24 | |||
25 | binding->release = false; | ||
26 | if (strcmp("--release", argv[0]) == 0) { | ||
27 | binding->release = true; | ||
28 | argv++; | ||
29 | argc--; | ||
30 | } | ||
31 | |||
32 | binding->button = 0; | ||
33 | if (strncasecmp(argv[0], "button", strlen("button")) == 0 && | ||
34 | strlen(argv[0]) == strlen("button0")) { | ||
35 | binding->button = argv[0][strlen("button")] - '0'; | ||
36 | } | ||
37 | if (binding->button < 1 || binding->button > 9) { | ||
38 | free_bar_binding(binding); | ||
39 | return cmd_results_new(CMD_FAILURE, "bar bindsym", | ||
40 | "Only button<1-9> is supported"); | ||
41 | } | ||
42 | |||
43 | binding->command = join_args(argv + 1, argc - 1); | ||
44 | |||
45 | list_t *bindings = config->current_bar->bindings; | ||
46 | bool overwritten = false; | ||
47 | for (int i = 0; i < bindings->length; i++) { | ||
48 | struct bar_binding *other = bindings->items[i]; | ||
49 | if (other->button == binding->button && | ||
50 | other->release == binding->release) { | ||
51 | overwritten = true; | ||
52 | bindings->items[i] = binding; | ||
53 | free_bar_binding(other); | ||
54 | wlr_log(WLR_DEBUG, "[bar %s] Updated binding for button%u%s", | ||
55 | config->current_bar->id, binding->button, | ||
56 | binding->release ? " (release)" : ""); | ||
57 | break; | ||
58 | } | ||
59 | } | ||
60 | if (!overwritten) { | ||
61 | list_add(bindings, binding); | ||
62 | wlr_log(WLR_DEBUG, "[bar %s] Added binding for button%u%s", | ||
63 | config->current_bar->id, binding->button, | ||
64 | binding->release ? " (release)" : ""); | ||
65 | } | ||
66 | |||
67 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
68 | } | ||