aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2015-12-15 21:55:20 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2015-12-15 22:01:53 +0100
commitf59f5d27aab52c877cd58a9d14e0cfc56b6febe9 (patch)
treed7e1f307c06f09eb1fb80151e63b5b3f492129c4 /sway
parentMerge pull request #329 from mikkeloscar/fix-bar-colors (diff)
downloadsway-f59f5d27aab52c877cd58a9d14e0cfc56b6febe9.tar.gz
sway-f59f5d27aab52c877cd58a9d14e0cfc56b6febe9.tar.zst
sway-f59f5d27aab52c877cd58a9d14e0cfc56b6febe9.zip
Implement bar option: output <output>
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c44
-rw-r--r--sway/config.c6
2 files changed, 49 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 },
diff --git a/sway/config.c b/sway/config.c
index 51dbe843..d4d3b0c8 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -48,6 +48,11 @@ static void free_bar(struct bar_config *bar) {
48 free_sway_mouse_binding(bar->bindings->items[i]); 48 free_sway_mouse_binding(bar->bindings->items[i]);
49 } 49 }
50 free(bar->bindings); 50 free(bar->bindings);
51
52 for (i = 0; i < bar->outputs->length; ++i) {
53 free(bar->outputs->items[i]);
54 }
55 list_free(bar->outputs);
51 free(bar); 56 free(bar);
52} 57}
53 58
@@ -558,6 +563,7 @@ struct bar_config *default_bar_config(void) {
558 bar->mode = strdup("dock"); 563 bar->mode = strdup("dock");
559 bar->hidden_state = strdup("hide"); 564 bar->hidden_state = strdup("hide");
560 bar->modifier = 0; 565 bar->modifier = 0;
566 bar->outputs = create_list();
561 bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; 567 bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
562 bar->bindings = create_list(); 568 bar->bindings = create_list();
563 bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); 569 bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done");