sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit b1bd3ae6f3210e6b3ecda2d253518da18420e6cd
parent ae7ed795730398d50e6408575a1edfbd5c34bd3c
Author: Christoph Gysin <christoph.gysin@gmail.com>
Date:   Sun, 29 Nov 2015 22:51:48 +0200

cmd_output: Merge instead of replace output config

Diffstat:
Minclude/config.h | 1+
Msway/commands.c | 10++++++----
Msway/config.c | 36++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/include/config.h b/include/config.h @@ -99,6 +99,7 @@ bool read_config(FILE *file, bool is_active); */ char *do_var_replacement(char *str); int output_name_cmp(const void *item, const void *data); +void merge_output_config(struct output_config *dst, struct output_config *src); /** 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 @@ -804,12 +804,14 @@ static struct cmd_results *cmd_output(int argc, char **argv) { i = list_seq_find(config->output_configs, output_name_cmp, name); if (i >= 0) { - // replace existing config + // merge existing config struct output_config *oc = config->output_configs->items[i]; - list_del(config->output_configs, i); - free_output_config(oc); + merge_output_config(oc, output); + free_output_config(output); + output = oc; + } else { + list_add(config->output_configs, output); } - list_add(config->output_configs, output); sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d) (bg %s %s)", output->name, output->enabled, output->width, diff --git a/sway/config.c b/sway/config.c @@ -271,6 +271,42 @@ int output_name_cmp(const void *item, const void *data) { return strcmp(output->name, name); } +void merge_output_config(struct output_config *dst, struct output_config *src) { + if (src->name) { + if (dst->name) { + free(dst->name); + } + dst->name = strdup(src->name); + } + if (src->enabled != -1) { + dst->enabled = src->enabled; + } + if (src->width != -1) { + dst->width = src->width; + } + if (src->height != -1) { + dst->height = src->height; + } + if (src->x != -1) { + dst->x = src->x; + } + if (src->y != -1) { + dst->y = src->y; + } + if (src->background) { + if (dst->background) { + free(dst->background); + } + dst->background = strdup(src->background); + } + if (src->background_option) { + if (dst->background_option) { + free(dst->background_option); + } + dst->background_option = strdup(src->background_option); + } +} + void apply_output_config(struct output_config *oc, swayc_t *output) { if (oc && oc->width > 0 && oc->height > 0) { output->width = oc->width;