aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-08-08 13:46:36 -0400
committerBrian Ashworth <bosrsf04@gmail.com>2018-08-08 15:37:06 -0400
commit43d1ffc9ddf01eaf614293b5c8aeada27c3c9907 (patch)
treea628319cf9fe03e2e0c2ec0cd4a885b39cf7807d /sway
parentfc039f0759c1293fc270b631b035176f6924797b (diff)
downloadsway-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 'sway')
-rw-r--r--sway/commands/output/background.c35
-rw-r--r--sway/config/output.c14
-rw-r--r--sway/sway.5.scd8
3 files changed, 44 insertions, 13 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c
index 4ed56c2a..e45b571e 100644
--- a/sway/commands/output/background.c
+++ b/sway/commands/output/background.c
@@ -6,6 +6,7 @@
#include <errno.h>
#include "sway/commands.h"
#include "sway/config.h"
+#include "sway/swaynag.h"
#include "log.h"
#include "stringop.h"
@@ -36,6 +37,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
output->background = calloc(1, strlen(argv[0]) + 3);
snprintf(output->background, strlen(argv[0]) + 3, "\"%s\"", argv[0]);
output->background_option = strdup("solid_color");
+ output->background_fallback = NULL;
argc -= 2; argv += 2;
} else {
bool valid = false;
@@ -104,16 +106,35 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
free(conf);
}
- if (access(src, F_OK) == -1) {
- struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output",
- "Unable to access background file '%s': %s", src, strerror(errno));
+ bool can_access = access(src, F_OK) != -1;
+ if (!can_access) {
+ wlr_log(WLR_ERROR, "Unable to access background file '%s': %s",
+ src, strerror(errno));
+ if (!config->validating) {
+ swaynag_log(config->swaynag_command,
+ &config->swaynag_config_errors,
+ "Unable to access background file '%s'", src);
+ }
free(src);
- return cmd_res;
+ } else {
+ output->background = src;
+ output->background_option = strdup(mode);
}
-
- output->background = src;
- output->background_option = strdup(mode);
argc -= j + 1; argv += j + 1;
+
+ output->background_fallback = NULL;
+ if (argc && *argv[0] == '#') {
+ output->background_fallback = calloc(1, strlen(argv[0]) + 3);
+ snprintf(output->background_fallback, strlen(argv[0]) + 3,
+ "\"%s\"", argv[0]);
+ argc--; argv++;
+
+ if (!can_access) {
+ output->background = output->background_fallback;
+ output->background_option = strdup("solid_color");
+ output->background_fallback = NULL;
+ }
+ }
}
config->handler_context.leftovers.argc = argc;
diff --git a/sway/config/output.c b/sway/config/output.c
index 504c48c6..1d8cb3ef 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -77,6 +77,10 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
free(dst->background_option);
dst->background_option = strdup(src->background_option);
}
+ if (src->background_fallback) {
+ free(dst->background_fallback);
+ dst->background_fallback = strdup(src->background_fallback);
+ }
if (src->dpms_state != 0) {
dst->dpms_state = src->dpms_state;
}
@@ -226,17 +230,19 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
wlr_log(WLR_DEBUG, "Setting background for output %d to %s",
output_i, oc->background);
- size_t len = snprintf(NULL, 0, "%s %d %s %s",
+ size_t len = snprintf(NULL, 0, "%s %d %s %s %s",
config->swaybg_command ? config->swaybg_command : "swaybg",
- output_i, oc->background, oc->background_option);
+ output_i, oc->background, oc->background_option,
+ oc->background_fallback ? oc->background_fallback : "");
char *command = malloc(len + 1);
if (!command) {
wlr_log(WLR_DEBUG, "Unable to allocate swaybg command");
return;
}
- snprintf(command, len + 1, "%s %d %s %s",
+ snprintf(command, len + 1, "%s %d %s %s %s",
config->swaybg_command ? config->swaybg_command : "swaybg",
- output_i, oc->background, oc->background_option);
+ output_i, oc->background, oc->background_option,
+ oc->background_fallback ? oc->background_fallback : "");
wlr_log(WLR_DEBUG, "-> %s", command);
char *const cmd[] = { "sh", "-c", command, NULL };
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 73a01152..31ab281b 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -489,9 +489,13 @@ The default colors are:
setting an integral scale factor and adjusting the font size of your
applications to taste.
-*output* <name> background|bg <file> <mode>
+*output* <name> background|bg <file> <mode> [<fallback\_color>]
Sets the wallpaper for the given output to the specified file, using the
- given scaling mode (one of "stretch", "fill", "fit", "center", "tile").
+ given scaling mode (one of "stretch", "fill", "fit", "center", "tile"). If
+ the specified file cannot be accessed or if the image does fill the entire
+ output, a fallback color may be provided to cover the rest of the output.
+ __fallback\_color__ should be specified as _#RRGGBB_. Alpha is not
+ supported.
**output** <name> background|bg <color> solid\_color
Sets the background of the given output to the specified color. _color_