diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-12-15 16:14:28 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-12-15 16:14:28 -0500 |
commit | 614034b0012dcf99d760eaa9951c537acb75ea43 (patch) | |
tree | d7e1f307c06f09eb1fb80151e63b5b3f492129c4 | |
parent | Merge pull request #329 from mikkeloscar/fix-bar-colors (diff) | |
parent | Implement bar option: output <output> (diff) | |
download | sway-614034b0012dcf99d760eaa9951c537acb75ea43.tar.gz sway-614034b0012dcf99d760eaa9951c537acb75ea43.tar.zst sway-614034b0012dcf99d760eaa9951c537acb75ea43.zip |
Merge pull request #332 from mikkeloscar/bar-output
Implement bar option: output <output>
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 44 | ||||
-rw-r--r-- | sway/config.c | 6 |
3 files changed, 50 insertions, 1 deletions
diff --git a/include/config.h b/include/config.h index 2f3b4cb0..ab937e0e 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -88,6 +88,7 @@ struct bar_config { | |||
88 | */ | 88 | */ |
89 | char *id; | 89 | char *id; |
90 | uint32_t modifier; | 90 | uint32_t modifier; |
91 | list_t *outputs; | ||
91 | enum desktop_shell_panel_position position; | 92 | enum desktop_shell_panel_position position; |
92 | list_t *bindings; | 93 | list_t *bindings; |
93 | char *status_command; | 94 | char *status_command; |
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; | |||
69 | static sway_cmd bar_cmd_colors; | 69 | static sway_cmd bar_cmd_colors; |
70 | static sway_cmd bar_cmd_mode; | 70 | static sway_cmd bar_cmd_mode; |
71 | static sway_cmd bar_cmd_modifier; | 71 | static sway_cmd bar_cmd_modifier; |
72 | static sway_cmd bar_cmd_output; | ||
72 | static sway_cmd bar_cmd_height; | 73 | static sway_cmd bar_cmd_height; |
73 | static sway_cmd bar_cmd_hidden_state; | 74 | static sway_cmd bar_cmd_hidden_state; |
74 | static sway_cmd bar_cmd_id; | 75 | static 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 | ||
1728 | static 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 | |||
1727 | static struct cmd_results *bar_cmd_position(int argc, char **argv) { | 1769 | static 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"); |