diff options
| author | Drew DeVault <sir@cmpwn.com> | 2018-01-05 09:23:13 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-05 09:23:13 -0500 | 
| commit | c5452a3220b0f42c310a17a375908535e661debf (patch) | |
| tree | eb3977fb64b7b739f8575d03402e235fa9836921 | |
| parent | 7dad5cd18c57d632093778e526a811d07aca8fe6 (diff) | |
| parent | 19ddb70a3296a7cc3256be65c488c18d87de4261 (diff) | |
| download | sway-c5452a3220b0f42c310a17a375908535e661debf.tar.xz | |
Merge pull request #1552 from martinetd/cleanup
config cleanup & implement free_config
| -rw-r--r-- | sway/commands.c | 4 | ||||
| -rw-r--r-- | sway/commands/input.c | 7 | ||||
| -rw-r--r-- | sway/config.c | 68 | ||||
| -rw-r--r-- | sway/main.c | 4 | 
4 files changed, 78 insertions, 5 deletions
diff --git a/sway/commands.c b/sway/commands.c index b0078a46..c1c6dc5d 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -70,8 +70,10 @@ void apply_input_config(struct input_config *input) {  		list_add(config->input_configs, input);  	} +	struct input_config *old_input_config = current_input_config;  	current_input_config = input;  	sway_input_manager_apply_input_config(input_manager, input); +	current_input_config = old_input_config;  }  void apply_seat_config(struct seat_config *seat) { @@ -195,7 +197,7 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {  struct cmd_results *handle_command(char *_exec) {  	// Even though this function will process multiple commands we will only  	// return the last error, if any (for now). (Since we have access to an -	// error string we could e.g. concatonate all errors there.) +	// error string we could e.g. concatenate all errors there.)  	struct cmd_results *results = NULL;  	char *exec = strdup(_exec);  	char *head = exec; diff --git a/sway/commands/input.c b/sway/commands/input.c index ccb1d276..edf45e4c 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -24,7 +24,11 @@ struct cmd_results *cmd_input(int argc, char **argv) {  	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) { @@ -60,6 +64,7 @@ struct cmd_results *cmd_input(int argc, char **argv) {  	} else {  		res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);  	} -	current_input_config = NULL; +	free_input_config(current_input_config); +	current_input_config = old_input_config;  	return res;  } diff --git a/sway/config.c b/sway/config.c index 312e0779..627ed94f 100644 --- a/sway/config.c +++ b/sway/config.c @@ -31,8 +31,70 @@  struct sway_config *config = NULL; +static void free_mode(struct sway_mode *mode) { +	int i; + +	if (!mode) { +		return; +	} +	free(mode->name); +	if (mode->keysym_bindings) { +		for (i = 0; i < mode->keysym_bindings->length; i++) { +			free_sway_binding(mode->keysym_bindings->items[i]); +		} +		list_free(mode->keysym_bindings); +	} +	if (mode->keycode_bindings) { +		for (i = 0; i < mode->keycode_bindings->length; i++) { +			free_sway_binding(mode->keycode_bindings->items[i]); +		} +		list_free(mode->keycode_bindings); +	} +	free(mode); +} +  void free_config(struct sway_config *config) { -	// TODO +	int i; + +	if (!config) { +		return; +	} + +	// TODO: handle all currently unhandled lists as we add implementations +	list_free(config->symbols); +	if (config->modes) { +		for (i = 0; i < config->modes->length; i++) { +			free_mode(config->modes->items[i]); +		} +		list_free(config->modes); +	} +	list_free(config->bars); +	list_free(config->cmd_queue); +	list_free(config->workspace_outputs); +	list_free(config->pid_workspaces); +	list_free(config->output_configs); +	if (config->input_configs) { +		for (i = 0; i < config->input_configs->length; i++) { +			free_input_config(config->input_configs->items[i]); +		} +		list_free(config->input_configs); +	} +	list_free(config->seat_configs); +	list_free(config->criteria); +	list_free(config->no_focus); +	list_free(config->active_bar_modifiers); +	list_free(config->config_chain); +	list_free(config->command_policies); +	list_free(config->feature_policies); +	list_free(config->ipc_policies); +	free(config->current_bar); +	free(config->floating_scroll_up_cmd); +	free(config->floating_scroll_down_cmd); +	free(config->floating_scroll_left_cmd); +	free(config->floating_scroll_right_cmd); +	free(config->font); +	free((char *)config->current_config); +	free(config);  }  static void config_defaults(struct sway_config *config) { @@ -186,6 +248,7 @@ static char *get_config_path(void) {  			if (file_exists(path)) {  				return path;  			} +			free(path);  		}  	} @@ -446,7 +509,7 @@ bool read_config(FILE *file, struct sway_config *config) {  			break;  		case CMD_DEFER: -			sway_log(L_DEBUG, "Defferring command `%s'", line); +			sway_log(L_DEBUG, "Deferring command `%s'", line);  			list_add(config->cmd_queue, strdup(line));  			break; @@ -524,6 +587,7 @@ bool read_config(FILE *file, struct sway_config *config) {  			case CMD_BLOCK_INPUT:  				sway_log(L_DEBUG, "End of input block"); +				free_input_config(current_input_config);  				current_input_config = NULL;  				block = CMD_BLOCK_END;  				break; diff --git a/sway/main.c b/sway/main.c index c18e2677..f2f24be3 100644 --- a/sway/main.c +++ b/sway/main.c @@ -380,7 +380,7 @@ int main(int argc, char **argv) {  	// prevent ipc from crashing sway  	signal(SIGPIPE, SIG_IGN); -	wlr_log(L_INFO, "Starting sway version " SWAY_VERSION "\n"); +	wlr_log(L_INFO, "Starting sway version " SWAY_VERSION);  	init_layout(); @@ -414,6 +414,8 @@ int main(int argc, char **argv) {  		server_run(&server);  	} +	wlr_log(L_INFO, "Shutting down sway"); +  	server_fini(&server);  	ipc_terminate();  | 
