aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config/output.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config/output.c')
-rw-r--r--sway/config/output.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 75309289..18707535 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -277,17 +277,51 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) {
277} 277}
278 278
279static struct output_config *get_output_config(char *name, char *identifier) { 279static struct output_config *get_output_config(char *name, char *identifier) {
280 struct output_config *oc_name = NULL;
280 int i = list_seq_find(config->output_configs, output_name_cmp, name); 281 int i = list_seq_find(config->output_configs, output_name_cmp, name);
281 if (i >= 0) { 282 if (i >= 0) {
282 return config->output_configs->items[i]; 283 oc_name = config->output_configs->items[i];
283 } 284 }
284 285
286 struct output_config *oc_id = NULL;
285 i = list_seq_find(config->output_configs, output_name_cmp, identifier); 287 i = list_seq_find(config->output_configs, output_name_cmp, identifier);
286 if (i >= 0) { 288 if (i >= 0) {
287 return config->output_configs->items[i]; 289 oc_id = config->output_configs->items[i];
288 } 290 }
289 291
290 return NULL; 292 struct output_config *result = NULL;
293 if (oc_name && oc_id) {
294 // Generate a config named `<identifier> on <name>` which contains a
295 // merged copy of the identifier on name. This will make sure that both
296 // identifier and name configs are respected, with identifier getting
297 // priority
298 size_t length = snprintf(NULL, 0, "%s on %s", identifier, name) + 1;
299 char *temp = malloc(length);
300 snprintf(temp, length, "%s on %s", identifier, name);
301
302 result = new_output_config(temp);
303 merge_output_config(result, oc_name);
304 merge_output_config(result, oc_id);
305
306 wlr_log(WLR_DEBUG, "Generated output config \"%s\" (enabled: %d)"
307 " (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)"
308 " (dpms %d)", result->name, result->enabled, result->width,
309 result->height, result->refresh_rate, result->x, result->y,
310 result->scale, result->transform, result->background,
311 result->background_option, result->dpms_state);
312
313 free(temp);
314 } else if (oc_name) {
315 // No identifier config, just return a copy of the name config
316 result = new_output_config(name);
317 merge_output_config(result, oc_name);
318 } else if (oc_id) {
319 // No name config, just return a copy of the identifier config
320 result = new_output_config(identifier);
321 merge_output_config(result, oc_id);
322 }
323
324 return result;
291} 325}
292 326
293void apply_output_config_to_outputs(struct output_config *oc) { 327void apply_output_config_to_outputs(struct output_config *oc) {
@@ -301,14 +335,17 @@ void apply_output_config_to_outputs(struct output_config *oc) {
301 char *name = sway_output->wlr_output->name; 335 char *name = sway_output->wlr_output->name;
302 output_get_identifier(id, sizeof(id), sway_output); 336 output_get_identifier(id, sizeof(id), sway_output);
303 if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { 337 if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
304 struct output_config *current = oc; 338 struct output_config *current = new_output_config(oc->name);
339 merge_output_config(current, oc);
305 if (wildcard) { 340 if (wildcard) {
306 struct output_config *tmp = get_output_config(name, id); 341 struct output_config *tmp = get_output_config(name, id);
307 if (tmp) { 342 if (tmp) {
343 free_output_config(current);
308 current = tmp; 344 current = tmp;
309 } 345 }
310 } 346 }
311 apply_output_config(current, sway_output); 347 apply_output_config(current, sway_output);
348 free_output_config(current);
312 349
313 if (!wildcard) { 350 if (!wildcard) {
314 // Stop looking if the output config isn't applicable to all 351 // Stop looking if the output config isn't applicable to all
@@ -348,8 +385,9 @@ static void default_output_config(struct output_config *oc,
348void create_default_output_configs(void) { 385void create_default_output_configs(void) {
349 struct sway_output *sway_output; 386 struct sway_output *sway_output;
350 wl_list_for_each(sway_output, &root->all_outputs, link) { 387 wl_list_for_each(sway_output, &root->all_outputs, link) {
351 char *name = sway_output->wlr_output->name; 388 char id[128];
352 struct output_config *oc = new_output_config(name); 389 output_get_identifier(id, sizeof(id), sway_output);
390 struct output_config *oc = new_output_config(id);
353 default_output_config(oc, sway_output->wlr_output); 391 default_output_config(oc, sway_output->wlr_output);
354 list_add(config->output_configs, oc); 392 list_add(config->output_configs, oc);
355 } 393 }