aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-02-28 12:47:40 +0100
committerSimon Ser <contact@emersion.fr>2023-04-14 18:34:54 +0200
commit04904ab9a57ff397702d6736523abeaa25d5d05b (patch)
tree47f55be8a2a3d97aaaa3dc857e62e410d32aec24
parent8d95638df6450ef9aa726e7d058b10182f584dc9 (diff)
Use all_output_by_name_or_id() in merge_id_on_name()
No need to iterate over the outputs manually.
-rw-r--r--sway/config/output.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 3b524433..352d7f7c 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -153,28 +153,22 @@ static void merge_wildcard_on_all(struct output_config *wildcard) {
}
static void merge_id_on_name(struct output_config *oc) {
- char *id_on_name = NULL;
- char id[128];
- char *name = NULL;
- struct sway_output *output;
- wl_list_for_each(output, &root->all_outputs, link) {
- name = output->wlr_output->name;
- output_get_identifier(id, sizeof(id), output);
- if (strcmp(name, oc->name) == 0 || strcmp(id, oc->name) == 0) {
- size_t length = snprintf(NULL, 0, "%s on %s", id, name) + 1;
- id_on_name = malloc(length);
- if (!id_on_name) {
- sway_log(SWAY_ERROR, "Failed to allocate id on name string");
- return;
- }
- snprintf(id_on_name, length, "%s on %s", id, name);
- break;
- }
+ struct sway_output *output = all_output_by_name_or_id(oc->name);
+ if (output == NULL) {
+ return;
}
+ const char *name = output->wlr_output->name;
+ char id[128];
+ output_get_identifier(id, sizeof(id), output);
+
+ size_t size = snprintf(NULL, 0, "%s on %s", id, name) + 1;
+ char *id_on_name = malloc(size);
if (!id_on_name) {
+ sway_log(SWAY_ERROR, "Failed to allocate id on name string");
return;
}
+ snprintf(id_on_name, size, "%s on %s", id, name);
int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name);
if (i >= 0) {