diff options
author | 2015-12-15 13:12:08 +0100 | |
---|---|---|
committer | 2015-12-15 13:12:55 +0100 | |
commit | 8c1d56812bea35b4543898ef3df82b2d35355be1 (patch) | |
tree | e56ebb3d5a9d36793f32d575af0648fc382ad81e /sway | |
parent | Merge pull request #326 from mikkeloscar/remove-spaces (diff) | |
download | sway-8c1d56812bea35b4543898ef3df82b2d35355be1.tar.gz sway-8c1d56812bea35b4543898ef3df82b2d35355be1.tar.zst sway-8c1d56812bea35b4543898ef3df82b2d35355be1.zip |
Implement bar option: colors {}
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 214 | ||||
-rw-r--r-- | sway/config.c | 33 |
2 files changed, 246 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c index 559d1e06..d2b53783 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -66,6 +66,7 @@ static sway_cmd cmd_workspace; | |||
66 | static sway_cmd cmd_ws_auto_back_and_forth; | 66 | static sway_cmd cmd_ws_auto_back_and_forth; |
67 | 67 | ||
68 | static sway_cmd bar_cmd_bindsym; | 68 | static sway_cmd bar_cmd_bindsym; |
69 | static sway_cmd bar_cmd_colors; | ||
69 | static sway_cmd bar_cmd_mode; | 70 | static sway_cmd bar_cmd_mode; |
70 | static sway_cmd bar_cmd_modifier; | 71 | static sway_cmd bar_cmd_modifier; |
71 | static sway_cmd bar_cmd_hidden_state; | 72 | static sway_cmd bar_cmd_hidden_state; |
@@ -77,6 +78,16 @@ static sway_cmd bar_cmd_tray_output; | |||
77 | static sway_cmd bar_cmd_tray_padding; | 78 | static sway_cmd bar_cmd_tray_padding; |
78 | static sway_cmd bar_cmd_workspace_buttons; | 79 | static sway_cmd bar_cmd_workspace_buttons; |
79 | 80 | ||
81 | static sway_cmd bar_colors_cmd_active_workspace; | ||
82 | static sway_cmd bar_colors_cmd_background; | ||
83 | static sway_cmd bar_colors_cmd_background; | ||
84 | static sway_cmd bar_colors_cmd_binding_mode; | ||
85 | static sway_cmd bar_colors_cmd_focused_workspace; | ||
86 | static sway_cmd bar_colors_cmd_inactive_workspace; | ||
87 | static sway_cmd bar_colors_cmd_separator; | ||
88 | static sway_cmd bar_colors_cmd_statusline; | ||
89 | static sway_cmd bar_colors_cmd_urgent_workspace; | ||
90 | |||
80 | swayc_t *sp_view; | 91 | swayc_t *sp_view; |
81 | int sp_index = 0; | 92 | int sp_index = 0; |
82 | 93 | ||
@@ -1567,6 +1578,20 @@ static struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | |||
1567 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 1578 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
1568 | } | 1579 | } |
1569 | 1580 | ||
1581 | static struct cmd_results *bar_cmd_colors(int argc, char **argv) { | ||
1582 | struct cmd_results *error = NULL; | ||
1583 | if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) { | ||
1584 | return error; | ||
1585 | } | ||
1586 | |||
1587 | if (strcmp("{", argv[0]) != 0) { | ||
1588 | return cmd_results_new(CMD_INVALID, "colors", | ||
1589 | "Expected '{' at the start of colors config definition."); | ||
1590 | } | ||
1591 | |||
1592 | return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL); | ||
1593 | } | ||
1594 | |||
1570 | static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | 1595 | static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { |
1571 | struct cmd_results *error = NULL; | 1596 | struct cmd_results *error = NULL; |
1572 | if ((error = checkarg(argc, "hidden_state", EXPECTED_EQUAL_TO, 1))) { | 1597 | if ((error = checkarg(argc, "hidden_state", EXPECTED_EQUAL_TO, 1))) { |
@@ -1804,7 +1829,7 @@ static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { | |||
1804 | static struct cmd_handler bar_handlers[] = { | 1829 | static struct cmd_handler bar_handlers[] = { |
1805 | { "binding_mode_indicator", NULL }, | 1830 | { "binding_mode_indicator", NULL }, |
1806 | { "bindsym", bar_cmd_bindsym }, | 1831 | { "bindsym", bar_cmd_bindsym }, |
1807 | { "colors", NULL }, | 1832 | { "colors", bar_cmd_colors }, |
1808 | { "font", NULL }, | 1833 | { "font", NULL }, |
1809 | { "hidden_state", bar_cmd_hidden_state }, | 1834 | { "hidden_state", bar_cmd_hidden_state }, |
1810 | { "id", bar_cmd_id }, | 1835 | { "id", bar_cmd_id }, |
@@ -1820,6 +1845,189 @@ static struct cmd_handler bar_handlers[] = { | |||
1820 | { "workspace_buttons", bar_cmd_workspace_buttons }, | 1845 | { "workspace_buttons", bar_cmd_workspace_buttons }, |
1821 | }; | 1846 | }; |
1822 | 1847 | ||
1848 | /** | ||
1849 | * Check and add color to buffer. | ||
1850 | * | ||
1851 | * return error object, or NULL if color is valid. | ||
1852 | */ | ||
1853 | static struct cmd_results *add_color(const char *name, char *buffer, const char *color) { | ||
1854 | if (strlen(color) != 7) { | ||
1855 | return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); | ||
1856 | } | ||
1857 | |||
1858 | if (color[0] != '#') { | ||
1859 | return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); | ||
1860 | } | ||
1861 | |||
1862 | int i; | ||
1863 | for (i = 1; i < 7; ++i) { | ||
1864 | if (!isxdigit(color[i])) { | ||
1865 | return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); | ||
1866 | } | ||
1867 | } | ||
1868 | |||
1869 | // copy color to buffer | ||
1870 | strncpy(buffer, color, 7); | ||
1871 | sway_log(L_DEBUG, "Setting %s color %s for bar: %s", name, color, config->current_bar->id); | ||
1872 | |||
1873 | return NULL; | ||
1874 | } | ||
1875 | |||
1876 | static struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) { | ||
1877 | struct cmd_results *error = NULL; | ||
1878 | if ((error = checkarg(argc, "active_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
1879 | return error; | ||
1880 | } | ||
1881 | |||
1882 | if ((error = add_color("active_workspace_border", config->current_bar->colors.active_workspace_border, argv[0]))) { | ||
1883 | return error; | ||
1884 | } | ||
1885 | |||
1886 | if ((error = add_color("active_workspace_bg", config->current_bar->colors.active_workspace_bg, argv[1]))) { | ||
1887 | return error; | ||
1888 | } | ||
1889 | |||
1890 | if ((error = add_color("active_workspace_text", config->current_bar->colors.active_workspace_text, argv[2]))) { | ||
1891 | return error; | ||
1892 | } | ||
1893 | |||
1894 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1895 | } | ||
1896 | |||
1897 | static struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { | ||
1898 | struct cmd_results *error = NULL; | ||
1899 | if ((error = checkarg(argc, "background", EXPECTED_EQUAL_TO, 1))) { | ||
1900 | return error; | ||
1901 | } | ||
1902 | |||
1903 | if ((error = add_color("background", config->current_bar->colors.background, argv[0]))) { | ||
1904 | return error; | ||
1905 | } | ||
1906 | |||
1907 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1908 | } | ||
1909 | |||
1910 | static struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { | ||
1911 | struct cmd_results *error = NULL; | ||
1912 | if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) { | ||
1913 | return error; | ||
1914 | } | ||
1915 | |||
1916 | if ((error = add_color("binding_mode_border", config->current_bar->colors.binding_mode_border, argv[0]))) { | ||
1917 | return error; | ||
1918 | } | ||
1919 | |||
1920 | if ((error = add_color("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) { | ||
1921 | return error; | ||
1922 | } | ||
1923 | |||
1924 | if ((error = add_color("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) { | ||
1925 | return error; | ||
1926 | } | ||
1927 | |||
1928 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1929 | } | ||
1930 | |||
1931 | static struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) { | ||
1932 | struct cmd_results *error = NULL; | ||
1933 | if ((error = checkarg(argc, "focused_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
1934 | return error; | ||
1935 | } | ||
1936 | |||
1937 | if ((error = add_color("focused_workspace_border", config->current_bar->colors.focused_workspace_border, argv[0]))) { | ||
1938 | return error; | ||
1939 | } | ||
1940 | |||
1941 | if ((error = add_color("focused_workspace_bg", config->current_bar->colors.focused_workspace_bg, argv[1]))) { | ||
1942 | return error; | ||
1943 | } | ||
1944 | |||
1945 | if ((error = add_color("focused_workspace_text", config->current_bar->colors.focused_workspace_text, argv[2]))) { | ||
1946 | return error; | ||
1947 | } | ||
1948 | |||
1949 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1950 | } | ||
1951 | |||
1952 | static struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) { | ||
1953 | struct cmd_results *error = NULL; | ||
1954 | if ((error = checkarg(argc, "inactive_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
1955 | return error; | ||
1956 | } | ||
1957 | |||
1958 | if ((error = add_color("inactive_workspace_border", config->current_bar->colors.inactive_workspace_border, argv[0]))) { | ||
1959 | return error; | ||
1960 | } | ||
1961 | |||
1962 | if ((error = add_color("inactive_workspace_bg", config->current_bar->colors.inactive_workspace_bg, argv[1]))) { | ||
1963 | return error; | ||
1964 | } | ||
1965 | |||
1966 | if ((error = add_color("inactive_workspace_text", config->current_bar->colors.inactive_workspace_text, argv[2]))) { | ||
1967 | return error; | ||
1968 | } | ||
1969 | |||
1970 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1971 | } | ||
1972 | |||
1973 | static struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) { | ||
1974 | struct cmd_results *error = NULL; | ||
1975 | if ((error = checkarg(argc, "separator", EXPECTED_EQUAL_TO, 1))) { | ||
1976 | return error; | ||
1977 | } | ||
1978 | |||
1979 | if ((error = add_color("separator", config->current_bar->colors.separator, argv[0]))) { | ||
1980 | return error; | ||
1981 | } | ||
1982 | |||
1983 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1984 | } | ||
1985 | |||
1986 | static struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) { | ||
1987 | struct cmd_results *error = NULL; | ||
1988 | if ((error = checkarg(argc, "statusline", EXPECTED_EQUAL_TO, 1))) { | ||
1989 | return error; | ||
1990 | } | ||
1991 | |||
1992 | if ((error = add_color("statusline", config->current_bar->colors.statusline, argv[0]))) { | ||
1993 | return error; | ||
1994 | } | ||
1995 | |||
1996 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1997 | } | ||
1998 | |||
1999 | static struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) { | ||
2000 | struct cmd_results *error = NULL; | ||
2001 | if ((error = checkarg(argc, "urgent_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
2002 | return error; | ||
2003 | } | ||
2004 | |||
2005 | if ((error = add_color("urgent_workspace_border", config->current_bar->colors.urgent_workspace_border, argv[0]))) { | ||
2006 | return error; | ||
2007 | } | ||
2008 | |||
2009 | if ((error = add_color("urgent_workspace_bg", config->current_bar->colors.urgent_workspace_bg, argv[1]))) { | ||
2010 | return error; | ||
2011 | } | ||
2012 | |||
2013 | if ((error = add_color("urgent_workspace_text", config->current_bar->colors.urgent_workspace_text, argv[2]))) { | ||
2014 | return error; | ||
2015 | } | ||
2016 | |||
2017 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2018 | } | ||
2019 | |||
2020 | static struct cmd_handler bar_colors_handlers[] = { | ||
2021 | { "active_workspace", bar_colors_cmd_active_workspace }, | ||
2022 | { "background", bar_colors_cmd_background }, | ||
2023 | { "binding_mode", bar_colors_cmd_binding_mode }, | ||
2024 | { "focused_workspace", bar_colors_cmd_focused_workspace }, | ||
2025 | { "inactive_workspace", bar_colors_cmd_inactive_workspace }, | ||
2026 | { "separator", bar_colors_cmd_separator }, | ||
2027 | { "statusline", bar_colors_cmd_statusline }, | ||
2028 | { "urgent_workspace", bar_colors_cmd_urgent_workspace }, | ||
2029 | }; | ||
2030 | |||
1823 | static int handler_compare(const void *_a, const void *_b) { | 2031 | static int handler_compare(const void *_a, const void *_b) { |
1824 | const struct cmd_handler *a = _a; | 2032 | const struct cmd_handler *a = _a; |
1825 | const struct cmd_handler *b = _b; | 2033 | const struct cmd_handler *b = _b; |
@@ -1833,6 +2041,10 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) { | |||
1833 | res = bsearch(&d, bar_handlers, | 2041 | res = bsearch(&d, bar_handlers, |
1834 | sizeof(bar_handlers) / sizeof(struct cmd_handler), | 2042 | sizeof(bar_handlers) / sizeof(struct cmd_handler), |
1835 | sizeof(struct cmd_handler), handler_compare); | 2043 | sizeof(struct cmd_handler), handler_compare); |
2044 | } else if (block == CMD_BLOCK_BAR_COLORS){ | ||
2045 | res = bsearch(&d, bar_colors_handlers, | ||
2046 | sizeof(bar_colors_handlers) / sizeof(struct cmd_handler), | ||
2047 | sizeof(struct cmd_handler), handler_compare); | ||
1836 | } else { | 2048 | } else { |
1837 | res = bsearch(&d, handlers, | 2049 | res = bsearch(&d, handlers, |
1838 | sizeof(handlers) / sizeof(struct cmd_handler), | 2050 | sizeof(handlers) / sizeof(struct cmd_handler), |
diff --git a/sway/config.c b/sway/config.c index 1fff3a08..a0e95677 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -263,6 +263,14 @@ bool read_config(FILE *file, bool is_active) { | |||
263 | } | 263 | } |
264 | break; | 264 | break; |
265 | 265 | ||
266 | case CMD_BLOCK_BAR_COLORS: | ||
267 | if (block == CMD_BLOCK_BAR) { | ||
268 | block = CMD_BLOCK_BAR_COLORS; | ||
269 | } else { | ||
270 | sway_log(L_ERROR, "Invalid block '%s'", line); | ||
271 | } | ||
272 | break; | ||
273 | |||
266 | case CMD_BLOCK_END: | 274 | case CMD_BLOCK_END: |
267 | switch(block) { | 275 | switch(block) { |
268 | case CMD_BLOCK_MODE: | 276 | case CMD_BLOCK_MODE: |
@@ -277,6 +285,11 @@ bool read_config(FILE *file, bool is_active) { | |||
277 | block = CMD_BLOCK_END; | 285 | block = CMD_BLOCK_END; |
278 | break; | 286 | break; |
279 | 287 | ||
288 | case CMD_BLOCK_BAR_COLORS: | ||
289 | sway_log(L_DEBUG, "End of bar colors block"); | ||
290 | block = CMD_BLOCK_BAR; | ||
291 | break; | ||
292 | |||
280 | case CMD_BLOCK_END: | 293 | case CMD_BLOCK_END: |
281 | sway_log(L_ERROR, "Unmatched }"); | 294 | sway_log(L_ERROR, "Unmatched }"); |
282 | break; | 295 | break; |
@@ -554,6 +567,26 @@ struct bar_config *default_bar_config(void) { | |||
554 | bar->strip_workspace_numbers = false; | 567 | bar->strip_workspace_numbers = false; |
555 | bar->binding_mode_indicator = true; | 568 | bar->binding_mode_indicator = true; |
556 | bar->tray_padding = 2; | 569 | bar->tray_padding = 2; |
570 | // set default colors | ||
571 | strcpy(bar->colors.background, "#000000"); | ||
572 | strcpy(bar->colors.statusline, "#ffffff"); | ||
573 | strcpy(bar->colors.separator, "#666666"); | ||
574 | strcpy(bar->colors.focused_workspace_border, "#4c7899"); | ||
575 | strcpy(bar->colors.focused_workspace_bg, "#285577"); | ||
576 | strcpy(bar->colors.focused_workspace_text, "#ffffff"); | ||
577 | strcpy(bar->colors.active_workspace_border, "333333"); | ||
578 | strcpy(bar->colors.active_workspace_bg, "#5f676a"); | ||
579 | strcpy(bar->colors.active_workspace_text, "#ffffff"); | ||
580 | strcpy(bar->colors.inactive_workspace_border, "#333333"); | ||
581 | strcpy(bar->colors.inactive_workspace_bg,"#222222"); | ||
582 | strcpy(bar->colors.inactive_workspace_text, "#888888"); | ||
583 | strcpy(bar->colors.urgent_workspace_border, "#2f343a"); | ||
584 | strcpy(bar->colors.urgent_workspace_bg,"#900000"); | ||
585 | strcpy(bar->colors.urgent_workspace_text, "#ffffff"); | ||
586 | strcpy(bar->colors.binding_mode_border, "#2f343a"); | ||
587 | strcpy(bar->colors.binding_mode_bg,"#900000"); | ||
588 | strcpy(bar->colors.binding_mode_text, "#ffffff"); | ||
589 | |||
557 | list_add(config->bars, bar); | 590 | list_add(config->bars, bar); |
558 | 591 | ||
559 | return bar; | 592 | return bar; |