output/config: Handle id_on_name in apply_output_config_to_outputs

apply_output_config_to_outputs required the output config to be a
wildcard, or to math name or identifier, but had no handling for
the id_or_name format.

This will be required in a latter commit.
This commit is contained in:
Kenny Levinsen 2024-03-08 23:00:06 +01:00
parent 23389ebd1f
commit 0e69bec782

View file

@ -705,31 +705,44 @@ struct output_config *find_output_config(struct sway_output *output) {
return get_output_config(id, output); return get_output_config(id, output);
} }
static void apply_output_config_to_output(struct output_config *oc, struct sway_output *sway_output) {
char id[128];
output_get_identifier(id, sizeof(id), sway_output);
struct output_config *current = get_output_config(id, sway_output);
if (!current) {
// No stored output config matched, apply oc directly
sway_log(SWAY_DEBUG, "Applying oc directly");
current = new_output_config(oc->name);
merge_output_config(current, oc);
}
apply_output_config(current, sway_output);
free_output_config(current);
}
void apply_output_config_to_outputs(struct output_config *oc) { void apply_output_config_to_outputs(struct output_config *oc) {
// Try to find the output container and apply configuration now. If // Try to find the output container and apply configuration now. If
// this is during startup then there will be no container and config // this is during startup then there will be no container and config
// will be applied during normal "new output" event from wlroots. // will be applied during normal "new output" event from wlroots.
char id[128];
bool wildcard = strcmp(oc->name, "*") == 0; bool wildcard = strcmp(oc->name, "*") == 0;
struct sway_output *sway_output, *tmp; struct sway_output *sway_output, *tmp;
wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) { wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) {
if (output_match_name_or_id(sway_output, oc->name)) { if (!wildcard && !output_match_name_or_id(sway_output, oc->name)) {
char id[128]; const char *name = sway_output->wlr_output->name;
output_get_identifier(id, sizeof(id), sway_output); output_get_identifier(id, sizeof(id), sway_output);
struct output_config *current = get_output_config(id, sway_output); char *id_on_name = format_str("%s on %s", id, name);
if (!current) { bool skip = !id_on_name || strcmp(oc->name, id_on_name) != 0;
// No stored output config matched, apply oc directly free(id_on_name);
sway_log(SWAY_DEBUG, "Applying oc directly"); if (skip) {
current = new_output_config(oc->name); continue;
merge_output_config(current, oc);
} }
apply_output_config(current, sway_output); }
free_output_config(current);
if (!wildcard) { apply_output_config_to_output(oc, sway_output);
// Stop looking if the output config isn't applicable to all if (!wildcard) {
// outputs // Stop looking if the output config isn't applicable to all
break; // outputs
} break;
} }
} }