summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 23e6e68c..d05a9069 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -69,6 +69,7 @@ static sway_cmd bar_cmd_bindsym;
69static sway_cmd bar_cmd_colors; 69static sway_cmd bar_cmd_colors;
70static sway_cmd bar_cmd_mode; 70static sway_cmd bar_cmd_mode;
71static sway_cmd bar_cmd_modifier; 71static sway_cmd bar_cmd_modifier;
72static sway_cmd bar_cmd_output;
72static sway_cmd bar_cmd_height; 73static sway_cmd bar_cmd_height;
73static sway_cmd bar_cmd_hidden_state; 74static sway_cmd bar_cmd_hidden_state;
74static sway_cmd bar_cmd_id; 75static sway_cmd bar_cmd_id;
@@ -1724,6 +1725,47 @@ static struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
1724 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1725 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1725} 1726}
1726 1727
1728static struct cmd_results *bar_cmd_output(int argc, char **argv) {
1729 struct cmd_results *error = NULL;
1730 if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
1731 return error;
1732 }
1733
1734 if (!config->current_bar) {
1735 return cmd_results_new(CMD_FAILURE, "output", "No bar defined.");
1736 }
1737
1738 const char *output = argv[0];
1739 list_t *outputs = config->current_bar->outputs;
1740
1741 int i;
1742 int add_output = 1;
1743 if (strcmp("*", output) == 0) {
1744 // remove all previous defined outputs and replace with '*'
1745 for (i = 0; i < outputs->length; ++i) {
1746 free(outputs->items[i]);
1747 list_del(outputs, i);
1748 }
1749 } else {
1750 // only add output if not already defined with either the same
1751 // name or as '*'
1752 for (i = 0; i < outputs->length; ++i) {
1753 const char *find = outputs->items[i];
1754 if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
1755 add_output = 0;
1756 break;
1757 }
1758 }
1759 }
1760
1761 if (add_output) {
1762 list_add(outputs, strdup(output));
1763 sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
1764 }
1765
1766 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1767}
1768
1727static struct cmd_results *bar_cmd_position(int argc, char **argv) { 1769static struct cmd_results *bar_cmd_position(int argc, char **argv) {
1728 struct cmd_results *error = NULL; 1770 struct cmd_results *error = NULL;
1729 if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { 1771 if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) {
@@ -1854,7 +1896,7 @@ static struct cmd_handler bar_handlers[] = {
1854 { "id", bar_cmd_id }, 1896 { "id", bar_cmd_id },
1855 { "mode", bar_cmd_mode }, 1897 { "mode", bar_cmd_mode },
1856 { "modifier", bar_cmd_modifier }, 1898 { "modifier", bar_cmd_modifier },
1857 { "output", NULL }, 1899 { "output", bar_cmd_output },
1858 { "position", bar_cmd_position }, 1900 { "position", bar_cmd_position },
1859 { "seperator_symbol", NULL }, 1901 { "seperator_symbol", NULL },
1860 { "status_command", bar_cmd_status_command }, 1902 { "status_command", bar_cmd_status_command },