From 9e0595f26bcca2a4d0aa735c4cd9fc4f792918bf Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 20 Jan 2018 11:32:07 -0500 Subject: input config handler context --- sway/commands/input.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'sway/commands/input.c') 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) { } 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,16 @@ 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]); + } + 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 +69,12 @@ struct cmd_results *cmd_input(int argc, char **argv) { } else { res = cmd_results_new(CMD_INVALID, "input ", "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; } -- cgit v1.2.3-70-g09d2