diff options
author | Zandr Martin <zandrmartin@gmail.com> | 2016-07-30 18:50:13 -0500 |
---|---|---|
committer | Zandr Martin <zandrmartin@gmail.com> | 2016-07-30 18:50:13 -0500 |
commit | 98aa59fdda5fcc9a589e93f7c6ef40d3eaee3972 (patch) | |
tree | a7acb9aab8520040d49be04184d70984a66b95e7 /sway | |
parent | Merge pull request #803 from zandrmartin/x11-pids (diff) | |
download | sway-98aa59fdda5fcc9a589e93f7c6ef40d3eaee3972.tar.gz sway-98aa59fdda5fcc9a589e93f7c6ef40d3eaee3972.tar.zst sway-98aa59fdda5fcc9a589e93f7c6ef40d3eaee3972.zip |
implement solid color rendering for swaybg
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 75 | ||||
-rw-r--r-- | sway/sway.5.txt | 4 |
2 files changed, 44 insertions, 35 deletions
diff --git a/sway/commands.c b/sway/commands.c index 053b5792..7247a407 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1651,47 +1651,52 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
1651 | } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { | 1651 | } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { |
1652 | wordexp_t p; | 1652 | wordexp_t p; |
1653 | if (++i >= argc) { | 1653 | if (++i >= argc) { |
1654 | return cmd_results_new(CMD_INVALID, "output", "Missing background file."); | 1654 | return cmd_results_new(CMD_INVALID, "output", "Missing background file or color specification."); |
1655 | } | 1655 | } |
1656 | if (i + 1 >= argc) { | 1656 | if (i + 1 >= argc) { |
1657 | return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode."); | 1657 | return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode or `solid_color`."); |
1658 | } | 1658 | } |
1659 | char *src = join_args(argv + i, argc - i - 1); | 1659 | if (strcasecmp(argv[argc - 1], "solid_color") == 0) { |
1660 | char *mode = argv[argc - 1]; | 1660 | output->background = strdup(argv[argc - 2]); |
1661 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { | 1661 | output->background_option = strdup("solid_color"); |
1662 | return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); | 1662 | } else { |
1663 | } | 1663 | char *src = join_args(argv + i, argc - i - 1); |
1664 | free(src); | 1664 | char *mode = argv[argc - 1]; |
1665 | src = p.we_wordv[0]; | 1665 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { |
1666 | if (config->reading && *src != '/') { | 1666 | return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); |
1667 | char *conf = strdup(config->current_config); | ||
1668 | char *conf_path = dirname(conf); | ||
1669 | src = malloc(strlen(conf_path) + strlen(src) + 2); | ||
1670 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | ||
1671 | free(conf); | ||
1672 | } | ||
1673 | if (access(src, F_OK) == -1) { | ||
1674 | return cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); | ||
1675 | } | ||
1676 | for (char *m = mode; *m; ++m) *m = tolower(*m); | ||
1677 | // Check mode | ||
1678 | bool valid = false; | ||
1679 | size_t j; | ||
1680 | for (j = 0; j < sizeof(bg_options) / sizeof(char *); ++j) { | ||
1681 | if (strcasecmp(mode, bg_options[j]) == 0) { | ||
1682 | valid = true; | ||
1683 | break; | ||
1684 | } | 1667 | } |
1685 | } | ||
1686 | if (!valid) { | ||
1687 | return cmd_results_new(CMD_INVALID, "output", "Invalid background scaling mode."); | ||
1688 | } | ||
1689 | output->background = strdup(src); | ||
1690 | output->background_option = strdup(mode); | ||
1691 | if (src != p.we_wordv[0]) { | ||
1692 | free(src); | 1668 | free(src); |
1669 | src = p.we_wordv[0]; | ||
1670 | if (config->reading && *src != '/') { | ||
1671 | char *conf = strdup(config->current_config); | ||
1672 | char *conf_path = dirname(conf); | ||
1673 | src = malloc(strlen(conf_path) + strlen(src) + 2); | ||
1674 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | ||
1675 | free(conf); | ||
1676 | } | ||
1677 | if (access(src, F_OK) == -1) { | ||
1678 | return cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); | ||
1679 | } | ||
1680 | for (char *m = mode; *m; ++m) *m = tolower(*m); | ||
1681 | // Check mode | ||
1682 | bool valid = false; | ||
1683 | size_t j; | ||
1684 | for (j = 0; j < sizeof(bg_options) / sizeof(char *); ++j) { | ||
1685 | if (strcasecmp(mode, bg_options[j]) == 0) { | ||
1686 | valid = true; | ||
1687 | break; | ||
1688 | } | ||
1689 | } | ||
1690 | if (!valid) { | ||
1691 | return cmd_results_new(CMD_INVALID, "output", "Invalid background scaling mode."); | ||
1692 | } | ||
1693 | output->background = strdup(src); | ||
1694 | output->background_option = strdup(mode); | ||
1695 | if (src != p.we_wordv[0]) { | ||
1696 | free(src); | ||
1697 | } | ||
1698 | wordfree(&p); | ||
1693 | } | 1699 | } |
1694 | wordfree(&p); | ||
1695 | } | 1700 | } |
1696 | } | 1701 | } |
1697 | 1702 | ||
diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 446995d5..787253a0 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt | |||
@@ -308,6 +308,10 @@ The default colors are: | |||
308 | Sets the wallpaper for the given output to the specified file, using the given | 308 | Sets the wallpaper for the given output to the specified file, using the given |
309 | scaling mode (one of "stretch", "fill", "fit", "center", "tile"). | 309 | scaling mode (one of "stretch", "fill", "fit", "center", "tile"). |
310 | 310 | ||
311 | **output** <name> <background|bg> <color> solid_color:: | ||
312 | Sets the background of the given output to the specified color. _color_ should | ||
313 | be specified as an _#rrggbb_ (no alpha) color. | ||
314 | |||
311 | **output** <name> disable:: | 315 | **output** <name> disable:: |
312 | Disables the specified output. | 316 | Disables the specified output. |
313 | 317 | ||