aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-11-20 22:10:03 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-11-21 10:36:15 -0500
commit2f858a1adaef17241ca6fda973f2b867b25e1971 (patch)
tree4942dfcbd3eeea04092ff1b40791b8c25e1f4403 /sway/commands/output
parentinput/keyboard: cleanup xkb_file error handing (diff)
downloadsway-2f858a1adaef17241ca6fda973f2b867b25e1971.tar.gz
sway-2f858a1adaef17241ca6fda973f2b867b25e1971.tar.zst
sway-2f858a1adaef17241ca6fda973f2b867b25e1971.zip
input_cmd_xkb_file: allow shell path expansion
This allows for shell path expansion for input_cmd_xkb_file. The logic has been extracted from output_cmd_background
Diffstat (limited to 'sway/commands/output')
-rw-r--r--sway/commands/output/background.c16
1 files changed, 2 insertions, 14 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c
index 054fb707..68ee9fe1 100644
--- a/sway/commands/output/background.c
+++ b/sway/commands/output/background.c
@@ -4,7 +4,6 @@
4#include <string.h> 4#include <string.h>
5#include <strings.h> 5#include <strings.h>
6#include <unistd.h> 6#include <unistd.h>
7#include <wordexp.h>
8#include <errno.h> 7#include <errno.h>
9#include "sway/commands.h" 8#include "sway/commands.h"
10#include "sway/config.h" 9#include "sway/config.h"
@@ -79,26 +78,15 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
79 return cmd_results_new(CMD_INVALID, "Missing background file"); 78 return cmd_results_new(CMD_INVALID, "Missing background file");
80 } 79 }
81 80
82 wordexp_t p = {0};
83 char *src = join_args(argv, j); 81 char *src = join_args(argv, j);
84 while (strstr(src, " ")) { 82 if (!expand_path(&src)) {
85 src = realloc(src, strlen(src) + 2);
86 char *ptr = strstr(src, " ") + 1;
87 memmove(ptr + 1, ptr, strlen(ptr) + 1);
88 *ptr = '\\';
89 }
90 if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
91 struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, 83 struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID,
92 "Invalid syntax (%s)", src); 84 "Invalid syntax (%s)", src);
93 free(src); 85 free(src);
94 wordfree(&p);
95 return cmd_res; 86 return cmd_res;
96 } 87 }
97 free(src);
98 src = join_args(p.we_wordv, p.we_wordc);
99 wordfree(&p);
100 if (!src) { 88 if (!src) {
101 sway_log(SWAY_ERROR, "Failed to duplicate string"); 89 sway_log(SWAY_ERROR, "Failed to allocate expanded path");
102 return cmd_results_new(CMD_FAILURE, "Unable to allocate resource"); 90 return cmd_results_new(CMD_FAILURE, "Unable to allocate resource");
103 } 91 }
104 92