diff options
Diffstat (limited to 'sway/commands/bar.c')
-rw-r--r-- | sway/commands/bar.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 73be7040..9c7357dd 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -82,26 +82,30 @@ struct cmd_results *cmd_bar(int argc, char **argv) { | |||
82 | ++argv; --argc; | 82 | ++argv; --argc; |
83 | } | 83 | } |
84 | 84 | ||
85 | if (!config->current_bar && config->reading) { | 85 | if (!config->current_bar) { |
86 | // Create new bar with default values | 86 | if (config->reading) { |
87 | struct bar_config *bar = default_bar_config(); | 87 | // Create new bar with default values |
88 | if (!bar) { | 88 | struct bar_config *bar = default_bar_config(); |
89 | return cmd_results_new(CMD_FAILURE, | 89 | if (!bar) { |
90 | "Unable to allocate bar state"); | 90 | return cmd_results_new(CMD_FAILURE, |
91 | } | 91 | "Unable to allocate bar state"); |
92 | } | ||
93 | |||
94 | // set bar id | ||
95 | int len = snprintf(NULL, 0, "bar-%d", config->bars->length - 1) + 1; | ||
96 | bar->id = malloc(len * sizeof(char)); | ||
97 | if (bar->id) { | ||
98 | snprintf(bar->id, len, "bar-%d", config->bars->length - 1); | ||
99 | } else { | ||
100 | return cmd_results_new(CMD_FAILURE, "Unable to allocate bar ID"); | ||
101 | } | ||
92 | 102 | ||
93 | // set bar id | 103 | // Set current bar |
94 | const int len = snprintf(NULL, 0, "bar-%d", config->bars->length - 1) + 1; | 104 | config->current_bar = bar; |
95 | bar->id = malloc(len * sizeof(char)); | 105 | sway_log(SWAY_DEBUG, "Creating bar %s", bar->id); |
96 | if (bar->id) { | ||
97 | snprintf(bar->id, len, "bar-%d", config->bars->length - 1); | ||
98 | } else { | 106 | } else { |
99 | return cmd_results_new(CMD_FAILURE, "Unable to allocate bar ID"); | 107 | return cmd_results_new(CMD_FAILURE, "No bar defined."); |
100 | } | 108 | } |
101 | |||
102 | // Set current bar | ||
103 | config->current_bar = bar; | ||
104 | sway_log(SWAY_DEBUG, "Creating bar %s", bar->id); | ||
105 | } | 109 | } |
106 | 110 | ||
107 | if (find_handler(argv[0], bar_config_handlers, | 111 | if (find_handler(argv[0], bar_config_handlers, |