diff options
Diffstat (limited to 'sway/commands/bar/id.c')
-rw-r--r-- | sway/commands/bar/id.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c new file mode 100644 index 00000000..d62a0961 --- /dev/null +++ b/sway/commands/bar/id.c | |||
@@ -0,0 +1,32 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_id(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | const char *name = argv[0]; | ||
12 | const char *oldname = config->current_bar->id; | ||
13 | |||
14 | // check if id is used by a previously defined bar | ||
15 | int i; | ||
16 | for (i = 0; i < config->bars->length; ++i) { | ||
17 | struct bar_config *find = config->bars->items[i]; | ||
18 | if (strcmp(name, find->id) == 0 && config->current_bar != find) { | ||
19 | return cmd_results_new(CMD_FAILURE, "id", | ||
20 | "Id '%s' already defined for another bar. Id unchanged (%s).", | ||
21 | name, oldname); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | sway_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); | ||
26 | |||
27 | // free old bar id | ||
28 | free(config->current_bar->id); | ||
29 | |||
30 | config->current_bar->id = strdup(name); | ||
31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
32 | } | ||