aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2023-02-28 12:47:40 +0100
committerLibravatar Simon Ser <contact@emersion.fr>2023-04-14 18:34:54 +0200
commit04904ab9a57ff397702d6736523abeaa25d5d05b (patch)
tree47f55be8a2a3d97aaaa3dc857e62e410d32aec24
parentIntroduce output_match_name_or_id() (diff)
downloadsway-04904ab9a57ff397702d6736523abeaa25d5d05b.tar.gz
sway-04904ab9a57ff397702d6736523abeaa25d5d05b.tar.zst
sway-04904ab9a57ff397702d6736523abeaa25d5d05b.zip
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) {
153} 153}
154 154
155static void merge_id_on_name(struct output_config *oc) { 155static void merge_id_on_name(struct output_config *oc) {
156 char *id_on_name = NULL; 156 struct sway_output *output = all_output_by_name_or_id(oc->name);
157 char id[128]; 157 if (output == NULL) {
158 char *name = NULL; 158 return;
159 struct sway_output *output;
160 wl_list_for_each(output, &root->all_outputs, link) {
161 name = output->wlr_output->name;
162 output_get_identifier(id, sizeof(id), output);
163 if (strcmp(name, oc->name) == 0 || strcmp(id, oc->name) == 0) {
164 size_t length = snprintf(NULL, 0, "%s on %s", id, name) + 1;
165 id_on_name = malloc(length);
166 if (!id_on_name) {
167 sway_log(SWAY_ERROR, "Failed to allocate id on name string");
168 return;
169 }
170 snprintf(id_on_name, length, "%s on %s", id, name);
171 break;
172 }
173 } 159 }
174 160
161 const char *name = output->wlr_output->name;
162 char id[128];
163 output_get_identifier(id, sizeof(id), output);
164
165 size_t size = snprintf(NULL, 0, "%s on %s", id, name) + 1;
166 char *id_on_name = malloc(size);
175 if (!id_on_name) { 167 if (!id_on_name) {
168 sway_log(SWAY_ERROR, "Failed to allocate id on name string");
176 return; 169 return;
177 } 170 }
171 snprintf(id_on_name, size, "%s on %s", id, name);
178 172
179 int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name); 173 int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name);
180 if (i >= 0) { 174 if (i >= 0) {