2018-11-25 22:12:48 +11:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-03-30 13:05:16 +11:00
|
|
|
#include <stdbool.h>
|
2018-03-30 08:20:03 +11:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *output = argv[0];
|
|
|
|
list_t *outputs = config->current_bar->outputs;
|
|
|
|
if (!outputs) {
|
|
|
|
outputs = create_list();
|
|
|
|
config->current_bar->outputs = outputs;
|
|
|
|
}
|
|
|
|
|
2018-03-30 13:05:16 +11:00
|
|
|
bool add_output = true;
|
2018-03-30 08:20:03 +11:00
|
|
|
if (strcmp("*", output) == 0) {
|
|
|
|
// remove all previous defined outputs and replace with '*'
|
2019-09-03 11:41:11 +10:00
|
|
|
while (outputs->length) {
|
|
|
|
free(outputs->items[0]);
|
|
|
|
list_del(outputs, 0);
|
2018-03-30 08:20:03 +11:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-03 11:41:11 +10:00
|
|
|
// only add output if not already defined, if the list has '*', remove
|
|
|
|
// it, in favor of a manual list
|
2018-03-30 13:05:16 +11:00
|
|
|
for (int i = 0; i < outputs->length; ++i) {
|
2018-03-30 08:20:03 +11:00
|
|
|
const char *find = outputs->items[i];
|
2019-09-03 11:41:11 +10:00
|
|
|
if (strcmp("*", find) == 0) {
|
|
|
|
free(outputs->items[i]);
|
|
|
|
list_del(outputs, i);
|
|
|
|
} else if (strcmp(output, find) == 0) {
|
2018-03-30 13:05:16 +11:00
|
|
|
add_output = false;
|
2018-03-30 08:20:03 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_output) {
|
|
|
|
list_add(outputs, strdup(output));
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Adding bar: '%s' to output '%s'",
|
2018-03-30 13:05:16 +11:00
|
|
|
config->current_bar->id, output);
|
2018-03-30 08:20:03 +11:00
|
|
|
}
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-03-30 08:20:03 +11:00
|
|
|
}
|