Reset outputs on reload

This commit is contained in:
Brian Ashworth 2018-07-20 22:17:20 -04:00
parent 51730a0597
commit bc7d332109
4 changed files with 95 additions and 55 deletions

View file

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