From 98aa59fdda5fcc9a589e93f7c6ef40d3eaee3972 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Sat, 30 Jul 2016 18:50:13 -0500 Subject: implement solid color rendering for swaybg --- sway/commands.c | 75 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'sway/commands.c') 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) { } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { wordexp_t p; if (++i >= argc) { - return cmd_results_new(CMD_INVALID, "output", "Missing background file."); + return cmd_results_new(CMD_INVALID, "output", "Missing background file or color specification."); } if (i + 1 >= argc) { - return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode."); + return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode or `solid_color`."); } - char *src = join_args(argv + i, argc - i - 1); - char *mode = argv[argc - 1]; - if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { - return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); - } - free(src); - src = p.we_wordv[0]; - if (config->reading && *src != '/') { - char *conf = strdup(config->current_config); - char *conf_path = dirname(conf); - src = malloc(strlen(conf_path) + strlen(src) + 2); - sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); - free(conf); - } - if (access(src, F_OK) == -1) { - return cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); - } - for (char *m = mode; *m; ++m) *m = tolower(*m); - // Check mode - bool valid = false; - size_t j; - for (j = 0; j < sizeof(bg_options) / sizeof(char *); ++j) { - if (strcasecmp(mode, bg_options[j]) == 0) { - valid = true; - break; + if (strcasecmp(argv[argc - 1], "solid_color") == 0) { + output->background = strdup(argv[argc - 2]); + output->background_option = strdup("solid_color"); + } else { + char *src = join_args(argv + i, argc - i - 1); + char *mode = argv[argc - 1]; + if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { + return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); } - } - if (!valid) { - return cmd_results_new(CMD_INVALID, "output", "Invalid background scaling mode."); - } - output->background = strdup(src); - output->background_option = strdup(mode); - if (src != p.we_wordv[0]) { free(src); + src = p.we_wordv[0]; + if (config->reading && *src != '/') { + char *conf = strdup(config->current_config); + char *conf_path = dirname(conf); + src = malloc(strlen(conf_path) + strlen(src) + 2); + sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); + free(conf); + } + if (access(src, F_OK) == -1) { + return cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); + } + for (char *m = mode; *m; ++m) *m = tolower(*m); + // Check mode + bool valid = false; + size_t j; + for (j = 0; j < sizeof(bg_options) / sizeof(char *); ++j) { + if (strcasecmp(mode, bg_options[j]) == 0) { + valid = true; + break; + } + } + if (!valid) { + return cmd_results_new(CMD_INVALID, "output", "Invalid background scaling mode."); + } + output->background = strdup(src); + output->background_option = strdup(mode); + if (src != p.we_wordv[0]) { + free(src); + } + wordfree(&p); } - wordfree(&p); } } -- cgit v1.2.3