From 43d1ffc9ddf01eaf614293b5c8aeada27c3c9907 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Wed, 8 Aug 2018 13:46:36 -0400 Subject: Allow a fallback color to be specified for swaybg This allows for a color to be set when the wallpaper does not fill the entire output. If specified, the fallback color is also used when the image path is inaccessible. --- sway/commands/output/background.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'sway/commands/output') diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 4ed56c2a..e45b571e 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -6,6 +6,7 @@ #include #include "sway/commands.h" #include "sway/config.h" +#include "sway/swaynag.h" #include "log.h" #include "stringop.h" @@ -36,6 +37,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { output->background = calloc(1, strlen(argv[0]) + 3); snprintf(output->background, strlen(argv[0]) + 3, "\"%s\"", argv[0]); output->background_option = strdup("solid_color"); + output->background_fallback = NULL; argc -= 2; argv += 2; } else { bool valid = false; @@ -104,16 +106,35 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { free(conf); } - if (access(src, F_OK) == -1) { - struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output", - "Unable to access background file '%s': %s", src, strerror(errno)); + bool can_access = access(src, F_OK) != -1; + if (!can_access) { + wlr_log(WLR_ERROR, "Unable to access background file '%s': %s", + src, strerror(errno)); + if (!config->validating) { + swaynag_log(config->swaynag_command, + &config->swaynag_config_errors, + "Unable to access background file '%s'", src); + } free(src); - return cmd_res; + } else { + output->background = src; + output->background_option = strdup(mode); } - - output->background = src; - output->background_option = strdup(mode); argc -= j + 1; argv += j + 1; + + output->background_fallback = NULL; + if (argc && *argv[0] == '#') { + output->background_fallback = calloc(1, strlen(argv[0]) + 3); + snprintf(output->background_fallback, strlen(argv[0]) + 3, + "\"%s\"", argv[0]); + argc--; argv++; + + if (!can_access) { + output->background = output->background_fallback; + output->background_option = strdup("solid_color"); + output->background_fallback = NULL; + } + } } config->handler_context.leftovers.argc = argc; -- cgit v1.2.3-54-g00ecf