From 7d82cd9c0a418385fbde72f4503459ab7afa1bde Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sun, 29 Nov 2015 14:51:42 +0200 Subject: [PATCH] cmd_output: Use list_seq_find() to find matching config --- include/config.h | 1 + sway/commands.c | 12 +++++------- sway/config.c | 8 ++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/config.h b/include/config.h index 6b48063a..21fbb8f9 100644 --- a/include/config.h +++ b/include/config.h @@ -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. */ 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. */ void apply_output_config(struct output_config *oc, swayc_t *output); diff --git a/sway/commands.c b/sway/commands.c index 1106f095..4eaa210f 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -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); + if (i >= 0) { + // replace existing config struct output_config *oc = config->output_configs->items[i]; - if (strcmp(oc->name, output->name) == 0) { - // replace existing config - list_del(config->output_configs, i); - free_output_config(oc); - break; - } + list_del(config->output_configs, i); + free_output_config(oc); } list_add(config->output_configs, output); diff --git a/sway/config.c b/sway/config.c index e9785aba..bb9142c0 100644 --- a/sway/config.c +++ b/sway/config.c @@ -261,6 +261,14 @@ bool read_config(FILE *file, bool is_active) { 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) { if (oc && oc->width > 0 && oc->height > 0) { output->width = oc->width;