aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/input
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/input
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/input')
-rw-r--r--sway/commands/input/xkb_file.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/sway/commands/input/xkb_file.c b/sway/commands/input/xkb_file.c
index ef59bffc..493f94fb 100644
--- a/sway/commands/input/xkb_file.c
+++ b/sway/commands/input/xkb_file.c
@@ -1,7 +1,10 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <unistd.h>
3#include <errno.h>
2#include "sway/config.h" 4#include "sway/config.h"
3#include "sway/commands.h" 5#include "sway/commands.h"
4#include "log.h" 6#include "log.h"
7#include "stringop.h"
5 8
6struct cmd_results *input_cmd_xkb_file(int argc, char **argv) { 9struct cmd_results *input_cmd_xkb_file(int argc, char **argv) {
7 struct cmd_results *error = NULL; 10 struct cmd_results *error = NULL;
@@ -18,6 +21,25 @@ struct cmd_results *input_cmd_xkb_file(int argc, char **argv) {
18 ic->xkb_file = NULL; 21 ic->xkb_file = NULL;
19 } else { 22 } else {
20 ic->xkb_file = strdup(argv[0]); 23 ic->xkb_file = strdup(argv[0]);
24 if (!expand_path(&ic->xkb_file)) {
25 error = cmd_results_new(CMD_INVALID, "Invalid syntax (%s)",
26 ic->xkb_file);
27 free(ic->xkb_file);
28 ic->xkb_file = NULL;
29 return error;
30 }
31 if (!ic->xkb_file) {
32 sway_log(SWAY_ERROR, "Failed to allocate expanded path");
33 return cmd_results_new(CMD_FAILURE, "Unable to allocate resource");
34 }
35
36 bool can_access = access(ic->xkb_file, F_OK) != -1;
37 if (!can_access) {
38 sway_log_errno(SWAY_ERROR, "Unable to access xkb file '%s'",
39 ic->xkb_file);
40 config_add_swaynag_warning("Unable to access xkb file '%s'",
41 ic->xkb_file);
42 }
21 } 43 }
22 ic->xkb_file_is_set = true; 44 ic->xkb_file_is_set = true;
23 45