aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/bar/output.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-30 00:11:00 -0400
committerGitHub <noreply@github.com>2018-03-30 00:11:00 -0400
commit9d7f47746cdcb0eed3cf41875d06a8ef238eef1c (patch)
tree997658454de40db3f8b76b68d658efaf2b686188 /sway/commands/bar/output.c
parent7162b9bea4d66d61376ad3605e23e2d83bb95201 (diff)
parentf26ecd9f58bb672fe107660ce9b37f4bf0777a8c (diff)
Merge pull request #1648 from swaywm/swaybar-layers
Port swaybar to layer shell
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 @@
+#define _XOPEN_SOURCE 500
+#include <stdbool.h>
+#include <string.h>
+#include "sway/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;
+ }
+
+ bool add_output = true;
+ if (strcmp("*", output) == 0) {
+ // remove all previous defined outputs and replace with '*'
+ for (int 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 (int i = 0; i < outputs->length; ++i) {
+ const char *find = outputs->items[i];
+ if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
+ add_output = false;
+ break;
+ }
+ }
+ }
+
+ if (add_output) {
+ list_add(outputs, strdup(output));
+ wlr_log(L_DEBUG, "Adding bar: '%s' to output '%s'",
+ config->current_bar->id, output);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}