aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/bar/mode.c
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-09-30 23:06:40 +0100
committerIan Fan <ianfan0@gmail.com>2018-10-14 13:33:12 +0100
commit1f90f92f45580adfbe4ce363181331c182f3f341 (patch)
tree9db916dca5ca91a63e10316a68e6296b4c7ef0f1 /sway/commands/bar/mode.c
parentabde9d6627483256ccfd20bdeeaa52d7790b0426 (diff)
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
Diffstat (limited to 'sway/commands/bar/mode.c')
-rw-r--r--sway/commands/bar/mode.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c
index 28e2d77b..dbdd3897 100644
--- a/sway/commands/bar/mode.c
+++ b/sway/commands/bar/mode.c
@@ -33,7 +33,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *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) {
@@ -51,24 +51,20 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
const char *mode = argv[0];
if (config->reading) {
- return bar_set_mode(config->current_bar, mode);
- }
-
- const char *id = NULL;
- if (argc == 2) {
- id = argv[1];
- }
-
- struct bar_config *bar;
- for (int i = 0; i < config->bars->length; ++i) {
- bar = config->bars->items[i];
- if (id && strcmp(id, bar->id) == 0) {
- return bar_set_mode(bar, mode);
- }
- error = bar_set_mode(bar, mode);
- if (error) {
- return error;
+ error = bar_set_mode(config->current_bar, mode);
+ } else {
+ const char *id = argc == 2 ? argv[1] : NULL;
+ for (int i = 0; i < config->bars->length; ++i) {
+ struct bar_config *bar = config->bars->items[i];
+ if (id) {
+ if (strcmp(id, bar->id) == 0) {
+ error = bar_set_mode(bar, mode);
+ break;
+ }
+ } else if ((error = bar_set_mode(bar, mode))) {
+ break;
+ }
}
}
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}