cmd_output: Use list_seq_find() to find matching config

This commit is contained in:
Christoph Gysin 2015-11-29 14:51:42 +02:00
parent 88f372a22a
commit 7d82cd9c0a
3 changed files with 14 additions and 7 deletions

View file

@ -98,6 +98,7 @@ bool read_config(FILE *file, bool is_active);
* Does variable replacement for a string based on the config's currently loaded variables. * Does variable replacement for a string based on the config's currently loaded variables.
*/ */
char *do_var_replacement(char *str); char *do_var_replacement(char *str);
int output_name_cmp(const void *item, const void *data);;
/** Sets up a WLC output handle based on a given output_config. /** Sets up a WLC output handle based on a given output_config.
*/ */
void apply_output_config(struct output_config *oc, swayc_t *output); void apply_output_config(struct output_config *oc, swayc_t *output);

View file

@ -804,14 +804,12 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
} }
} }
for (i = 0; i < config->output_configs->length; ++i) { i = list_seq_find(config->output_configs, output_name_cmp, name);
struct output_config *oc = config->output_configs->items[i]; if (i >= 0) {
if (strcmp(oc->name, output->name) == 0) {
// replace existing config // replace existing config
struct output_config *oc = config->output_configs->items[i];
list_del(config->output_configs, i); list_del(config->output_configs, i);
free_output_config(oc); free_output_config(oc);
break;
}
} }
list_add(config->output_configs, output); list_add(config->output_configs, output);

View file

@ -261,6 +261,14 @@ bool read_config(FILE *file, bool is_active) {
return success; return success;
} }
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 apply_output_config(struct output_config *oc, swayc_t *output) { void apply_output_config(struct output_config *oc, swayc_t *output) {
if (oc && oc->width > 0 && oc->height > 0) { if (oc && oc->width > 0 && oc->height > 0) {
output->width = oc->width; output->width = oc->width;