From bc7d3321093339d34839718b35af034de4aeb9f1 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Fri, 20 Jul 2018 22:17:20 -0400 Subject: Reset outputs on reload --- include/sway/config.h | 4 +++ sway/commands/output.c | 62 +++++--------------------------------- sway/config.c | 4 +++ sway/config/output.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 55 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 87768399..b8da29c5 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -464,8 +464,12 @@ void apply_output_config(struct output_config *oc, struct output_config *store_output_config(struct output_config *oc); +void apply_output_config_to_outputs(struct output_config *oc); + void free_output_config(struct output_config *oc); +void create_default_output_configs(void); + int workspace_output_cmp_workspace(const void *a, const void *b); int sway_binding_cmp(const void *a, const void *b); diff --git a/sway/commands/output.c b/sway/commands/output.c index 4d98162b..ef1b7a69 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -21,60 +21,6 @@ static struct cmd_handler output_handlers[] = { { "transform", output_cmd_transform }, }; -static struct output_config *get_output_config(char *name, char *identifier) { - int i = list_seq_find(config->output_configs, output_name_cmp, name); - if (i >= 0) { - return config->output_configs->items[i]; - } - - i = list_seq_find(config->output_configs, output_name_cmp, identifier); - if (i >= 0) { - return config->output_configs->items[i]; - } - - return NULL; -} - -static void apply_output_config_to_outputs(struct output_config *oc) { - // Try to find the output container and apply configuration now. If - // this is during startup then there will be no container and config - // will be applied during normal "new output" event from wlroots. - bool wildcard = strcmp(oc->name, "*") == 0; - char id[128]; - struct sway_output *sway_output; - wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) { - char *name = sway_output->wlr_output->name; - output_get_identifier(id, sizeof(id), sway_output); - if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { - if (!sway_output->swayc) { - if (!oc->enabled) { - if (!wildcard) { - break; - } - continue; - } - - output_enable(sway_output); - } - - struct output_config *current = oc; - if (wildcard) { - struct output_config *tmp = get_output_config(name, id); - if (tmp) { - current = tmp; - } - } - apply_output_config(current, sway_output->swayc); - - if (!wildcard) { - // Stop looking if the output config isn't applicable to all - // outputs - break; - } - } - } -} - struct cmd_results *cmd_output(int argc, char **argv) { struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1); if (error != NULL) { @@ -115,7 +61,13 @@ struct cmd_results *cmd_output(int argc, char **argv) { config->handler_context.leftovers.argv = NULL; output = store_output_config(output); - apply_output_config_to_outputs(output); + + // If reloading, the output configs will be applied after reading the + // entire config and before the deferred commands so that an auto generated + // workspace name is not given to re-enabled outputs. + if (!config->reloading) { + apply_output_config_to_outputs(output); + } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/config.c b/sway/config.c index 4b892852..ed624bfa 100644 --- a/sway/config.c +++ b/sway/config.c @@ -361,6 +361,7 @@ bool load_main_config(const char *file, bool is_active) { wlr_log(WLR_DEBUG, "Performing configuration file reload"); config->reloading = true; config->active = true; + create_default_output_configs(); } config->current_config_path = path; @@ -419,6 +420,9 @@ bool load_main_config(const char *file, bool is_active) { success = success && load_config(path, config); if (is_active) { + for (int i = 0; i < config->output_configs->length; i++) { + apply_output_config_to_outputs(config->output_configs->items[i]); + } config->reloading = false; } diff --git a/sway/config/output.c b/sway/config/output.c index 505fa745..504c48c6 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -263,6 +263,60 @@ void apply_output_config(struct output_config *oc, struct sway_container *output } } +static struct output_config *get_output_config(char *name, char *identifier) { + int i = list_seq_find(config->output_configs, output_name_cmp, name); + if (i >= 0) { + return config->output_configs->items[i]; + } + + i = list_seq_find(config->output_configs, output_name_cmp, identifier); + if (i >= 0) { + return config->output_configs->items[i]; + } + + return NULL; +} + +void apply_output_config_to_outputs(struct output_config *oc) { + // Try to find the output container and apply configuration now. If + // this is during startup then there will be no container and config + // will be applied during normal "new output" event from wlroots. + bool wildcard = strcmp(oc->name, "*") == 0; + char id[128]; + struct sway_output *sway_output; + wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) { + char *name = sway_output->wlr_output->name; + output_get_identifier(id, sizeof(id), sway_output); + if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { + if (!sway_output->swayc) { + if (!oc->enabled) { + if (!wildcard) { + break; + } + continue; + } + + output_enable(sway_output); + } + + struct output_config *current = oc; + if (wildcard) { + struct output_config *tmp = get_output_config(name, id); + if (tmp) { + current = tmp; + } + } + apply_output_config(current, sway_output->swayc); + + if (!wildcard) { + // Stop looking if the output config isn't applicable to all + // outputs + break; + } + } + } +} + void free_output_config(struct output_config *oc) { if (!oc) { return; @@ -272,3 +326,29 @@ void free_output_config(struct output_config *oc) { free(oc->background_option); free(oc); } + +static void default_output_config(struct output_config *oc, + struct wlr_output *wlr_output) { + oc->enabled = 1; + if (!wl_list_empty(&wlr_output->modes)) { + struct wlr_output_mode *mode = + wl_container_of(wlr_output->modes.prev, mode, link); + oc->width = mode->width; + oc->height = mode->height; + oc->refresh_rate = mode->refresh; + } + oc->x = oc->y = -1; + oc->scale = 1; + oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; +} + +void create_default_output_configs(void) { + struct sway_output *sway_output; + wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) { + char *name = sway_output->wlr_output->name; + struct output_config *oc = new_output_config(name); + default_output_config(oc, sway_output->wlr_output); + list_add(config->output_configs, oc); + } +} + -- cgit v1.2.3-70-g09d2