From b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Thu, 1 Sep 2016 21:39:08 -0500 Subject: refactor commands.c --- sway/commands/bar/output.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 sway/commands/bar/output.c (limited to 'sway/commands/bar/output.c') diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c new file mode 100644 index 00000000..9a0d7a73 --- /dev/null +++ b/sway/commands/bar/output.c @@ -0,0 +1,49 @@ +#include +#include "commands.h" +#include "list.h" +#include "log.h" + +struct cmd_results *bar_cmd_output(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (!config->current_bar) { + return cmd_results_new(CMD_FAILURE, "output", "No bar defined."); + } + + const char *output = argv[0]; + list_t *outputs = config->current_bar->outputs; + if (!outputs) { + outputs = create_list(); + config->current_bar->outputs = outputs; + } + + int i; + int add_output = 1; + if (strcmp("*", output) == 0) { + // remove all previous defined outputs and replace with '*' + for (i = 0; i < outputs->length; ++i) { + free(outputs->items[i]); + list_del(outputs, i); + } + } else { + // only add output if not already defined with either the same + // name or as '*' + for (i = 0; i < outputs->length; ++i) { + const char *find = outputs->items[i]; + if (strcmp("*", find) == 0 || strcmp(output, find) == 0) { + add_output = 0; + break; + } + } + } + + if (add_output) { + list_add(outputs, strdup(output)); + sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} -- cgit v1.2.3 From 65ace5dec5c24695501056376e227fb9b1f84a3a Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Fri, 2 Sep 2016 14:11:48 -0500 Subject: merge in latest commits --- sway/commands/bar/output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/commands/bar/output.c') diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c index 9a0d7a73..01a23d9c 100644 --- a/sway/commands/bar/output.c +++ b/sway/commands/bar/output.c @@ -1,5 +1,5 @@ #include -#include "commands.h" +#include "sway/commands.h" #include "list.h" #include "log.h" -- cgit v1.2.3