aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/input.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-01-22 01:16:23 +0100
committerGitHub <noreply@github.com>2018-01-22 01:16:23 +0100
commit0c58673c6a108ba241419a0f1d5fecd47f22370e (patch)
treec3e19af6dd70f04fc5c617e932b4afcc7a1b41d9 /sway/commands/input.c
parenta6bc46eea9d7dec6a2b93f85bac2e3737e0c6725 (diff)
parentbeb3805cf0300bc2640290233aa763d757c12466 (diff)
Merge pull request #1574 from acrisci/config-refactor
Command criteria
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) {
}
if (config->reading && strcmp("{", argv[1]) == 0) {
- current_input_config = new_input_config(argv[0]);
- wlr_log(L_DEBUG, "entering input block: %s", current_input_config->identifier);
+ free_input_config(config->handler_context.input_config);
+ config->handler_context.input_config = new_input_config(argv[0]);
+ if (!config->handler_context.input_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ wlr_log(L_DEBUG, "entering input block: %s", argv[0]);
return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL);
}
@@ -20,15 +24,19 @@ struct cmd_results *cmd_input(int argc, char **argv) {
return error;
}
+ bool has_context = (config->handler_context.input_config != NULL);
+ if (!has_context) {
+ // caller did not give a context so create one just for this command
+ config->handler_context.input_config = new_input_config(argv[0]);
+ if (!config->handler_context.input_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ }
+
int argc_new = argc-2;
char **argv_new = argv+2;
struct cmd_results *res;
- struct input_config *old_input_config = current_input_config;
- current_input_config = new_input_config(argv[0]);
- if (!current_input_config) {
- return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
- }
if (strcasecmp("accel_profile", argv[1]) == 0) {
res = input_cmd_accel_profile(argc_new, argv_new);
} else if (strcasecmp("click_method", argv[1]) == 0) {
@@ -64,7 +72,12 @@ struct cmd_results *cmd_input(int argc, char **argv) {
} else {
res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);
}
- free_input_config(current_input_config);
- current_input_config = old_input_config;
+
+ if (!has_context) {
+ // clean up the context we created earlier
+ free_input_config(config->handler_context.input_config);
+ config->handler_context.input_config = NULL;
+ }
+
return res;
}