From 4c32212adaca665bbf588d777c2c14bf31ade204 Mon Sep 17 00:00:00 2001 From: James Murphy Date: Sat, 20 Aug 2016 16:01:48 +0000 Subject: [PATCH] Use default black background if no wallpaper is specified Fixes: https://github.com/SirCmpwn/sway/issues/865 --- include/config.h | 3 +++ sway/config.c | 48 +++++++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/include/config.h b/include/config.h index 56deaf01..c900db1e 100644 --- a/include/config.h +++ b/include/config.h @@ -247,6 +247,9 @@ struct sway_config { int32_t floating_maximum_height; int32_t floating_minimum_width; int32_t floating_minimum_height; + + char *default_background; + char *default_background_option; }; /** diff --git a/sway/config.c b/sway/config.c index 8531a337..05a610a7 100644 --- a/sway/config.c +++ b/sway/config.c @@ -196,6 +196,8 @@ void free_config(struct sway_config *config) { free(config->floating_scroll_down_cmd); free(config->floating_scroll_left_cmd); free(config->floating_scroll_right_cmd); + free(config->default_background); + free(config->default_background_option); free(config); } @@ -299,6 +301,9 @@ static void config_defaults(struct sway_config *config) { config->border_colors.placeholder.child_border = 0x0C0C0CFF; config->border_colors.background = 0xFFFFFFFF; + + config->default_background = strdup("#000000"); + config->default_background_option = strdup("solid_color"); } static int compare_modifiers(const void *left, const void *right) { @@ -859,7 +864,7 @@ void apply_input_config(struct input_config *ic, struct libinput_device *dev) { } void apply_output_config(struct output_config *oc, swayc_t *output) { - if (oc->enabled == 0) { + if (oc && oc->enabled == 0) { destroy_output(output); return; } @@ -911,30 +916,31 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { } } - if (oc && oc->background) { - if (output->bg_pid != 0) { - terminate_swaybg(output->bg_pid); - } + char *bg = oc && oc->background ? oc->background : config->default_background; + char *bg_option = oc && oc->background_option ? oc->background_option : config->default_background_option; - sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background); + if (output->bg_pid != 0) { + terminate_swaybg(output->bg_pid); + } - size_t bufsize = 4; - char output_id[bufsize]; - snprintf(output_id, bufsize, "%d", output_i); - output_id[bufsize-1] = 0; + sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, bg); - char *const cmd[] = { - "swaybg", - output_id, - oc->background, - oc->background_option, - NULL, - }; + size_t bufsize = 4; + char output_id[bufsize]; + snprintf(output_id, bufsize, "%d", output_i); + output_id[bufsize-1] = 0; - output->bg_pid = fork(); - if (output->bg_pid == 0) { - execvp(cmd[0], cmd); - } + char *const cmd[] = { + "swaybg", + output_id, + bg, + bg_option, + NULL, + }; + + output->bg_pid = fork(); + if (output->bg_pid == 0) { + execvp(cmd[0], cmd); } // reload swaybars