summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-04-01 01:52:34 -0400
committeremersion <contact@emersion.fr>2019-04-01 11:33:14 +0300
commit7892d8cc51c84b6a0330bc27517e5d3a9efbb67e (patch)
tree11b7da9c0948595fc8fc9a4470b90615857beba0 /main.c
parentd815e29b645dbbfcaac8c770bd21ddf9a90d2737 (diff)
Allow spaces in image file path
This allows one or more spaces to be in the image file path
Diffstat (limited to 'main.c')
-rw-r--r--main.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/main.c b/main.c
index 7048276..7af227c 100644
--- a/main.c
+++ b/main.c
@@ -374,6 +374,23 @@ static cairo_surface_t *select_image(struct swaylock_state *state,
return default_image;
}
+static char *join_args(char **argv, int argc) {
+ assert(argc > 0);
+ int len = 0, i;
+ for (i = 0; i < argc; ++i) {
+ len += strlen(argv[i]) + 1;
+ }
+ char *res = malloc(len);
+ len = 0;
+ for (i = 0; i < argc; ++i) {
+ strcpy(res + len, argv[i]);
+ len += strlen(argv[i]);
+ res[len++] = ' ';
+ }
+ res[len - 1] = '\0';
+ return res;
+}
+
static void load_image(char *arg, struct swaylock_state *state) {
// [[<output>]:]<path>
struct swaylock_image *image = calloc(1, sizeof(struct swaylock_image));
@@ -407,11 +424,19 @@ static void load_image(char *arg, struct swaylock_state *state) {
}
}
- // Bash doesn't replace the ~ with $HOME if the output name is supplied
+ // The shell will not expand ~ to the value of $HOME when an output name is
+ // given. Also, any image paths given in the config file need to have shell
+ // expansions performed
wordexp_t p;
+ while (strstr(image->path, " ")) {
+ image->path = realloc(image->path, strlen(image->path) + 2);
+ char *ptr = strstr(image->path, " ") + 1;
+ memmove(ptr + 1, ptr, strlen(ptr) + 1);
+ *ptr = '\\';
+ }
if (wordexp(image->path, &p, 0) == 0) {
free(image->path);
- image->path = strdup(p.we_wordv[0]);
+ image->path = join_args(p.we_wordv, p.we_wordc);
wordfree(&p);
}