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. --- swaybg/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'swaybg') diff --git a/swaybg/main.c b/swaybg/main.c index f8e7e7ef..5b0d0458 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -17,6 +17,7 @@ struct swaybg_args { int output_idx; const char *path; enum background_mode mode; + const char *fallback; }; struct swaybg_context { @@ -76,6 +77,10 @@ static void render_frame(struct swaybg_state *state) { cairo_set_source_u32(cairo, state->context.color); cairo_paint(cairo); } else { + if (state->args->fallback && state->context.color) { + cairo_set_source_u32(cairo, state->context.color); + cairo_paint(cairo); + } render_background_image(cairo, state->context.image, state->args->mode, buffer_width, buffer_height); } @@ -91,6 +96,9 @@ static bool prepare_context(struct swaybg_state *state) { state->context.color = parse_color(state->args->path); return is_valid_color(state->args->path); } + if (state->args->fallback && is_valid_color(state->args->fallback)) { + state->context.color = parse_color(state->args->fallback); + } if (!(state->context.image = load_background_image(state->args->path))) { return false; } @@ -190,7 +198,7 @@ int main(int argc, const char **argv) { state.args = &args; wlr_log_init(WLR_DEBUG, NULL); - if (argc != 4) { + if (argc < 4 || argc > 5) { wlr_log(WLR_ERROR, "Do not run this program manually. " "See man 5 sway and look for output options."); return 1; @@ -202,6 +210,9 @@ int main(int argc, const char **argv) { if (args.mode == BACKGROUND_MODE_INVALID) { return 1; } + + args.fallback = argc == 5 ? argv[4] : NULL; + if (!prepare_context(&state)) { return 1; } -- cgit v1.2.3-54-g00ecf