diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/sway/commands.c b/sway/commands.c index 42845f65..e00cc94d 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -716,20 +716,23 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
716 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { | 716 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { |
717 | return error; | 717 | return error; |
718 | } | 718 | } |
719 | const char *name = argv[0]; | ||
720 | |||
719 | struct output_config *output = calloc(1, sizeof(struct output_config)); | 721 | struct output_config *output = calloc(1, sizeof(struct output_config)); |
720 | output->x = output->y = output->width = output->height = -1; | 722 | output->x = output->y = output->width = output->height = -1; |
721 | output->name = strdup(argv[0]); | 723 | output->name = strdup(name); |
722 | output->enabled = true; | 724 | output->enabled = true; |
723 | 725 | ||
724 | // TODO: atoi doesn't handle invalid numbers | 726 | // TODO: atoi doesn't handle invalid numbers |
725 | if (strcasecmp(argv[1], "disable") == 0) { | ||
726 | output->enabled = false; | ||
727 | } | ||
728 | // TODO: Check missing params after each sub-command | 727 | // TODO: Check missing params after each sub-command |
729 | 728 | ||
730 | int i; | 729 | int i; |
731 | for (i = 1; i < argc; ++i) { | 730 | for (i = 1; i < argc; ++i) { |
732 | if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) { | 731 | const char *command = argv[i]; |
732 | |||
733 | if (strcasecmp(command, "disable") == 0) { | ||
734 | output->enabled = false; | ||
735 | } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { | ||
733 | char *res = argv[++i]; | 736 | char *res = argv[++i]; |
734 | char *x = strchr(res, 'x'); | 737 | char *x = strchr(res, 'x'); |
735 | int width = -1, height = -1; | 738 | int width = -1, height = -1; |
@@ -747,7 +750,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
747 | } | 750 | } |
748 | output->width = width; | 751 | output->width = width; |
749 | output->height = height; | 752 | output->height = height; |
750 | } else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) { | 753 | } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) { |
751 | char *res = argv[++i]; | 754 | char *res = argv[++i]; |
752 | char *c = strchr(res, ','); | 755 | char *c = strchr(res, ','); |
753 | int x = -1, y = -1; | 756 | int x = -1, y = -1; |
@@ -765,7 +768,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
765 | } | 768 | } |
766 | output->x = x; | 769 | output->x = x; |
767 | output->y = y; | 770 | output->y = y; |
768 | } else if (strcasecmp(argv[i], "bg") == 0 || strcasecmp(argv[i], "background") == 0) { | 771 | } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { |
769 | wordexp_t p; | 772 | wordexp_t p; |
770 | if (++i >= argc) { | 773 | if (++i >= argc) { |
771 | return cmd_results_new(CMD_INVALID, "output", "Missing background file."); | 774 | return cmd_results_new(CMD_INVALID, "output", "Missing background file."); |
@@ -801,20 +804,19 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
801 | } | 804 | } |
802 | } | 805 | } |
803 | 806 | ||
804 | 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 | ||
805 | struct output_config *oc = config->output_configs->items[i]; | 810 | struct output_config *oc = config->output_configs->items[i]; |
806 | if (strcmp(oc->name, output->name) == 0) { | 811 | list_del(config->output_configs, i); |
807 | // replace existing config | 812 | free_output_config(oc); |
808 | list_del(config->output_configs, i); | ||
809 | free_output_config(oc); | ||
810 | break; | ||
811 | } | ||
812 | } | 813 | } |
813 | list_add(config->output_configs, output); | 814 | list_add(config->output_configs, output); |
814 | 815 | ||
815 | sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)", | 816 | sway_log(L_DEBUG, "Config stored for output %s (%s) (%d x %d @ %d, %d) (bg %s %s)", |
816 | output->name, output->width, output->height, output->x, output->y, | 817 | output->name, output->enabled ? "enable" : "disable", output->width, |
817 | output->background, output->background_option); | 818 | output->height, output->x, output->y, output->background, |
819 | output->background_option); | ||
818 | 820 | ||
819 | if (output->name) { | 821 | if (output->name) { |
820 | // Try to find the output container and apply configuration now. If | 822 | // Try to find the output container and apply configuration now. If |