aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/bar.c')
-rw-r--r--sway/commands/bar.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index d42b7fc2..22756acb 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -8,7 +8,7 @@
8#include "log.h" 8#include "log.h"
9 9
10// Must be in alphabetical order for bsearch 10// Must be in alphabetical order for bsearch
11static struct cmd_handler bar_handlers[] = { 11static const struct cmd_handler bar_handlers[] = {
12 { "bindcode", bar_cmd_bindcode }, 12 { "bindcode", bar_cmd_bindcode },
13 { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, 13 { "binding_mode_indicator", bar_cmd_binding_mode_indicator },
14 { "bindsym", bar_cmd_bindsym }, 14 { "bindsym", bar_cmd_bindsym },
@@ -41,7 +41,7 @@ static struct cmd_handler bar_handlers[] = {
41}; 41};
42 42
43// Must be in alphabetical order for bsearch 43// Must be in alphabetical order for bsearch
44static struct cmd_handler bar_config_handlers[] = { 44static const struct cmd_handler bar_config_handlers[] = {
45 { "id", bar_cmd_id }, 45 { "id", bar_cmd_id },
46 { "swaybar_command", bar_cmd_swaybar_command }, 46 { "swaybar_command", bar_cmd_swaybar_command },
47}; 47};
@@ -73,12 +73,10 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
73 } 73 }
74 ++argv; --argc; 74 ++argv; --argc;
75 } else if (config->reading && !config->current_bar) { 75 } else if (config->reading && !config->current_bar) {
76 int len = snprintf(NULL, 0, "bar-%d", config->bars->length) + 1; 76 id = format_str("bar-%d", config->bars->length);
77 id = malloc(len * sizeof(char));
78 if (!id) { 77 if (!id) {
79 return cmd_results_new(CMD_FAILURE, "Unable to allocate bar id"); 78 return cmd_results_new(CMD_FAILURE, "Unable to allocate bar id");
80 } 79 }
81 snprintf(id, len, "bar-%d", config->bars->length);
82 } else if (!config->reading && strcmp(argv[0], "mode") != 0 && 80 } else if (!config->reading && strcmp(argv[0], "mode") != 0 &&
83 strcmp(argv[0], "hidden_state") != 0) { 81 strcmp(argv[0], "hidden_state") != 0) {
84 if (is_subcommand(argv[0])) { 82 if (is_subcommand(argv[0])) {
@@ -116,6 +114,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
116 if (res && res->status != CMD_SUCCESS) { 114 if (res && res->status != CMD_SUCCESS) {
117 if (id) { 115 if (id) {
118 free_bar_config(config->current_bar); 116 free_bar_config(config->current_bar);
117 config->current_bar = NULL;
119 id = NULL; 118 id = NULL;
120 } 119 }
121 return res; 120 return res;