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/config.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sway/config.c') diff --git a/sway/config.c b/sway/config.c index 5ec45b17..54357625 100644 --- a/sway/config.c +++ b/sway/config.c @@ -54,6 +54,8 @@ static void free_mode(struct sway_mode *mode) { } void free_config(struct sway_config *config) { + config_clear_handler_context(config); + int i; if (!config) { @@ -480,6 +482,11 @@ bool load_include_configs(const char *path, struct sway_config *config) { return true; } +void config_clear_handler_context(struct sway_config *config) { + free_input_config(config->handler_context.input_config); + + memset(&config->handler_context, 0, sizeof(config->handler_context)); +} bool read_config(FILE *file, struct sway_config *config) { bool success = true; @@ -592,8 +599,6 @@ bool read_config(FILE *file, struct sway_config *config) { case CMD_BLOCK_INPUT: wlr_log(L_DEBUG, "End of input block"); - free_input_config(current_input_config); - current_input_config = NULL; block = CMD_BLOCK_END; break; @@ -635,6 +640,7 @@ bool read_config(FILE *file, struct sway_config *config) { default:; } + config_clear_handler_context(config); default:; } free(line); -- cgit v1.2.3-54-g00ecf From cc3c713889e529c74888d9cd89af7039bfbae20c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 20 Jan 2018 11:44:34 -0500 Subject: seat config handler context --- include/sway/config.h | 1 + include/sway/input/input-manager.h | 2 -- sway/commands.c | 1 - sway/commands/input.c | 3 +++ sway/commands/seat.c | 25 +++++++++++++++++++++---- sway/commands/seat/attach.c | 2 ++ sway/commands/seat/fallback.c | 3 +++ sway/config.c | 2 +- 8 files changed, 31 insertions(+), 8 deletions(-) (limited to 'sway/config.c') diff --git a/include/sway/config.h b/include/sway/config.h index 1ab96b51..27fae0c6 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -354,6 +354,7 @@ struct sway_config { // Context for command handlers struct { struct input_config *input_config; + struct seat_config *seat_config; } handler_context; }; diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 8388f930..58a93fe3 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -5,8 +5,6 @@ #include "sway/config.h" #include "list.h" -extern struct seat_config *current_seat_config; - /** * The global singleton input manager * TODO: make me not a global diff --git a/sway/commands.c b/sway/commands.c index fd2e1514..414ef809 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -86,7 +86,6 @@ void apply_seat_config(struct seat_config *seat) { list_add(config->seat_configs, seat); } - current_seat_config = seat; sway_input_manager_apply_seat_config(input_manager, seat); } diff --git a/sway/commands/input.c b/sway/commands/input.c index 5de65621..fa9cf05a 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -28,6 +28,9 @@ struct cmd_results *cmd_input(int argc, char **argv) { 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; diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 6284002b..45079616 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -11,8 +11,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) { } if (config->reading && strcmp("{", argv[1]) == 0) { - current_seat_config = new_seat_config(argv[0]); - wlr_log(L_DEBUG, "entering seat block: %s", current_seat_config->name); + free_seat_config(config->handler_context.seat_config); + config->handler_context.seat_config = new_seat_config(argv[0]); + if (!config->handler_context.seat_config) { + return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); + } + wlr_log(L_DEBUG, "entering seat block: %s", argv[0]); return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); } @@ -20,11 +24,18 @@ struct cmd_results *cmd_seat(int argc, char **argv) { return error; } + bool has_context = (config->handler_context.seat_config != NULL); + if (!has_context) { + config->handler_context.seat_config = new_seat_config(argv[0]); + if (!config->handler_context.seat_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; - current_seat_config = new_seat_config(argv[0]); if (strcasecmp("attach", argv[1]) == 0) { res = seat_cmd_attach(argc_new, argv_new); } else if (strcasecmp("fallback", argv[1]) == 0) { @@ -32,6 +43,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) { } else { res = cmd_results_new(CMD_INVALID, "seat ", "Unknown command %s", argv[1]); } - current_seat_config = NULL; + + if (!has_context) { + // clean up the context we created earlier + free_seat_config(config->handler_context.seat_config); + config->handler_context.seat_config = NULL; + } + return res; } diff --git a/sway/commands/seat/attach.c b/sway/commands/seat/attach.c index 80ec63ce..3e771c00 100644 --- a/sway/commands/seat/attach.c +++ b/sway/commands/seat/attach.c @@ -12,6 +12,8 @@ struct cmd_results *seat_cmd_attach(int argc, char **argv) { if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) { return error; } + struct seat_config *current_seat_config = + config->handler_context.seat_config; if (!current_seat_config) { return cmd_results_new(CMD_FAILURE, "attach", "No seat defined"); } diff --git a/sway/commands/seat/fallback.c b/sway/commands/seat/fallback.c index 7c129aae..56feaab5 100644 --- a/sway/commands/seat/fallback.c +++ b/sway/commands/seat/fallback.c @@ -9,6 +9,8 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) { if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) { return error; } + struct seat_config *current_seat_config = + config->handler_context.seat_config; if (!current_seat_config) { return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined"); } @@ -20,6 +22,7 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) { } else if (strcasecmp(argv[0], "false") == 0) { new_config->fallback = 0; } else { + free_seat_config(new_config); return cmd_results_new(CMD_INVALID, "fallback", "Expected 'fallback '"); } diff --git a/sway/config.c b/sway/config.c index 54357625..2683d6bc 100644 --- a/sway/config.c +++ b/sway/config.c @@ -484,6 +484,7 @@ bool load_include_configs(const char *path, struct sway_config *config) { void config_clear_handler_context(struct sway_config *config) { free_input_config(config->handler_context.input_config); + free_seat_config(config->handler_context.seat_config); memset(&config->handler_context, 0, sizeof(config->handler_context)); } @@ -604,7 +605,6 @@ bool read_config(FILE *file, struct sway_config *config) { case CMD_BLOCK_SEAT: wlr_log(L_DEBUG, "End of seat block"); - current_seat_config = NULL; block = CMD_BLOCK_END; break; -- cgit v1.2.3-54-g00ecf