summaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/output.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/bar/output.c')
-rw-r--r--sway/commands/bar/output.c49
1 files changed, 49 insertions, 0 deletions
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 @@
1#include <string.h>
2#include "commands.h"
3#include "list.h"
4#include "log.h"
5
6struct cmd_results *bar_cmd_output(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
9 return error;
10 }
11
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "output", "No bar defined.");
14 }
15
16 const char *output = argv[0];
17 list_t *outputs = config->current_bar->outputs;
18 if (!outputs) {
19 outputs = create_list();
20 config->current_bar->outputs = outputs;
21 }
22
23 int i;
24 int add_output = 1;
25 if (strcmp("*", output) == 0) {
26 // remove all previous defined outputs and replace with '*'
27 for (i = 0; i < outputs->length; ++i) {
28 free(outputs->items[i]);
29 list_del(outputs, i);
30 }
31 } else {
32 // only add output if not already defined with either the same
33 // name or as '*'
34 for (i = 0; i < outputs->length; ++i) {
35 const char *find = outputs->items[i];
36 if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
37 add_output = 0;
38 break;
39 }
40 }
41 }
42
43 if (add_output) {
44 list_add(outputs, strdup(output));
45 sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
46 }
47
48 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
49}