mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
config/output: Support multiple matches in find_output_config
Simplify find_output_config and inline the search through the output configs instead of using list_seq_find with a comparator function. The new implementation will merge any amount of matched configs in order, which will be relied upon in a future commit.
This commit is contained in:
parent
fb5eadc363
commit
a0c0349934
|
@ -25,13 +25,6 @@
|
||||||
#include <wlr/backend/drm.h>
|
#include <wlr/backend/drm.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int output_name_cmp(const void *item, const void *data) {
|
|
||||||
const struct output_config *output = item;
|
|
||||||
const char *name = data;
|
|
||||||
|
|
||||||
return strcmp(output->name, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void output_get_identifier(char *identifier, size_t len,
|
void output_get_identifier(char *identifier, size_t len,
|
||||||
struct sway_output *output) {
|
struct sway_output *output) {
|
||||||
struct wlr_output *wlr_output = output->wlr_output;
|
struct wlr_output *wlr_output = output->wlr_output;
|
||||||
|
@ -615,8 +608,6 @@ static void default_output_config(struct output_config *oc,
|
||||||
// configuration that applies to the specified output.
|
// configuration that applies to the specified output.
|
||||||
struct output_config *find_output_config(struct sway_output *sway_output) {
|
struct output_config *find_output_config(struct sway_output *sway_output) {
|
||||||
const char *name = sway_output->wlr_output->name;
|
const char *name = sway_output->wlr_output->name;
|
||||||
struct output_config *oc = NULL;
|
|
||||||
|
|
||||||
struct output_config *result = new_output_config(name);
|
struct output_config *result = new_output_config(name);
|
||||||
if (config->reloading) {
|
if (config->reloading) {
|
||||||
default_output_config(result, sway_output->wlr_output);
|
default_output_config(result, sway_output->wlr_output);
|
||||||
|
@ -625,25 +616,21 @@ struct output_config *find_output_config(struct sway_output *sway_output) {
|
||||||
char id[128];
|
char id[128];
|
||||||
output_get_identifier(id, sizeof(id), sway_output);
|
output_get_identifier(id, sizeof(id), sway_output);
|
||||||
|
|
||||||
int i;
|
// We take a new config and merge on top, in order, the wildcard config,
|
||||||
bool match = false;
|
// output config by name, and output config by identifier to form the final
|
||||||
if ((i = list_seq_find(config->output_configs, output_name_cmp, "*")) >= 0) {
|
// config. If there are multiple matches, they are merged in order.
|
||||||
match = true;
|
struct output_config *oc = NULL;
|
||||||
oc = config->output_configs->items[i];
|
const char *names[] = {"*", name, id, NULL};
|
||||||
|
for (const char **name = &names[0]; *name; name++) {
|
||||||
|
for (int idx = 0; idx < config->output_configs->length; idx++) {
|
||||||
|
oc = config->output_configs->items[idx];
|
||||||
|
if (strcmp(oc->name, *name) == 0) {
|
||||||
merge_output_config(result, oc);
|
merge_output_config(result, oc);
|
||||||
}
|
}
|
||||||
if ((i = list_seq_find(config->output_configs, output_name_cmp, name)) >= 0) {
|
|
||||||
match = true;
|
|
||||||
oc = config->output_configs->items[i];
|
|
||||||
merge_output_config(result, oc);
|
|
||||||
}
|
}
|
||||||
if ((i = list_seq_find(config->output_configs, output_name_cmp, id)) >= 0) {
|
|
||||||
match = true;
|
|
||||||
oc = config->output_configs->items[i];
|
|
||||||
merge_output_config(result, oc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match && !config->reloading) {
|
if (oc == NULL && !config->reloading) {
|
||||||
// No name, identifier, or wildcard config. Since we are not
|
// No name, identifier, or wildcard config. Since we are not
|
||||||
// reloading with defaults, the output config will be empty, so
|
// reloading with defaults, the output config will be empty, so
|
||||||
// just return NULL
|
// just return NULL
|
||||||
|
|
Loading…
Reference in a new issue