diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-29 16:26:11 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-29 16:26:11 -0500 |
commit | 3f950b6e526baaf719f5a7b5d7085f6468b16b29 (patch) | |
tree | 225c3470228ee2f5ac29d29ca046132154404f43 | |
parent | Merge pull request #277 from christophgysin/cmd_output (diff) | |
parent | cmd_output: Merge instead of replace output config (diff) | |
download | sway-3f950b6e526baaf719f5a7b5d7085f6468b16b29.tar.gz sway-3f950b6e526baaf719f5a7b5d7085f6468b16b29.tar.zst sway-3f950b6e526baaf719f5a7b5d7085f6468b16b29.zip |
Merge pull request #278 from christophgysin/merge
cmd_output: Merge instead of replace output config
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 18 | ||||
-rw-r--r-- | sway/config.c | 36 |
3 files changed, 48 insertions, 9 deletions
diff --git a/include/config.h b/include/config.h index 9caadec8..b9ef340b 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -40,7 +40,7 @@ struct sway_mode { | |||
40 | */ | 40 | */ |
41 | struct output_config { | 41 | struct output_config { |
42 | char *name; | 42 | char *name; |
43 | bool enabled; | 43 | int enabled; |
44 | int width, height; | 44 | int width, height; |
45 | int x, y; | 45 | int x, y; |
46 | char *background; | 46 | char *background; |
@@ -99,6 +99,7 @@ bool read_config(FILE *file, bool is_active); | |||
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 | int output_name_cmp(const void *item, const void *data); |
102 | void merge_output_config(struct output_config *dst, struct output_config *src); | ||
102 | /** Sets up a WLC output handle based on a given output_config. | 103 | /** Sets up a WLC output handle based on a given output_config. |
103 | */ | 104 | */ |
104 | void apply_output_config(struct output_config *oc, swayc_t *output); | 105 | void apply_output_config(struct output_config *oc, swayc_t *output); |
diff --git a/sway/commands.c b/sway/commands.c index d6ee4553..307196a3 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -719,7 +719,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
719 | struct output_config *output = calloc(1, sizeof(struct output_config)); | 719 | struct output_config *output = calloc(1, sizeof(struct output_config)); |
720 | output->x = output->y = output->width = output->height = -1; | 720 | output->x = output->y = output->width = output->height = -1; |
721 | output->name = strdup(name); | 721 | output->name = strdup(name); |
722 | output->enabled = true; | 722 | output->enabled = -1; |
723 | 723 | ||
724 | // TODO: atoi doesn't handle invalid numbers | 724 | // TODO: atoi doesn't handle invalid numbers |
725 | 725 | ||
@@ -728,7 +728,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
728 | const char *command = argv[i]; | 728 | const char *command = argv[i]; |
729 | 729 | ||
730 | if (strcasecmp(command, "disable") == 0) { | 730 | if (strcasecmp(command, "disable") == 0) { |
731 | output->enabled = false; | 731 | output->enabled = 0; |
732 | } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { | 732 | } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { |
733 | if (++i >= argc) { | 733 | if (++i >= argc) { |
734 | return cmd_results_new(CMD_INVALID, "output", "Missing resolution argument."); | 734 | return cmd_results_new(CMD_INVALID, "output", "Missing resolution argument."); |
@@ -815,15 +815,17 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
815 | 815 | ||
816 | i = list_seq_find(config->output_configs, output_name_cmp, name); | 816 | i = list_seq_find(config->output_configs, output_name_cmp, name); |
817 | if (i >= 0) { | 817 | if (i >= 0) { |
818 | // replace existing config | 818 | // merge existing config |
819 | struct output_config *oc = config->output_configs->items[i]; | 819 | struct output_config *oc = config->output_configs->items[i]; |
820 | list_del(config->output_configs, i); | 820 | merge_output_config(oc, output); |
821 | free_output_config(oc); | 821 | free_output_config(output); |
822 | output = oc; | ||
823 | } else { | ||
824 | list_add(config->output_configs, output); | ||
822 | } | 825 | } |
823 | list_add(config->output_configs, output); | ||
824 | 826 | ||
825 | sway_log(L_DEBUG, "Config stored for output %s (%s) (%d x %d @ %d, %d) (bg %s %s)", | 827 | sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d) (bg %s %s)", |
826 | output->name, output->enabled ? "enable" : "disable", output->width, | 828 | output->name, output->enabled, output->width, |
827 | output->height, output->x, output->y, output->background, | 829 | output->height, output->x, output->y, output->background, |
828 | output->background_option); | 830 | output->background_option); |
829 | 831 | ||
diff --git a/sway/config.c b/sway/config.c index 67b442ad..aa4675ce 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -271,6 +271,42 @@ int output_name_cmp(const void *item, const void *data) { | |||
271 | return strcmp(output->name, name); | 271 | return strcmp(output->name, name); |
272 | } | 272 | } |
273 | 273 | ||
274 | void merge_output_config(struct output_config *dst, struct output_config *src) { | ||
275 | if (src->name) { | ||
276 | if (dst->name) { | ||
277 | free(dst->name); | ||
278 | } | ||
279 | dst->name = strdup(src->name); | ||
280 | } | ||
281 | if (src->enabled != -1) { | ||
282 | dst->enabled = src->enabled; | ||
283 | } | ||
284 | if (src->width != -1) { | ||
285 | dst->width = src->width; | ||
286 | } | ||
287 | if (src->height != -1) { | ||
288 | dst->height = src->height; | ||
289 | } | ||
290 | if (src->x != -1) { | ||
291 | dst->x = src->x; | ||
292 | } | ||
293 | if (src->y != -1) { | ||
294 | dst->y = src->y; | ||
295 | } | ||
296 | if (src->background) { | ||
297 | if (dst->background) { | ||
298 | free(dst->background); | ||
299 | } | ||
300 | dst->background = strdup(src->background); | ||
301 | } | ||
302 | if (src->background_option) { | ||
303 | if (dst->background_option) { | ||
304 | free(dst->background_option); | ||
305 | } | ||
306 | dst->background_option = strdup(src->background_option); | ||
307 | } | ||
308 | } | ||
309 | |||
274 | void apply_output_config(struct output_config *oc, swayc_t *output) { | 310 | void apply_output_config(struct output_config *oc, swayc_t *output) { |
275 | if (oc && oc->width > 0 && oc->height > 0) { | 311 | if (oc && oc->width > 0 && oc->height > 0) { |
276 | output->width = oc->width; | 312 | output->width = oc->width; |