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