diff options
author | emersion <contact@emersion.fr> | 2018-07-20 19:53:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 19:53:53 +0100 |
commit | a2b2146f7fb8d5e868880daff9484145a68ab4a3 (patch) | |
tree | 51d76189b5a38150001c16d520ad72ed4876874f /sway/config | |
parent | b642d47c7f1f61993edd20200298fe971f636bbb (diff) | |
parent | 9605ab45f1c863076bd68acfb1d2e5d25c1b285d (diff) |
Merge pull request #2318 from RedSoxFan/fix-output-wildcard
Fix output wildcard handling
Diffstat (limited to 'sway/config')
-rw-r--r-- | sway/config/output.c | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/sway/config/output.c b/sway/config/output.c index 1bf9e5f1..505fa745 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -45,10 +45,6 @@ struct output_config *new_output_config(const char *name) { } void merge_output_config(struct output_config *dst, struct output_config *src) { - if (src->name) { - free(dst->name); - dst->name = strdup(src->name); - } if (src->enabled != -1) { dst->enabled = src->enabled; } @@ -86,6 +82,56 @@ void merge_output_config(struct output_config *dst, struct output_config *src) { } } +static void merge_wildcard_on_all(struct output_config *wildcard) { + for (int i = 0; i < config->output_configs->length; i++) { + struct output_config *oc = config->output_configs->items[i]; + if (strcmp(wildcard->name, oc->name) != 0) { + wlr_log(WLR_DEBUG, "Merging output * config on %s", oc->name); + merge_output_config(oc, wildcard); + } + } +} + +struct output_config *store_output_config(struct output_config *oc) { + bool wildcard = strcmp(oc->name, "*") == 0; + if (wildcard) { + merge_wildcard_on_all(oc); + } + + int i = list_seq_find(config->output_configs, output_name_cmp, oc->name); + if (i >= 0) { + wlr_log(WLR_DEBUG, "Merging on top of existing output config"); + struct output_config *current = config->output_configs->items[i]; + merge_output_config(current, oc); + free_output_config(oc); + oc = current; + } else if (!wildcard) { + wlr_log(WLR_DEBUG, "Adding non-wildcard output config"); + i = list_seq_find(config->output_configs, output_name_cmp, "*"); + if (i >= 0) { + wlr_log(WLR_DEBUG, "Merging on top of output * config"); + struct output_config *current = new_output_config(oc->name); + merge_output_config(current, config->output_configs->items[i]); + merge_output_config(current, oc); + free_output_config(oc); + oc = current; + } + list_add(config->output_configs, oc); + } else { + // New wildcard config. Just add it + wlr_log(WLR_DEBUG, "Adding output * config"); + list_add(config->output_configs, oc); + } + + wlr_log(WLR_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz " + "position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)", + oc->name, oc->enabled, oc->width, oc->height, oc->refresh_rate, + oc->x, oc->y, oc->scale, oc->transform, oc->background, + oc->background_option, oc->dpms_state); + + return oc; +} + static void set_mode(struct wlr_output *output, int width, int height, float refresh_rate) { int mhz = (int)(refresh_rate * 1000); @@ -165,16 +211,6 @@ void apply_output_config(struct output_config *oc, struct sway_container *output wlr_output_layout_add_auto(output_layout, wlr_output); } - if (!oc || !oc->background) { - // Look for a * config for background - int i = list_seq_find(config->output_configs, output_name_cmp, "*"); - if (i >= 0) { - oc = config->output_configs->items[i]; - } else { - oc = NULL; - } - } - int output_i; for (output_i = 0; output_i < root_container.children->length; ++output_i) { if (root_container.children->items[output_i] == output) { |