aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/input.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-01-20 11:32:07 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-01-20 11:34:57 -0500
commit9e0595f26bcca2a4d0aa735c4cd9fc4f792918bf (patch)
tree1417f4b913875db24efc5418481ab057679680cd /sway/commands/input.c
parentMerge pull request #1571 from acrisci/wlroots-modifiers-update (diff)
downloadsway-9e0595f26bcca2a4d0aa735c4cd9fc4f792918bf.tar.gz
sway-9e0595f26bcca2a4d0aa735c4cd9fc4f792918bf.tar.zst
sway-9e0595f26bcca2a4d0aa735c4cd9fc4f792918bf.zip
input config handler context
Diffstat (limited to 'sway/commands/input.c')
-rw-r--r--sway/commands/input.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 5ea39f62..5de65621 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -11,8 +11,12 @@ struct cmd_results *cmd_input(int argc, char **argv) {
11 } 11 }
12 12
13 if (config->reading && strcmp("{", argv[1]) == 0) { 13 if (config->reading && strcmp("{", argv[1]) == 0) {
14 current_input_config = new_input_config(argv[0]); 14 free_input_config(config->handler_context.input_config);
15 wlr_log(L_DEBUG, "entering input block: %s", current_input_config->identifier); 15 config->handler_context.input_config = new_input_config(argv[0]);
16 if (!config->handler_context.input_config) {
17 return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
18 }
19 wlr_log(L_DEBUG, "entering input block: %s", argv[0]);
16 return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); 20 return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL);
17 } 21 }
18 22
@@ -20,15 +24,16 @@ struct cmd_results *cmd_input(int argc, char **argv) {
20 return error; 24 return error;
21 } 25 }
22 26
27 bool has_context = (config->handler_context.input_config != NULL);
28 if (!has_context) {
29 // caller did not give a context so create one just for this command
30 config->handler_context.input_config = new_input_config(argv[0]);
31 }
32
23 int argc_new = argc-2; 33 int argc_new = argc-2;
24 char **argv_new = argv+2; 34 char **argv_new = argv+2;
25 35
26 struct cmd_results *res; 36 struct cmd_results *res;
27 struct input_config *old_input_config = current_input_config;
28 current_input_config = new_input_config(argv[0]);
29 if (!current_input_config) {
30 return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
31 }
32 if (strcasecmp("accel_profile", argv[1]) == 0) { 37 if (strcasecmp("accel_profile", argv[1]) == 0) {
33 res = input_cmd_accel_profile(argc_new, argv_new); 38 res = input_cmd_accel_profile(argc_new, argv_new);
34 } else if (strcasecmp("click_method", argv[1]) == 0) { 39 } else if (strcasecmp("click_method", argv[1]) == 0) {
@@ -64,7 +69,12 @@ struct cmd_results *cmd_input(int argc, char **argv) {
64 } else { 69 } else {
65 res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]); 70 res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);
66 } 71 }
67 free_input_config(current_input_config); 72
68 current_input_config = old_input_config; 73 if (!has_context) {
74 // clean up the context we created earlier
75 free_input_config(config->handler_context.input_config);
76 config->handler_context.input_config = NULL;
77 }
78
69 return res; 79 return res;
70} 80}