output/config: Merge direct matches too

match_id_on_name merges with existing configuration if there was an
id_on_name match, or if it should create one, but does nothing if there
is only a match on the specific name or identifier.

Simplify the logic by merging non-wildcard configs on any match.
This commit is contained in:
Kenny Levinsen 2024-03-08 21:54:39 +01:00
parent 92062cff53
commit 1c71f48ed0

View file

@ -166,6 +166,7 @@ static struct output_config *merge_id_on_name(struct output_config *oc) {
char id[128]; char id[128];
output_get_identifier(id, sizeof(id), output); output_get_identifier(id, sizeof(id), output);
struct output_config *new_oc = NULL;
char *id_on_name = format_str("%s on %s", id, name); char *id_on_name = format_str("%s on %s", id, name);
if (!id_on_name) { if (!id_on_name) {
return NULL; return NULL;
@ -174,38 +175,48 @@ static struct output_config *merge_id_on_name(struct output_config *oc) {
int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name); int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name);
if (i >= 0) { if (i >= 0) {
sway_log(SWAY_DEBUG, "Merging on top of existing id on name config"); sway_log(SWAY_DEBUG, "Merging on top of existing id on name config");
merge_output_config(config->output_configs->items[i], oc); new_oc = config->output_configs->items[i];
free(id_on_name); merge_output_config(new_oc, oc);
return config->output_configs->items[i]; goto done;
} }
// If both a name and identifier config, exist generate an id on name // If both a name and identifier config, exist generate an id on name
struct output_config *ion_oc = NULL;
int ni = list_seq_find(config->output_configs, output_name_cmp, name); int ni = list_seq_find(config->output_configs, output_name_cmp, name);
int ii = list_seq_find(config->output_configs, output_name_cmp, id); int ii = list_seq_find(config->output_configs, output_name_cmp, id);
if ((ni >= 0 && ii >= 0) || (ni >= 0 && strcmp(oc->name, id) == 0) if ((ni >= 0 && ii >= 0) || (ni >= 0 && strcmp(oc->name, id) == 0)
|| (ii >= 0 && strcmp(oc->name, name) == 0)) { || (ii >= 0 && strcmp(oc->name, name) == 0)) {
ion_oc = new_output_config(id_on_name); new_oc = new_output_config(id_on_name);
if (ni >= 0) { if (ni >= 0) {
merge_output_config(ion_oc, config->output_configs->items[ni]); merge_output_config(new_oc, config->output_configs->items[ni]);
} }
if (ii >= 0) { if (ii >= 0) {
merge_output_config(ion_oc, config->output_configs->items[ii]); merge_output_config(new_oc, config->output_configs->items[ii]);
} }
merge_output_config(ion_oc, oc); merge_output_config(new_oc, oc);
list_add(config->output_configs, ion_oc); list_add(config->output_configs, new_oc);
sway_log(SWAY_DEBUG, "Generated id on name output config \"%s\"" sway_log(SWAY_DEBUG, "Generated id on name output config \"%s\""
" (enabled: %d) (%dx%d@%fHz position %d,%d scale %f " " (enabled: %d) (%dx%d@%fHz position %d,%d scale %f "
"transform %d) (bg %s %s) (power %d) (max render time: %d)", "transform %d) (bg %s %s) (power %d) (max render time: %d)",
ion_oc->name, ion_oc->enabled, ion_oc->width, ion_oc->height, new_oc->name, new_oc->enabled, new_oc->width, new_oc->height,
ion_oc->refresh_rate, ion_oc->x, ion_oc->y, ion_oc->scale, new_oc->refresh_rate, new_oc->x, new_oc->y, new_oc->scale,
ion_oc->transform, ion_oc->background, new_oc->transform, new_oc->background,
ion_oc->background_option, ion_oc->power, new_oc->background_option, new_oc->power,
ion_oc->max_render_time); new_oc->max_render_time);
goto done;
} }
// If only direct match exists, merge with that
if (ni >= 0 && strcmp(oc->name, name) == 0) {
new_oc = config->output_configs->items[ni];
merge_output_config(new_oc, oc);
} else if (ii >= 0 && strcmp(oc->name, id) == 0) {
new_oc = config->output_configs->items[ii];
merge_output_config(new_oc, oc);
}
done:
free(id_on_name); free(id_on_name);
return ion_oc; return new_oc;
} }
struct output_config *store_output_config(struct output_config *oc) { struct output_config *store_output_config(struct output_config *oc) {