Merge pull request #1552 from martinetd/cleanup

config cleanup & implement free_config
This commit is contained in:
Drew DeVault 2018-01-05 09:23:13 -05:00 committed by GitHub
commit c5452a3220
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 5 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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;

View file

@ -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();