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.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index d42b7fc2..635e895b 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809
2#include <stdio.h> 1#include <stdio.h>
3#include <string.h> 2#include <string.h>
4#include <strings.h> 3#include <strings.h>
@@ -8,7 +7,7 @@
8#include "log.h" 7#include "log.h"
9 8
10// Must be in alphabetical order for bsearch 9// Must be in alphabetical order for bsearch
11static struct cmd_handler bar_handlers[] = { 10static const struct cmd_handler bar_handlers[] = {
12 { "bindcode", bar_cmd_bindcode }, 11 { "bindcode", bar_cmd_bindcode },
13 { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, 12 { "binding_mode_indicator", bar_cmd_binding_mode_indicator },
14 { "bindsym", bar_cmd_bindsym }, 13 { "bindsym", bar_cmd_bindsym },
@@ -41,7 +40,7 @@ static struct cmd_handler bar_handlers[] = {
41}; 40};
42 41
43// Must be in alphabetical order for bsearch 42// Must be in alphabetical order for bsearch
44static struct cmd_handler bar_config_handlers[] = { 43static const struct cmd_handler bar_config_handlers[] = {
45 { "id", bar_cmd_id }, 44 { "id", bar_cmd_id },
46 { "swaybar_command", bar_cmd_swaybar_command }, 45 { "swaybar_command", bar_cmd_swaybar_command },
47}; 46};
@@ -73,12 +72,10 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
73 } 72 }
74 ++argv; --argc; 73 ++argv; --argc;
75 } else if (config->reading && !config->current_bar) { 74 } else if (config->reading && !config->current_bar) {
76 int len = snprintf(NULL, 0, "bar-%d", config->bars->length) + 1; 75 id = format_str("bar-%d", config->bars->length);
77 id = malloc(len * sizeof(char));
78 if (!id) { 76 if (!id) {
79 return cmd_results_new(CMD_FAILURE, "Unable to allocate bar id"); 77 return cmd_results_new(CMD_FAILURE, "Unable to allocate bar id");
80 } 78 }
81 snprintf(id, len, "bar-%d", config->bars->length);
82 } else if (!config->reading && strcmp(argv[0], "mode") != 0 && 79 } else if (!config->reading && strcmp(argv[0], "mode") != 0 &&
83 strcmp(argv[0], "hidden_state") != 0) { 80 strcmp(argv[0], "hidden_state") != 0) {
84 if (is_subcommand(argv[0])) { 81 if (is_subcommand(argv[0])) {
@@ -116,6 +113,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
116 if (res && res->status != CMD_SUCCESS) { 113 if (res && res->status != CMD_SUCCESS) {
117 if (id) { 114 if (id) {
118 free_bar_config(config->current_bar); 115 free_bar_config(config->current_bar);
116 config->current_bar = NULL;
119 id = NULL; 117 id = NULL;
120 } 118 }
121 return res; 119 return res;