diff options
author | Christoph Gysin <christoph.gysin@gmail.com> | 2015-11-29 14:51:42 +0200 |
---|---|---|
committer | Christoph Gysin <christoph.gysin@gmail.com> | 2015-11-29 15:29:06 +0200 |
commit | 7d82cd9c0a418385fbde72f4503459ab7afa1bde (patch) | |
tree | d82e43a424ccde83f5ced21c79b2d6b519f62bd1 | |
parent | cmd_output: Cleanup cmd_output argument handling (diff) | |
download | sway-7d82cd9c0a418385fbde72f4503459ab7afa1bde.tar.gz sway-7d82cd9c0a418385fbde72f4503459ab7afa1bde.tar.zst sway-7d82cd9c0a418385fbde72f4503459ab7afa1bde.zip |
cmd_output: Use list_seq_find() to find matching config
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 12 | ||||
-rw-r--r-- | 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); | |||
98 | * Does variable replacement for a string based on the config's currently loaded variables. | 98 | * Does variable replacement for a string based on the config's currently loaded variables. |
99 | */ | 99 | */ |
100 | char *do_var_replacement(char *str); | 100 | char *do_var_replacement(char *str); |
101 | int output_name_cmp(const void *item, const void *data);; | ||
101 | /** Sets up a WLC output handle based on a given output_config. | 102 | /** Sets up a WLC output handle based on a given output_config. |
102 | */ | 103 | */ |
103 | void apply_output_config(struct output_config *oc, swayc_t *output); | 104 | 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) { | |||
804 | } | 804 | } |
805 | } | 805 | } |
806 | 806 | ||
807 | for (i = 0; i < config->output_configs->length; ++i) { | 807 | i = list_seq_find(config->output_configs, output_name_cmp, name); |
808 | if (i >= 0) { | ||
809 | // replace existing config | ||
808 | struct output_config *oc = config->output_configs->items[i]; | 810 | struct output_config *oc = config->output_configs->items[i]; |
809 | if (strcmp(oc->name, output->name) == 0) { | 811 | list_del(config->output_configs, i); |
810 | // replace existing config | 812 | free_output_config(oc); |
811 | list_del(config->output_configs, i); | ||
812 | free_output_config(oc); | ||
813 | break; | ||
814 | } | ||
815 | } | 813 | } |
816 | list_add(config->output_configs, output); | 814 | list_add(config->output_configs, output); |
817 | 815 | ||
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) { | |||
261 | return success; | 261 | return success; |
262 | } | 262 | } |
263 | 263 | ||
264 | int output_name_cmp(const void *item, const void *data) | ||
265 | { | ||
266 | const struct output_config *output = item; | ||
267 | const char *name = data; | ||
268 | |||
269 | return strcmp(output->name, name); | ||
270 | } | ||
271 | |||
264 | void apply_output_config(struct output_config *oc, swayc_t *output) { | 272 | void apply_output_config(struct output_config *oc, swayc_t *output) { |
265 | if (oc && oc->width > 0 && oc->height > 0) { | 273 | if (oc && oc->width > 0 && oc->height > 0) { |
266 | output->width = oc->width; | 274 | output->width = oc->width; |