diff options
-rw-r--r-- | sway/commands/bar.c | 19 | ||||
-rw-r--r-- | sway/commands/bar/id.c | 2 |
2 files changed, 19 insertions, 2 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 49a94104..8d118fb6 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -38,6 +38,12 @@ static struct cmd_handler bar_config_handlers[] = { | |||
38 | { "swaybar_command", bar_cmd_swaybar_command }, | 38 | { "swaybar_command", bar_cmd_swaybar_command }, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | // Determines whether the subcommand is valid in any bar handler struct | ||
42 | static bool is_subcommand(char *name) { | ||
43 | return find_handler(name, bar_handlers, sizeof(bar_handlers)) || | ||
44 | find_handler(name, bar_config_handlers, sizeof(bar_config_handlers)); | ||
45 | } | ||
46 | |||
41 | struct cmd_results *cmd_bar(int argc, char **argv) { | 47 | struct cmd_results *cmd_bar(int argc, char **argv) { |
42 | struct cmd_results *error = NULL; | 48 | struct cmd_results *error = NULL; |
43 | if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { | 49 | if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { |
@@ -47,8 +53,8 @@ struct cmd_results *cmd_bar(int argc, char **argv) { | |||
47 | bool spawn = false; | 53 | bool spawn = false; |
48 | if (argc > 1) { | 54 | if (argc > 1) { |
49 | struct bar_config *bar = NULL; | 55 | struct bar_config *bar = NULL; |
50 | if (!find_handler(argv[0], bar_handlers, sizeof(bar_handlers)) | 56 | if (!is_subcommand(argv[0]) || |
51 | && find_handler(argv[1], bar_handlers, sizeof(bar_handlers))) { | 57 | (strcmp(argv[0], "id") != 0 && is_subcommand(argv[1]))) { |
52 | for (int i = 0; i < config->bars->length; ++i) { | 58 | for (int i = 0; i < config->bars->length; ++i) { |
53 | struct bar_config *item = config->bars->items[i]; | 59 | struct bar_config *item = config->bars->items[i]; |
54 | if (strcmp(item->id, argv[0]) == 0) { | 60 | if (strcmp(item->id, argv[0]) == 0) { |
@@ -106,6 +112,15 @@ struct cmd_results *cmd_bar(int argc, char **argv) { | |||
106 | if (config->reading) { | 112 | if (config->reading) { |
107 | return config_subcommand(argv, argc, bar_config_handlers, | 113 | return config_subcommand(argv, argc, bar_config_handlers, |
108 | sizeof(bar_config_handlers)); | 114 | sizeof(bar_config_handlers)); |
115 | } else if (spawn) { | ||
116 | for (int i = config->bars->length - 1; i >= 0; i--) { | ||
117 | struct bar_config *bar = config->bars->items[i]; | ||
118 | if (bar == config->current_bar) { | ||
119 | list_del(config->bars, i); | ||
120 | free_bar_config(bar); | ||
121 | break; | ||
122 | } | ||
123 | } | ||
109 | } | 124 | } |
110 | return cmd_results_new(CMD_INVALID, "bar", | 125 | return cmd_results_new(CMD_INVALID, "bar", |
111 | "Can only be used in the config file."); | 126 | "Can only be used in the config file."); |
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c index 65fa69fd..7690a852 100644 --- a/sway/commands/bar/id.c +++ b/sway/commands/bar/id.c | |||
@@ -13,6 +13,8 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) { | |||
13 | const char *oldname = config->current_bar->id; | 13 | const char *oldname = config->current_bar->id; |
14 | if (strcmp(name, oldname) == 0) { | 14 | if (strcmp(name, oldname) == 0) { |
15 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); // NOP | 15 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); // NOP |
16 | } else if (strcmp(name, "id") == 0) { | ||
17 | return cmd_results_new(CMD_INVALID, "id", "id cannot be 'id'"); | ||
16 | } | 18 | } |
17 | // check if id is used by a previously defined bar | 19 | // check if id is used by a previously defined bar |
18 | for (int i = 0; i < config->bars->length; ++i) { | 20 | for (int i = 0; i < config->bars->length; ++i) { |