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 | 835d246e5b561b99993c66e885cecafd38ff78f5 (patch) | |
tree | 52b70788d9496c26578158fe0dec60f2f3e049a0 | |
parent | be10fb28cf8d2ed96e26c6822afaf085285fe831 (diff) | |
download | swaybg-835d246e5b561b99993c66e885cecafd38ff78f5.tar.gz swaybg-835d246e5b561b99993c66e885cecafd38ff78f5.tar.bz2 |
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.
-rw-r--r-- | main.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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; } |