mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 09:51:29 +00:00
Merge pull request #2318 from RedSoxFan/fix-output-wildcard
Fix output wildcard handling
This commit is contained in:
commit
a2b2146f7f
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue