diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-08-08 13:46:36 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-08-08 15:37:06 -0400 |
commit | 43d1ffc9ddf01eaf614293b5c8aeada27c3c9907 (patch) | |
tree | a628319cf9fe03e2e0c2ec0cd4a885b39cf7807d /swaybg | |
parent | fc039f0759c1293fc270b631b035176f6924797b (diff) | |
download | sway-43d1ffc9ddf01eaf614293b5c8aeada27c3c9907.tar.xz |
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.
Diffstat (limited to 'swaybg')
-rw-r--r-- | swaybg/main.c | 13 |
1 files changed, 12 insertions, 1 deletions
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; } |