diff options
author | 2018-08-08 16:42:33 -0400 | |
---|---|---|
committer | 2018-08-08 16:42:33 -0400 | |
commit | 78c0f013dd600f2877e93508ff4897daf0dc25a0 (patch) | |
tree | a628319cf9fe03e2e0c2ec0cd4a885b39cf7807d /swaybg | |
parent | Merge pull request #2423 from manio/master (diff) | |
parent | Allow a fallback color to be specified for swaybg (diff) | |
download | sway-78c0f013dd600f2877e93508ff4897daf0dc25a0.tar.gz sway-78c0f013dd600f2877e93508ff4897daf0dc25a0.tar.zst sway-78c0f013dd600f2877e93508ff4897daf0dc25a0.zip |
Merge pull request #2439 from RedSoxFan/fix-2434
Allow a fallback color to be specified for swaybg
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 { | |||
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 | ||
22 | struct swaybg_context { | 23 | struct 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 | } |