aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/input.c')
-rw-r--r--sway/commands/input.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 5ea39f62..fa9cf05a 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,19 @@ 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 if (!config->handler_context.input_config) {
32 return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
33 }
34 }
35
23 int argc_new = argc-2; 36 int argc_new = argc-2;
24 char **argv_new = argv+2; 37 char **argv_new = argv+2;
25 38
26 struct cmd_results *res; 39 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) { 40 if (strcasecmp("accel_profile", argv[1]) == 0) {
33 res = input_cmd_accel_profile(argc_new, argv_new); 41 res = input_cmd_accel_profile(argc_new, argv_new);
34 } else if (strcasecmp("click_method", argv[1]) == 0) { 42 } else if (strcasecmp("click_method", argv[1]) == 0) {
@@ -64,7 +72,12 @@ struct cmd_results *cmd_input(int argc, char **argv) {
64 } else { 72 } else {
65 res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]); 73 res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);
66 } 74 }
67 free_input_config(current_input_config); 75
68 current_input_config = old_input_config; 76 if (!has_context) {
77 // clean up the context we created earlier
78 free_input_config(config->handler_context.input_config);
79 config->handler_context.input_config = NULL;
80 }
81
69 return res; 82 return res;
70} 83}