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.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..f7ca0aa4
--- /dev/null
+++ b/sway/commands/bar/output.c
@@ -0,0 +1,49 @@
1#define _XOPEN_SOURCE 500
2#include <stdbool.h>
3#include <string.h>
4#include "sway/commands.h"
5#include "list.h"
6#include "log.h"
7
8struct cmd_results *bar_cmd_output(int argc, char **argv) {
9 struct cmd_results *error = NULL;
10 if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
11 return error;
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 bool add_output = true;
25 if (strcmp("*", output) == 0) {
26 // remove all previous defined outputs and replace with '*'
27 for (int 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 (int 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 = false;
38 break;
39 }
40 }
41 }
42
43 if (add_output) {
44 list_add(outputs, strdup(output));
45 wlr_log(L_DEBUG, "Adding bar: '%s' to output '%s'",
46 config->current_bar->id, output);
47 }
48 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
49}