commands: fix sending bar mode/hidden_state updates to all bars

Previously, if a change was sent to all bars, it would only actually
change the first bar it encountered, due to return value handling
This commit is contained in:
Ian Fan 2018-09-30 23:06:40 +01:00
parent abde9d6627
commit 1f90f92f45
2 changed files with 30 additions and 38 deletions

View file

@ -32,7 +32,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar,
} }
// free old mode // free old mode
free(old_state); free(old_state);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return NULL;
} }
struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
@ -50,24 +50,20 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
const char *state = argv[0]; const char *state = argv[0];
if (config->reading) { if (config->reading) {
return bar_set_hidden_state(config->current_bar, state); error = bar_set_hidden_state(config->current_bar, state);
} } else {
const char *id = argc == 2 ? argv[1] : NULL;
const char *id = NULL; for (int i = 0; i < config->bars->length; ++i) {
if (argc == 2) { struct bar_config *bar = config->bars->items[i];
id = argv[1]; if (id) {
} if (strcmp(id, bar->id) == 0) {
struct bar_config *bar; error = bar_set_hidden_state(bar, state);
for (int i = 0; i < config->bars->length; ++i) { break;
bar = config->bars->items[i]; }
if (id && strcmp(id, bar->id) == 0) { } else if ((error = bar_set_hidden_state(bar, state))) {
return bar_set_hidden_state(bar, state); break;
} }
error = bar_set_hidden_state(bar, state);
if (error) {
return error;
} }
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -33,7 +33,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode
// free old mode // free old mode
free(old_mode); free(old_mode);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return NULL;
} }
struct cmd_results *bar_cmd_mode(int argc, char **argv) { struct cmd_results *bar_cmd_mode(int argc, char **argv) {
@ -51,24 +51,20 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
const char *mode = argv[0]; const char *mode = argv[0];
if (config->reading) { if (config->reading) {
return bar_set_mode(config->current_bar, mode); error = bar_set_mode(config->current_bar, mode);
} } else {
const char *id = argc == 2 ? argv[1] : NULL;
const char *id = NULL; for (int i = 0; i < config->bars->length; ++i) {
if (argc == 2) { struct bar_config *bar = config->bars->items[i];
id = argv[1]; if (id) {
} if (strcmp(id, bar->id) == 0) {
error = bar_set_mode(bar, mode);
struct bar_config *bar; break;
for (int i = 0; i < config->bars->length; ++i) { }
bar = config->bars->items[i]; } else if ((error = bar_set_mode(bar, mode))) {
if (id && strcmp(id, bar->id) == 0) { break;
return bar_set_mode(bar, mode); }
}
error = bar_set_mode(bar, mode);
if (error) {
return error;
} }
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }