diff options
author | Christoph Gysin <christoph.gysin@gmail.com> | 2015-11-29 10:28:52 +0200 |
---|---|---|
committer | Christoph Gysin <christoph.gysin@gmail.com> | 2015-11-29 14:51:56 +0200 |
commit | 88f372a22adab3c7a7b088d9d400066ed9c7b1af (patch) | |
tree | b0acbd386b2f043a90cf947d1e2607a0ac53fd68 | |
parent | Merge pull request #272 from mikkeloscar/output-cmd-warnings (diff) | |
download | sway-88f372a22adab3c7a7b088d9d400066ed9c7b1af.tar.gz sway-88f372a22adab3c7a7b088d9d400066ed9c7b1af.tar.zst sway-88f372a22adab3c7a7b088d9d400066ed9c7b1af.zip |
cmd_output: Cleanup cmd_output argument handling
-rw-r--r-- | sway/commands.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/sway/commands.c b/sway/commands.c index 42845f65..1106f095 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."); |