summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-29 16:26:11 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-29 16:26:11 -0500
commit3f950b6e526baaf719f5a7b5d7085f6468b16b29 (patch)
tree225c3470228ee2f5ac29d29ca046132154404f43 /sway
parentMerge pull request #277 from christophgysin/cmd_output (diff)
parentcmd_output: Merge instead of replace output config (diff)
downloadsway-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
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c18
-rw-r--r--sway/config.c36
2 files changed, 46 insertions, 8 deletions
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
274void 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
274void apply_output_config(struct output_config *oc, swayc_t *output) { 310void 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;