aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-07-20 12:32:29 -0400
committerBrian Ashworth <bosrsf04@gmail.com>2018-07-20 12:32:29 -0400
commit9605ab45f1c863076bd68acfb1d2e5d25c1b285d (patch)
tree51d76189b5a38150001c16d520ad72ed4876874f
parentb642d47c7f1f61993edd20200298fe971f636bbb (diff)
downloadsway-9605ab45f1c863076bd68acfb1d2e5d25c1b285d.tar.xz
Fix output wildcard handling
-rw-r--r--include/sway/config.h2
-rw-r--r--sway/commands/output.c104
-rw-r--r--sway/config/output.c64
3 files changed, 108 insertions, 62 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index f660a269..6f6710e9 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -461,6 +461,8 @@ void merge_output_config(struct output_config *dst, struct output_config *src);
void apply_output_config(struct output_config *oc,
struct sway_container *output);
+struct output_config *store_output_config(struct output_config *oc);
+
void free_output_config(struct output_config *oc);
int workspace_output_cmp_workspace(const void *a, const void *b);
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 15bbd687..4d98162b 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -21,6 +21,60 @@ static struct cmd_handler output_handlers[] = {
{ "transform", output_cmd_transform },
};
+static struct output_config *get_output_config(char *name, char *identifier) {
+ int i = list_seq_find(config->output_configs, output_name_cmp, name);
+ if (i >= 0) {
+ return config->output_configs->items[i];
+ }
+
+ i = list_seq_find(config->output_configs, output_name_cmp, identifier);
+ if (i >= 0) {
+ return config->output_configs->items[i];
+ }
+
+ return NULL;
+}
+
+static void apply_output_config_to_outputs(struct output_config *oc) {
+ // Try to find the output container and apply configuration now. If
+ // this is during startup then there will be no container and config
+ // will be applied during normal "new output" event from wlroots.
+ bool wildcard = strcmp(oc->name, "*") == 0;
+ char id[128];
+ struct sway_output *sway_output;
+ wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) {
+ char *name = sway_output->wlr_output->name;
+ output_get_identifier(id, sizeof(id), sway_output);
+ if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
+ if (!sway_output->swayc) {
+ if (!oc->enabled) {
+ if (!wildcard) {
+ break;
+ }
+ continue;
+ }
+
+ output_enable(sway_output);
+ }
+
+ struct output_config *current = oc;
+ if (wildcard) {
+ struct output_config *tmp = get_output_config(name, id);
+ if (tmp) {
+ current = tmp;
+ }
+ }
+ apply_output_config(current, sway_output->swayc);
+
+ if (!wildcard) {
+ // Stop looking if the output config isn't applicable to all
+ // outputs
+ break;
+ }
+ }
+ }
+}
+
struct cmd_results *cmd_output(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1);
if (error != NULL) {
@@ -60,54 +114,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
config->handler_context.leftovers.argc = 0;
config->handler_context.leftovers.argv = NULL;
- int i = list_seq_find(config->output_configs, output_name_cmp, output->name);
- if (i >= 0) {
- // Merge existing config
- struct output_config *current = config->output_configs->items[i];
- merge_output_config(current, output);
- free_output_config(output);
- output = current;
- } else {
- list_add(config->output_configs, output);
- }
-
- 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)",
- output->name, output->enabled, output->width, output->height,
- output->refresh_rate, output->x, output->y, output->scale,
- output->transform, output->background, output->background_option, output->dpms_state);
-
- // Try to find the output container and apply configuration now. If
- // this is during startup then there will be no container and config
- // will be applied during normal "new output" event from wlroots.
- char identifier[128];
- bool all = strcmp(output->name, "*") == 0;
- struct sway_output *sway_output;
- wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) {
- output_get_identifier(identifier, sizeof(identifier), sway_output);
- wlr_log(WLR_DEBUG, "Checking identifier %s", identifier);
- if (all || strcmp(sway_output->wlr_output->name, output->name) == 0
- || strcmp(identifier, output->name) == 0) {
- if (!sway_output->swayc) {
- if (!output->enabled) {
- if (!all) {
- break;
- }
- continue;
- }
-
- output_enable(sway_output);
- }
-
- apply_output_config(output, sway_output->swayc);
-
- if (!all) {
- // Stop looking if the output config isn't applicable to all
- // outputs
- break;
- }
- }
- }
+ output = store_output_config(output);
+ apply_output_config_to_outputs(output);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
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) {