aboutsummaryrefslogtreecommitdiffstats
path: root/swaybg
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-08 13:46:36 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-08 15:37:06 -0400
commit43d1ffc9ddf01eaf614293b5c8aeada27c3c9907 (patch)
treea628319cf9fe03e2e0c2ec0cd4a885b39cf7807d /swaybg
parentMerge pull request #2423 from manio/master (diff)
downloadsway-43d1ffc9ddf01eaf614293b5c8aeada27c3c9907.tar.gz
sway-43d1ffc9ddf01eaf614293b5c8aeada27c3c9907.tar.zst
sway-43d1ffc9ddf01eaf614293b5c8aeada27c3c9907.zip
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.c13
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 {
17 int output_idx; 17 int output_idx;
18 const char *path; 18 const char *path;
19 enum background_mode mode; 19 enum background_mode mode;
20 const char *fallback;
20}; 21};
21 22
22struct swaybg_context { 23struct swaybg_context {
@@ -76,6 +77,10 @@ static void render_frame(struct swaybg_state *state) {
76 cairo_set_source_u32(cairo, state->context.color); 77 cairo_set_source_u32(cairo, state->context.color);
77 cairo_paint(cairo); 78 cairo_paint(cairo);
78 } else { 79 } else {
80 if (state->args->fallback && state->context.color) {
81 cairo_set_source_u32(cairo, state->context.color);
82 cairo_paint(cairo);
83 }
79 render_background_image(cairo, state->context.image, 84 render_background_image(cairo, state->context.image,
80 state->args->mode, buffer_width, buffer_height); 85 state->args->mode, buffer_width, buffer_height);
81 } 86 }
@@ -91,6 +96,9 @@ static bool prepare_context(struct swaybg_state *state) {
91 state->context.color = parse_color(state->args->path); 96 state->context.color = parse_color(state->args->path);
92 return is_valid_color(state->args->path); 97 return is_valid_color(state->args->path);
93 } 98 }
99 if (state->args->fallback && is_valid_color(state->args->fallback)) {
100 state->context.color = parse_color(state->args->fallback);
101 }
94 if (!(state->context.image = load_background_image(state->args->path))) { 102 if (!(state->context.image = load_background_image(state->args->path))) {
95 return false; 103 return false;
96 } 104 }
@@ -190,7 +198,7 @@ int main(int argc, const char **argv) {
190 state.args = &args; 198 state.args = &args;
191 wlr_log_init(WLR_DEBUG, NULL); 199 wlr_log_init(WLR_DEBUG, NULL);
192 200
193 if (argc != 4) { 201 if (argc < 4 || argc > 5) {
194 wlr_log(WLR_ERROR, "Do not run this program manually. " 202 wlr_log(WLR_ERROR, "Do not run this program manually. "
195 "See man 5 sway and look for output options."); 203 "See man 5 sway and look for output options.");
196 return 1; 204 return 1;
@@ -202,6 +210,9 @@ int main(int argc, const char **argv) {
202 if (args.mode == BACKGROUND_MODE_INVALID) { 210 if (args.mode == BACKGROUND_MODE_INVALID) {
203 return 1; 211 return 1;
204 } 212 }
213
214 args.fallback = argc == 5 ? argv[4] : NULL;
215
205 if (!prepare_context(&state)) { 216 if (!prepare_context(&state)) {
206 return 1; 217 return 1;
207 } 218 }